Fix tests after r183770 on non-Mac ports. These tests are expecting Mac editing behavior.
[WebKit-https.git] / LayoutTests / editing / execCommand / toggle-mixed-text-decorations.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <p id="description"></p>
5 <div id="console"></div>
6 <script src="../../resources/js-test-pre.js"></script>
7 <script>
8
9 description("Test to make sure we can toggle underline and strike through separately.")
10
11 if (window.internals)
12     internals.settings.setEditingBehavior('mac');
13
14 var testContainer = document.createElement("div");
15 testContainer.contentEditable = true;
16 document.body.appendChild(testContainer);
17
18 function testSingleToggle(toggleCommand, initialContents, expectedContents)
19 {
20     testContainer.innerHTML = initialContents;
21     getSelection().collapse(testContainer, 0);
22     getSelection().modify('')
23     window.getSelection().selectAllChildren(testContainer);
24     document.execCommand("styleWithCSS", false, false);
25     document.execCommand(toggleCommand, false, null);
26     if (testContainer.innerHTML === expectedContents) {
27         testPassed("one " + toggleCommand + " command converted " + initialContents + " to " + expectedContents);
28     } else {
29         testFailed("one " + toggleCommand + " command converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
30     }
31 }
32
33 function content(markup) {
34     testContainer.innerHTML = markup;
35 }
36
37 function select(offset, extent) {
38     getSelection().collapse(testContainer, 0);
39     for (var i = 0; i < offset; i++)
40         getSelection().modify('move', 'forward', 'character');
41     for (var i = offset; i < extent; i++)
42         getSelection().modify('extend', 'forward', 'character');
43 }
44
45 function toggle(command) {
46     document.execCommand(command, false, null);
47     return testContainer.innerHTML;
48 }
49
50 evalAndLog('document.execCommand("styleWithCSS", false, false);');
51
52 debug('');
53 debug('Toggling strikeThrough');
54 shouldBe('content("<s><u>a</u>b</s>"); select(0, 2); toggle("strikeThrough")', '"<u>a</u>b"');
55 shouldBe('content("<s><u>a</u>b<u>c</u></s>"); select(0, 3); toggle("strikeThrough")', '"<u>a</u>b<u>c</u>"');
56 shouldBe('content("<s>a<u>b</u>c</s>"); select(0, 3); toggle("strikeThrough")', '"a<u>b</u>c"');
57 shouldBe('content("<s>a<u>b</u>c</s>"); select(1, 3); toggle("strikeThrough")', '"<strike>a</strike><u>b</u>c"');
58 shouldBe('content("<s>a<u>b</u>c</s>"); select(0, 2); toggle("strikeThrough")', '"a<u>b</u><strike>c</strike>"');
59 shouldBe('content("<s><u>ab</u></s>c"); select(1, 3); toggle("strikeThrough")', '"<u><strike>a</strike>b</u>c"');
60 shouldBe('content("<s>a<u>b</u></s>c"); select(1, 3); toggle("strikeThrough")', '"<strike>a</strike><u>b</u>c"');
61 shouldBe('content("a<s><u>b</u>c</s>"); select(0, 2); toggle("strikeThrough")', '"<strike>a</strike><s><u>b</u>c</s>"');
62 shouldBe('content("a<strike><u>b</u>c</strike>"); select(0, 2); toggle("strikeThrough")', '"<strike>a<u>b</u>c</strike>"');
63 shouldBe('content("a<u><s>bc</s></u>"); select(0, 2); toggle("strikeThrough")', '"<strike>a</strike><u><s>bc</s></u>"');
64 shouldBe('content("a<s><b><u>bc</u></b></s>"); select(0, 2); toggle("strikeThrough")', '"<strike>a</strike><s><b><u>bc</u></b></s>"');
65 shouldBe('content("a<strike><b><u>bc</u></b></strike>"); select(0, 2); toggle("strikeThrough")', '"<strike>a<b><u>bc</u></b></strike>"');
66
67 debug('');
68 debug('Toggling underline');
69 shouldBe('content("<u><s>a</s>b</u>"); select(0, 2); toggle("underline")', '"<s>a</s>b"');
70 shouldBe('content("<u><s>a</s>b<s>c</s></u>"); select(0, 3); toggle("underline")', '"<s>a</s>b<s>c</s>"');
71 shouldBe('content("<u>a<s>b</s>c</u>"); select(0, 3); toggle("underline")', '"a<s>b</s>c"');
72 shouldBe('content("<u>a<s>b</s>c</u>"); select(1, 3); toggle("underline")', '"<u>a</u><s>b</s>c"');
73 shouldBe('content("<u>a<s>b</s>c</u>"); select(0, 2); toggle("underline")', '"a<s>b</s><u>c</u>"');
74 shouldBe('content("<u><s>ab</s></u>c"); select(1, 3); toggle("underline")', '"<s><u>a</u>b</s>c"');
75 shouldBe('content("<u>a<s>b</s></u>c"); select(1, 3); toggle("underline")', '"<u>a</u><s>b</s>c"');
76 shouldBe('content("a<u><s>b</s>c</u>"); select(0, 2); toggle("underline")', '"<u>a<s>b</s>c</u>"');
77 shouldBe('content("a<s><u>bc</u></s>"); select(0, 2); toggle("underline")', '"<u>a</u><s><u>bc</u></s>"');
78 shouldBe('content("a<u><b><s>bc</s></b></u>"); select(0, 2); toggle("underline")', '"<u>a<b><s>bc</s></b></u>"');
79
80 evalAndLog('document.execCommand("styleWithCSS", false, true);');
81
82 debug('');
83 debug('Toggling strikeThrough');
84 shouldBe('content(\'<span style="text-decoration: line-through;"><span style="text-decoration: underline">a</span>b</span>\');\n'
85     + 'select(0, 2); toggle("strikeThrough")',
86     '\'<span style="text-decoration: underline;">a</span>b\'');
87 shouldBe('content(\'<span style="text-decoration: line-through;"><span style="text-decoration: underline;">a</span>b<span style="text-decoration: underline">c</span></span>\');\n'
88     + 'select(0, 3); toggle("strikeThrough")',
89     '\'<span style="text-decoration: underline;">a</span>b<span style="text-decoration: underline;">c</span>\'');
90 shouldBe('content(\'<span style="text-decoration: line-through;">a<span style="text-decoration: underline;">b</span>c</span>\');\n'
91     + 'select(0, 3); toggle("strikeThrough")',
92     '\'a<span style="text-decoration: underline;">b</span>c\'');
93 shouldBe('content(\'<span style="text-decoration: line-through;">a<span style="text-decoration: underline;">b</span>c</span>\');\n'
94     + 'select(1, 3); toggle("strikeThrough")',
95     '\'<span style="text-decoration: line-through;">a</span><span style="text-decoration: underline;">b</span>c\'');
96 shouldBe('content(\'<span style="text-decoration: line-through;">a<span style="text-decoration: underline;">b</span>c</span>\');\n'
97     + 'select(0, 2); toggle("strikeThrough")',
98     '\'a<span style="text-decoration: underline;">b</span><span style="text-decoration: line-through;">c</span>\'');
99 shouldBe('content(\'<span style="text-decoration: line-through;"><span style="text-decoration: underline;">ab</span></span>c\');\n'
100     + 'select(1, 3); toggle("strikeThrough")',
101     '\'<span style="text-decoration: underline;"><span style="text-decoration: line-through;">a</span>b</span>c\'');
102 shouldBe('content(\'a<span style="text-decoration: line-through;"><span style="text-decoration: underline;">b</span>c</span>\');\n'
103     + 'select(0, 2); toggle("strikeThrough")',
104     '\'<span style="text-decoration: line-through;">a<span style="text-decoration: underline line-through;">b</span>c</span>\'');
105 shouldBe('content(\'a<span style="text-decoration: underline;"><span style="text-decoration: line-through;">bc</span></span>\');\n'
106     + 'select(0, 2); toggle("strikeThrough")',
107     '\'<span style="text-decoration: line-through;">a</span><span style="text-decoration: underline;"><span style="text-decoration: line-through;">bc</span></span>\'');
108 shouldBe('content(\'a<span style="text-decoration: line-through;"><b><span style="text-decoration: underline;">bc</span></b></span>\');\n'
109     + 'select(0, 2); toggle("strikeThrough")',
110     '\'<span style="text-decoration: line-through;">a<b><span style="text-decoration: underline;"><span style="text-decoration: underline line-through;">b</span>c</span></b></span>\'');
111
112 debug('');
113 debug('Toggling underline');
114 shouldBe('content(\'<span style="text-decoration: underline;"><span style="text-decoration: line-through;">a</span>b</span>\');\n'
115     + 'select(0, 2); toggle("underline")',
116     '\'<span style="text-decoration: line-through;">a</span>b\'');
117 shouldBe('content(\'<span style="text-decoration: underline;"><span style="text-decoration: line-through;">a</span>b<span style="text-decoration: line-through;">c</span></span>\');\n'
118     + 'select(0, 3); toggle("underline")',
119     '\'<span style="text-decoration: line-through;">a</span>b<span style="text-decoration: line-through;">c</span>\'');
120 shouldBe('content(\'<span style="text-decoration: underline;">a<span style="text-decoration: line-through;">b</span>c</span>\');\n'
121     + 'select(0, 3); toggle("underline")',
122     '\'a<span style="text-decoration: line-through;">b</span>c\'');
123 shouldBe('content(\'<span style="text-decoration: underline;">a<span style="text-decoration: line-through;">b</span>c</span>\');\n'
124     + 'select(1, 3); toggle("underline")',
125     '\'<span style="text-decoration: underline;">a</span><span style="text-decoration: line-through;">b</span>c\'');
126 shouldBe('content(\'<span style="text-decoration: underline;">a<span style="text-decoration: line-through;">b</span>c</span>\');\n'
127     + 'select(0, 2); toggle("underline")',
128     '\'a<span style="text-decoration: line-through;">b</span><span style="text-decoration: underline;">c</span>\'');
129 shouldBe('content(\'<span style="text-decoration: underline;"><span style="text-decoration: line-through;">ab</span></span>c\');\n'
130     + 'select(1, 3); toggle("underline")',
131     '\'<span style="text-decoration: line-through;"><span style="text-decoration: underline;">a</span>b</span>c\'');
132 shouldBe('content(\'<span style="text-decoration: underline;">a<span style="text-decoration: line-through;">b</span></span>c\');\n'
133     + 'select(1, 3); toggle("underline")',
134     '\'<span style="text-decoration: underline;">a</span><span style="text-decoration: line-through;">b</span>c\'');
135 shouldBe('content(\'a<span style="text-decoration: underline;"><span style="text-decoration: line-through;">b</span>c</span>\');\n'
136     + 'select(0, 2); toggle("underline")',
137     '\'<span style="text-decoration: underline;">a<span style="text-decoration: line-through underline;">b</span>c</span>\'');
138 shouldBe('content(\'a<span style="text-decoration: line-through;"><span style="text-decoration: underline;">bc</span></span>\');\n'
139     + 'select(0, 2); toggle("underline")',
140     '\'<span style="text-decoration: underline;">a</span><span style="text-decoration: line-through;"><span style="text-decoration: underline;">bc</span></span>\'');
141 shouldBe('content(\'a<span style="text-decoration: underline;"><b><span style="text-decoration: line-through;">bc</span></b></span>\');\n'
142     + 'select(0, 2); toggle("underline")',
143     '\'<span style="text-decoration: underline;">a<b><span style="text-decoration: line-through;"><span style="text-decoration: underline line-through;">b</span>c</span></b></span>\'');
144
145 document.body.removeChild(testContainer);
146
147 var successfullyParsed = true;
148
149 </script>
150 <script src="../../resources/js-test-post.js"></script>
151 </body>
152 </html>