Editing tests should use testRunner instead of layoutTestController
[WebKit-https.git] / LayoutTests / editing / execCommand / script-tests / toggle-style-2.js
1 description("Test to make sure we remove span tags with no attributes if we removed the last attribute.")
2
3 var testContainer = document.createElement("div");
4 testContainer.contentEditable = true;
5 document.body.appendChild(testContainer);
6
7 function testSingleToggle(toggleCommand, initialContents, expectedContents)
8 {
9     testContainer.innerHTML = initialContents;
10     window.getSelection().selectAllChildren(testContainer);
11     document.execCommand(toggleCommand, false, null);
12     if (testContainer.innerHTML === expectedContents) {
13         testPassed("one " + toggleCommand + " command converted " + initialContents + " to " + expectedContents);
14     } else {
15         testFailed("one " + toggleCommand + " command converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
16     }
17 }
18
19 function testDoubleToggle(toggleCommand, initialContents, expectedContents)
20 {
21     testContainer.innerHTML = initialContents;
22     window.getSelection().selectAllChildren(testContainer);
23     document.execCommand(toggleCommand, false, null);
24     document.execCommand(toggleCommand, false, null);
25     if (testContainer.innerHTML === expectedContents) {
26         testPassed("two " + toggleCommand + " commands converted " + initialContents + " to " + expectedContents);
27     } else {
28         testFailed("two " + toggleCommand + " commands converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
29     }
30 }
31
32 testSingleToggle("underline", "test", "<u>test</u>");
33 testSingleToggle("underline", "<u><b><strike>test</strike></b></u>", "<b><strike>test</strike></b>");
34 testDoubleToggle("underline", "test", "test");
35 testSingleToggle("strikethrough", "test", "<strike>test</strike>");
36 testSingleToggle("strikethrough", "<u><b><strike>test</strike></b></u>", "<u><b>test</b></u>");
37 testDoubleToggle("strikethrough", "test", "test");
38
39 testSingleToggle("strikethrough", "<u>test</u>", "<u><strike>test</strike></u>");
40 testSingleToggle("underline", "<strike>test</strike>", "<u><strike>test</strike></u>");
41
42 testSingleToggle("strikethrough", '<span style="text-decoration: overline;">test</span>', '<span style="text-decoration: overline;"><strike>test</strike></span>');
43 testSingleToggle("underline", '<span style="text-decoration: overline;">test</span>', '<span style="text-decoration: overline;"><u>test</u></span>');
44
45 document.body.removeChild(testContainer);
46
47 var successfullyParsed = true;