Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / execCommand / remove-format-elements.html
blobf82f0699309223294e280e4ccc0dec1b9b8db9ea
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <div id="test" contenteditable></div>
5 <dl>
6 <dt>Removed</dt>
7 <dd id="removed"></dd>
8 <dt>Preserved</dt>
9 <dd id="preserved"></dd>
10 <dt>Exceptions</dt>
11 <dd id="exceptions"></dd>
12 </dl>
13 <script type="text/javascript">
15 if (window.testRunner)
16 testRunner.dumpAsText();
18 var elements = [ "noscript", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio",
19 "b", "base", "basefont", "bdo", "bgsound", "big", "blockquote", "body", "br", "button",
20 "canvas", ["table", "caption"], "center", "cite", "code", ["table", "col"], ["table", "colgroup"], "command",
21 "datagrid", "datalist", "dcell", "dcol", "dd", "del", "details", "dfn", "dir", "div", "dl", "drow", "dt",
22 "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset",
23 "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html",
24 "i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "layer", "legend", ["ul", "li"], "link", "listing",
25 "main", "map", "mark", "marquee", "menu", "meta", "meter", "nav", "nobr", "noembed", "noframes", "nolayer", "noscript",
26 "object", "ol", "optgroup", "option", "p", "param", "plaintext", "pre", "progress", "q", "rp", "rt", "ruby",
27 "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup",
28 "table", ["table", "tbody"], ["table", "td"], "textarea", ["table", "tfoot"], ["table", "th"], ["table", "thead"],
29 "title", ["table", "tr"], "track", "tt", "u", "ul", "var", "video", "wbr", "xmp" ];
31 function addResult(container, name, annotation, description)
33 if (container.innerHTML.length && !annotation)
34 container.innerHTML += ', ';
35 container.innerHTML += name;
36 if (annotation)
37 container.appendChild(document.createTextNode(" (" + annotation + ")"));
38 if (description)
39 container.appendChild(document.createTextNode(description));
40 if (annotation || description)
41 container.appendChild(document.createElement('br'));
44 function contains(node, descendant)
46 while (descendant && descendant != node && descendant.parentNode)
47 descendant = descendant.parentNode;
48 return descendant == node;
51 var test = document.getElementById('test');
52 for (var i = 0; i < elements.length; i++) {
53 var elementName;
54 var instance = null;
55 var container = null;
56 if (typeof elements[i] == 'string') {
57 elementName = elements[i];
58 instance = document.createElement(elementName)
59 container = instance;
60 } else {
61 var elementList = elements[i];
62 for (var j = 0; j < elementList.length; j++) {
63 var node = document.createElement(elementList[j]);
64 if (!container)
65 container = node;
66 if (instance)
67 instance.appendChild(node);
68 instance = node;
70 elementName = elementList[elementList.length - 1];
72 var dummy_text = document.createTextNode('hello=1;');
73 if (instance === undefined) {
74 addResult(document.getElementById('exceptions'), elementName, test.innerHTML);
75 continue;
77 test.innerHTML = "";
78 try {
79 instance.appendChild(dummy_text); // this may fail for non-container elements.
80 } catch (error) { }
81 test.appendChild(container);
82 test.appendChild(document.createTextNode(' webkit=2;'));
83 var ec = ''
84 if (window.getSelection) {
85 window.getSelection().selectAllChildren(test);
86 } else {
87 var range = document.body.createTextRange();
88 range.moveToElementText(test.firstChild);
89 try { range.select(); }
90 catch (error) { ec += ' failed to select'; }
92 document.execCommand('removeFormat', false, null);
94 if (ec) {
95 addResult(document.getElementById('exceptions'), elementName, test.innerHTML, ec);
96 continue;
99 if (!test.firstChild || test.firstChild.nodeType == 3 /*TextNode*/)
100 addResult(document.getElementById('removed'), elementName)
101 else if (contains(test, instance) && (instance.innerHTML == "" || instance.innerHTML == "hello=1;" || elementName == "keygen"))
102 addResult(document.getElementById('preserved'), elementName);
103 else
104 addResult(document.getElementById('exceptions'), elementName, test.innerHTML);
106 document.body.removeChild(test);
108 </script>
109 </body>
110 </html>