1 description('Test to make sure we push down inline styles properly.');
4 internals.settings.setEditingBehavior('mac');
5 var testContainer = document.createElement("div");
6 testContainer.contentEditable = true;
7 document.body.appendChild(testContainer);
9 function testSingleToggle(toggleCommand, selector, initialContents, expectedContents)
11 testContainer.innerHTML = initialContents;
12 var selected = selector(testContainer);
13 document.execCommand('styleWithCSS', false, 'false');
14 document.execCommand(toggleCommand, false, null);
15 var action = toggleCommand + ' on ' + selected + ' of ' + initialContents + " yields " + testContainer.innerHTML;
16 if (testContainer.innerHTML == expectedContents)
19 testFailed(action + ", expected " + expectedContents);
22 function selectAll(container) {
23 window.getSelection().selectAllChildren(container);
27 function selectTest(container) {
28 window.getSelection().selectAllChildren(document.getElementById('test'));
32 function selectFirstWord(container) {
33 window.getSelection().collapse(container, 0);
34 window.getSelection().modify('extend', 'forward', 'word');
38 function selectSecondWord(container) {
39 window.getSelection().collapse(container, 0);
40 window.getSelection().modify('move', 'forward', 'word');
41 window.getSelection().modify('extend', 'forward', 'word');
45 function selectLastTwoWords(container) {
46 window.getSelection().collapse(container, container.childNodes.length);
47 window.getSelection().modify('extend', 'backward', 'word');
48 window.getSelection().modify('extend', 'backward', 'word');
49 return 'last two words';
52 testSingleToggle("bold", selectFirstWord, '<b><div>hello</div> world</b>', '<div>hello</div><b> world</b>');
53 testSingleToggle("bold", selectFirstWord, '<b><div>hello</div>world</b>', '<div>hello</div><b>world</b>');
54 testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><em>world</em></b>', '<div>hello</div><em style="font-weight: bold;">world</em>');
55 testSingleToggle("bold", selectSecondWord, '<b>hello <div>world</div></b>', '<b>hello </b><div>world</div>');
56 testSingleToggle("bold", selectSecondWord, '<b><em>hello</em> <div>world</div></b>', '<em style="font-weight: bold;">hello</em> <div>world</div>');
57 testSingleToggle("bold", selectAll, '<b> <div>text</div> </b>', ' <div>text</div> ');
58 testSingleToggle("bold", selectAll, '<b><strike><div>text</div></strike></b>', '<strike><div>text</div></strike>');
59 testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><div>world</div></b>', '<div>hello</div><div style="font-weight: bold;">world</div>');
60 testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><div style="font-weight: normal;">world</div>webkit</b>', '<div>hello</div><div style="font-weight: normal;">world</div><b>webkit</b>');
61 testSingleToggle("bold", selectSecondWord, '<b style="font-style: italic;">hello world</b>', '<b style="font-style: italic;">hello</b><span style="font-style: italic;"> world</span>');
63 testSingleToggle("underline", selectSecondWord, '<u>hello <b>world</b> webkit</u>', '<u>hello</u> <b>world</b><u> webkit</u>');
64 testSingleToggle("underline", selectLastTwoWords, '<u>hello <b>world</b> webkit</u>', '<u>hello </u><b>world</b> webkit');
65 testSingleToggle("underline", selectLastTwoWords, '<u>hello <b>world webkit</b></u>', '<u>hello </u><b>world webkit</b>');
66 testSingleToggle("underline", selectSecondWord, '<u>hello <b>world webkit</b></u>', '<u>hello</u> <b>world<u> webkit</u></b>');
67 testSingleToggle("underline", selectSecondWord, '<u><b>hello world</b> webkit</u>', '<b><u>hello</u> world</b><u> webkit</u>');
68 testSingleToggle("underline", selectSecondWord, '<u><strike>hello world</strike></u>', '<strike><u>hello</u> world</strike>');
69 testSingleToggle("underline", selectSecondWord, '<u><strike>hello world webkit</strike></u>', '<strike><u>hello</u> world<u> webkit</u></strike>');
70 testSingleToggle("underline", selectSecondWord, '<u><strike>hello world</strike> webkit</u>', '<strike><u>hello</u> world</strike><u> webkit</u>');
71 testSingleToggle("underline", selectSecondWord, '<u>hello <em><code>world webkit</code></em> rocks</u>', '<u>hello</u> <em><code>world<u> webkit</u></code></em><u> rocks</u>');
73 testSingleToggle("strikeThrough", selectAll, '<s style="color: blue;">hello world</strike>', '<span style="color: blue;">hello world</span>');
74 testSingleToggle("strikeThrough", selectFirstWord, '<s style="color: blue;"><div>hello</div> <b>world</b> webkit</strike>', '<span style="color: blue;"><div>hello</div> <b style="text-decoration-line: line-through;">world</b><strike> webkit</strike></span>');
76 document.body.removeChild(testContainer);
78 var successfullyParsed = true;