Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / editing / style / script-tests / push-down-inline-styles.js
1 description('Test to make sure we push down inline styles properly.');
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     if (document.getElementById('test'))
11         window.getSelection().selectAllChildren(document.getElementById('test'));
12     else
13         window.getSelection().selectAllChildren(testContainer);
14     document.execCommand('styleWithCSS', false, 'false');
15     document.execCommand(toggleCommand, false, null);
16     if (testContainer.innerHTML === expectedContents) {
17         testPassed(toggleCommand + " converted " + initialContents + " to " + expectedContents);
18     } else {
19         testFailed(toggleCommand + " converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
20     }
21 }
22
23
24 testSingleToggle("bold", '<span style="font-weight: 900;"> <div>text</div> </span>', ' <div>text</div> ');
25 testSingleToggle("bold", '<span style="font-weight: 900;"><div>text</div></span>', '<div>text</div>');
26 testSingleToggle("bold", '<span style="font-weight: 900;"><div id="test">hello</div><div>world</div></span>', '<div id="test">hello</div><div style="font-weight: 900;">world</div>');
27 testSingleToggle("bold", '<div style="font-weight: bold;">hello<div id="test">world</div></div>', '<div><b>hello</b><div id="test">world</div></div>');
28 testSingleToggle("bold", '<span style="font-weight: bold;">hello<span id="test">world</div></div>', '<b>hello</b><span id="test">world</span>');
29 testSingleToggle("bold", '<span style="font-style: italic; font-weight: bold;">hello<span id="test">world</div></div>', '<span style="font-style: italic;"><b>hello</b><span id="test">world</span></span>');
30 testSingleToggle("bold", '<span style="font-weight: bold;"><div id="test">hello</div><div style="font-weight: normal;"><div>world</div>webkit</div>', '<div id="test">hello</div><div>world</div>webkit');
31 testSingleToggle("italic", '<span style="font-style: italic;"><div>hello</div></span>', '<div>hello</div>');
32 testSingleToggle("italic", '<span style="font-style: italic;"><div id="test">hello</div><span style="font-style: oblique;">world</span>', '<div id="test">hello</div><span style="font-style: oblique;">world</span>');
33 testSingleToggle("italic", '<span style="font-style: italic; font-weight: bold;"><div>hello</div></span>', '<span style="font-weight: bold;"><div>hello</div></span>');
34 testSingleToggle("italic", '<span style="font-style: italic; text-decoration: line-through;"><div>hello</div></span>', '<span style="text-decoration-line: line-through;"><div>hello</div></span>');
35 testSingleToggle("italic", '<span style="font-style: italic;">hello<div id="test">world</div><blockquote>webkit</blockquote></span>', '<i>hello</i><div id="test">world</div><blockquote style="font-style: italic;">webkit</blockquote>');
36 testSingleToggle("italic", '<span style="font-style: italic;">hello <span id="test">world</span> webkit</span>', '<i>hello </i><span id="test">world</span><i> webkit</i>');
37 testSingleToggle("underline", '<span style="text-decoration: underline;"><div id="test">hello</div>world</span>', '<div id="test">hello</div><u>world</u>');
38 testSingleToggle("underline", '<span style="text-decoration: underline;"><div id="test">hello</div><blockquote>world<br>webkit</blockquote></span>', '<div id="test">hello</div><blockquote style="text-decoration-line: underline;">world<br>webkit</blockquote>');
39 testSingleToggle("underline", '<span style="text-decoration: underline;">hello<div id="test">world</div>webkit</u>', '<u>hello</u><div id="test">world</div><u>webkit</u>');
40 testSingleToggle("underline",
41     '<div style="text-decoration: underline;"><div>hello</span></div><div id="test">webkit</div><span style="font-style: italic;">rocks</span>',
42     '<div><div style="text-decoration-line: underline;">hello</span></div><div id="test">webkit</div><u><span style="font-style: italic;">rocks</span></u></div>');
43 testSingleToggle("underline", '<span style="text-decoration-line: underline;"><div style="text-decoration-line: line-through;">hello</div><div id="test">world</div></span>', '<div style="text-decoration-line: underline line-through;">hello</div><div id="test">world</div>');
44 testSingleToggle("strikeThrough", '<span style="text-decoration-line: line-through;"><div id="test">hello</div><div style="text-decoration-line: underline;">world</div></span>', '<div id="test">hello</div><div style="text-decoration-line: line-through underline;">world</div>');
45
46 document.body.removeChild(testContainer);
47
48 var successfullyParsed = true;