1 description('Test to make sure WebKit adds just one element when applying inline style and removes redundant styled elements.');
3 var testContainer = document.createElement("div");
4 testContainer.contentEditable = true;
5 document.body.appendChild(testContainer);
7 function testSingleToggle(toggleCommand, value, initialContents, expectedContents)
9 testContainer.innerHTML = initialContents;
10 window.getSelection().selectAllChildren(testContainer);
11 document.execCommand('styleWithCSS', false, 'false');
12 document.execCommand(toggleCommand, false, value);
13 var action = toggleCommand + '(' + value + ') on all of "' + initialContents + '" yields "' + testContainer.innerHTML + '"';
14 if (testContainer.innerHTML == expectedContents)
17 testFailed(action + ', expected "' + expectedContents + '"');
20 testSingleToggle("fontSize", 4, 'hello <font size="4">world</font> WebKit', '<font size="4">hello world WebKit</font>');
21 testSingleToggle("fontName", "Arial", 'hello <b><font face="Arial">world</font></b> WebKit', '<font face="Arial">hello <b>world</b> WebKit</font>');
22 testSingleToggle("italic", null, 'hello <u><i title="message">world </i><i>WebKit</i></u>', '<i>hello <u><span title="message">world </span>WebKit</u></i>');
23 testSingleToggle("bold", null, 'hello <i><b>world</b> WebKit</i>', '<b>hello <i>world WebKit</i></b>');
24 testSingleToggle("bold", null, 'hello <i><b class="test">world</b> WebKit</i>', '<b>hello <i><span class="test">world</span> WebKit</i></b>');
25 testSingleToggle("bold", null, 'hello <b contenteditable="false">world</b> <b>WebKit </b><u><b>rocks</b></u>', '<b>hello </b><b contenteditable="false">world</b><b> WebKit <u>rocks</u></b>');
26 testSingleToggle("strikeThrough", null, 'hello <b>world <strike>WebKit</strike></b>', '<strike>hello <b>world WebKit</b></strike>');
27 testSingleToggle("strikeThrough", null, 'hello <i><strike>world</strike></i><b><strike>WebKit</strike></b> rocks', '<strike>hello <i>world</i><b>WebKit</b> rocks</strike>');
28 testSingleToggle("strikeThrough", null, 'hello <i><strike>world</strike></i> WebKit <b><strike>rocks</strike></b>', '<strike>hello <i>world</i> WebKit <b>rocks</b></strike>');
30 // block nodes and br tests
31 testSingleToggle("bold", null, 'hello<div><i>world</i> <b>WebKit</b></div><div>rocks</div>', '<b>hello</b><div><b><i>world</i> WebKit</b></div><div><b>rocks</b></div>');
32 testSingleToggle("bold", null, 'hello<br style="display: block;"><i><b>world</b></i><br><b>WebKit</b>', '<b>hello<br style="display: block;"><i>world</i><br>WebKit</b>');
33 testSingleToggle("bold", null, 'hello<p><b>world</b> <i><b>W</b>ebKit</i></p><b>rocks</b>', '<b>hello</b><p><b>world <i>WebKit</i></b></p><b>rocks</b>');
35 document.body.removeChild(testContainer);
36 var successfullyParsed = true;