Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / editing / execCommand / script-tests / toggle-unlink-mac.js
1 description("Test to make sure we preserve styles when removing links")
2
3 var testContainer = document.createElement("div");
4 testContainer.contentEditable = true;
5 document.body.appendChild(testContainer);
6
7 function testSingleToggle(toggleCommand, initialContents, selector, expectedContents)
8 {
9     testContainer.innerHTML = initialContents;
10     var selected = selector(testContainer);
11     document.execCommand(toggleCommand, false, 'http://webkit.org/');
12     action = toggleCommand + ' on ' + selected + ' of "' + initialContents + '" yields "' + testContainer.innerHTML + '"';
13     if (testContainer.innerHTML === expectedContents)
14         testPassed(action);
15     else
16         testFailed(action + ', expected "' + expectedContents + '"');
17 }
18
19 function selectAll(container) {
20     window.getSelection().selectAllChildren(container);
21     return 'all';
22 }
23
24 function selectFirstTwoWords(container) {
25     window.getSelection().collapse(container, 0);
26     window.getSelection().modify('extend', 'forward', 'word');
27     window.getSelection().modify('extend', 'forward', 'word');
28     return 'first two words';
29 }
30
31 function selectLastTwoWords(container) {
32     window.getSelection().collapse(container, container.childNodes.length);
33     window.getSelection().modify('extend', 'backward', 'word');
34     window.getSelection().modify('extend', 'backward', 'word');
35     return 'last two words';
36 }
37
38 function selectLastWord(container) {
39     window.getSelection().collapse(container, container.childNodes.length);
40     window.getSelection().modify('extend', 'backward', 'word');
41     return 'last word';
42 }
43
44 if (window.internals)
45    internals.settings.setEditingBehavior('mac');
46
47 testSingleToggle("unlink", 'hello <b>world</b>', selectAll, 'hello <b>world</b>');
48 testSingleToggle("unlink", '<a href="http://webkit.org/"><u>hello world</u></a>', selectAll, '<u>hello world</u>');
49 testSingleToggle("unlink", 'hello <i><a href="http://webkit.org/">world</a></i>', selectAll, 'hello <i>world</i>');
50 testSingleToggle("unlink", 'hello <a href="http://webkit.org/" style="font-weight: bold;">world</a>', selectAll, 'hello <b>world</b>');
51 testSingleToggle("unlink", 'hello <a href="http://webkit.org/" style="color: blue;">world</a> WebKit', selectAll, 'hello <font color="#0000ff">world</font> WebKit');
52 testSingleToggle("unlink", 'hello <a href="http://webkit.org/" style="color: blue; display: block;">world</a> WebKit',
53     selectAll, 'hello <font color="#0000ff"><span style="display: block;">world</span></font> WebKit');
54 testSingleToggle("unlink", '<a href="http://webkit.org/" style="font-size: large;">hello world</a> WebKit',
55     selectLastTwoWords, '<a href="http://webkit.org/" style="font-size: large;">hello </a><font size="4">world</font> WebKit');
56 testSingleToggle("unlink", 'hello <a href="http://webkit.org/" style="font-size: large;">world <span style="font-size: small;">WebKit</span> rocks</a>',
57     selectLastTwoWords, 'hello <a href="http://webkit.org/"><font size="4">world </font></a><span style="font-size: small;">WebKit</span><font size="4"> rocks</font>');
58 testSingleToggle("unlink", 'hello <a href="http://webkit.org/" style="font-style: italic;"><b>world</b> WebKit</a>',
59     selectFirstTwoWords, 'hello <b style="font-style: italic;">world</b><a href="http://webkit.org/"><i> WebKit</i></a>');
60
61 testSingleToggle("unlink", '<a href="http://webkit.org/" style="background-color: yellow;"><div>hello</div><div>world</div></a>',
62     selectAll, '<div style="background-color: yellow;">hello</div><div style="background-color: yellow;">world</div>');
63 testSingleToggle("unlink", 'hello<a href="http://webkit.org/" style="background-color: yellow;"><div>world</div></a>WebKit',
64     selectAll, 'hello<div style="background-color: yellow;">world</div><span style="background-color: yellow;">WebKit</span>');
65 testSingleToggle("unlink", '<a href="http://webkit.org/" style="font-weight: bold;"><div>hello</div><div>world WebKit</div></a>',
66     selectLastTwoWords, '<a href="http://webkit.org/"><div style="font-weight: bold;">hello</div></a><div style="font-weight: bold;">world WebKit</div>');
67 testSingleToggle("unlink", '<a href="http://webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>',
68     selectLastWord, '<a href="http://webkit.org/"><div style="font-weight: normal;">hello</div></a><div style="font-weight: bold;">world</div>');
69
70 document.body.removeChild(testContainer);
71
72 var successfullyParsed = true;