1 description("Test to make sure we preserve styles when removing links")
3 var testContainer = document.createElement("div");
4 testContainer.contentEditable = true;
5 document.body.appendChild(testContainer);
7 function testSingleToggle(toggleCommand, initialContents, selector, expectedContents)
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)
16 testFailed(action + ', expected "' + expectedContents + '"');
19 function selectAll(container) {
20 window.getSelection().selectAllChildren(container);
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';
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';
38 function selectLastWord(container) {
39 window.getSelection().collapse(container, container.childNodes.length);
40 window.getSelection().modify('extend', 'backward', 'word');
45 internals.settings.setEditingBehavior('mac');
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>');
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>');
70 document.body.removeChild(testContainer);
72 var successfullyParsed = true;