Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/Node-cloneNode.html

Issue 1529523002: Import dom/ from web-platform-tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak W3CImportExpectations Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>Node.cloneNode</title>
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-node-clonenode">
5 <script src="../../../../resources/testharness.js"></script>
6 <script src="../../../../resources/testharnessreport.js"></script>
7 <div id=log></div>
8 <script>
9 function assert_equal_node(nodeA, nodeB) {
10 assert_equals(nodeB.nodeType, nodeA.nodeType, "nodeType");
11 assert_equals(nodeB.nodeName, nodeA.nodeName, "nodeName");
12
13 if (nodeA.nodeType === Node.ELEMENT_NODE) {
14 assert_equals(nodeB.prefix, nodeA.prefix);
15 assert_equals(nodeB.namespaceURI, nodeA.namespaceURI);
16 assert_equals(nodeB.localName, nodeA.localName);
17 assert_equals(nodeB.tagName, nodeA.tagName);
18 assert_not_equals(nodeB.attributes != nodeA.attributes);
19 assert_equals(nodeB.attributes.length, nodeA.attributes.length);
20 for (var i = 0, il = nodeA.attributes.length; i < il; ++i) {
21 assert_not_equals(nodeB.attributes[i], nodeA.attributes[i]);
22 assert_equals(nodeB.attributes[i].name, nodeA.attributes[i].name);
23 assert_equals(nodeB.attributes[i].prefix, nodeA.attributes[i].prefix);
24 assert_equals(nodeB.attributes[i].namespaceURI, nodeA.attributes[i].namesp aceURI);
25 assert_equals(nodeB.attributes[i].value, nodeA.attributes[i].value);
26 }
27 }
28 }
29
30 function check_copy(orig, copy, type) {
31 assert_not_equals(orig, copy);
32 assert_equal_node(orig, copy);
33 assert_true(orig instanceof type, "Should be type");
34 assert_true(copy instanceof type, "Should be type");
35 }
36
37 function create_element_and_check(localName, type) {
38 test(function() {
39 var element = document.createElement(localName);
40 var copy = element.cloneNode();
41 check_copy(element, copy, type);
42 }, "createElement(" + localName + ")");
43 }
44
45 // test1: createElement
46 test(function() {
47 create_element_and_check("a", HTMLAnchorElement);
48 create_element_and_check("abbr", HTMLElement);
49 create_element_and_check("acronym", HTMLElement);
50 create_element_and_check("address", HTMLElement);
51 create_element_and_check("applet", HTMLAppletElement);
52 create_element_and_check("area", HTMLAreaElement);
53 create_element_and_check("article", HTMLElement);
54 create_element_and_check("aside", HTMLElement);
55 create_element_and_check("audio", HTMLAudioElement);
56 create_element_and_check("b", HTMLElement);
57 create_element_and_check("base", HTMLBaseElement);
58 create_element_and_check("bdi", HTMLElement);
59 create_element_and_check("bdo", HTMLElement);
60 create_element_and_check("bgsound", HTMLElement);
61 create_element_and_check("big", HTMLElement);
62 create_element_and_check("blockquote",HTMLElement);
63 create_element_and_check("body", HTMLBodyElement);
64 create_element_and_check("br", HTMLBRElement);
65 create_element_and_check("button", HTMLButtonElement);
66 create_element_and_check("canvas", HTMLCanvasElement);
67 create_element_and_check("caption", HTMLTableCaptionElement);
68 create_element_and_check("center", HTMLElement);
69 create_element_and_check("cite", HTMLElement);
70 create_element_and_check("code", HTMLElement);
71 create_element_and_check("col", HTMLTableColElement);
72 create_element_and_check("colgroup", HTMLTableColElement);
73 create_element_and_check("data", HTMLDataElement);
74 create_element_and_check("datalist", HTMLDataListElement);
75 create_element_and_check("dialog", HTMLDialogElement);
76 create_element_and_check("dd", HTMLElement);
77 create_element_and_check("del", HTMLModElement);
78 create_element_and_check("details", HTMLElement);
79 create_element_and_check("dfn", HTMLElement);
80 create_element_and_check("dir", HTMLDirectoryElement);
81 create_element_and_check("div", HTMLDivElement);
82 create_element_and_check("dl", HTMLDListElement);
83 create_element_and_check("dt", HTMLElement);
84 create_element_and_check("embed", HTMLEmbedElement);
85 create_element_and_check("fieldset", HTMLFieldSetElement);
86 create_element_and_check("figcaption",HTMLElement);
87 create_element_and_check("figure", HTMLElement);
88 create_element_and_check("font", HTMLFontElement);
89 create_element_and_check("footer", HTMLElement);
90 create_element_and_check("form", HTMLFormElement);
91 create_element_and_check("frame", HTMLFrameElement);
92 create_element_and_check("frameset", HTMLFrameSetElement);
93 create_element_and_check("h1", HTMLHeadingElement);
94 create_element_and_check("h2", HTMLHeadingElement);
95 create_element_and_check("h3", HTMLHeadingElement);
96 create_element_and_check("h4", HTMLHeadingElement);
97 create_element_and_check("h5", HTMLHeadingElement);
98 create_element_and_check("h6", HTMLHeadingElement);
99 create_element_and_check("head", HTMLHeadElement);
100 create_element_and_check("header", HTMLElement);
101 create_element_and_check("hgroup", HTMLElement);
102 create_element_and_check("hr", HTMLHRElement);
103 create_element_and_check("html", HTMLHtmlElement);
104 create_element_and_check("i", HTMLElement);
105 create_element_and_check("iframe", HTMLIFrameElement);
106 create_element_and_check("img", HTMLImageElement);
107 create_element_and_check("input", HTMLInputElement);
108 create_element_and_check("ins", HTMLModElement);
109 create_element_and_check("isindex", HTMLElement);
110 create_element_and_check("kbd", HTMLElement);
111 create_element_and_check("label", HTMLLabelElement);
112 create_element_and_check("legend", HTMLLegendElement);
113 create_element_and_check("li", HTMLLIElement);
114 create_element_and_check("link", HTMLLinkElement);
115 create_element_and_check("main", HTMLElement);
116 create_element_and_check("map", HTMLMapElement);
117 create_element_and_check("mark", HTMLElement);
118 create_element_and_check("marquee", HTMLElement);
119 create_element_and_check("meta", HTMLMetaElement);
120 create_element_and_check("meter", HTMLMeterElement);
121 create_element_and_check("nav", HTMLElement);
122 create_element_and_check("nobr", HTMLElement);
123 create_element_and_check("noframes", HTMLElement);
124 create_element_and_check("noscript", HTMLElement);
125 create_element_and_check("object", HTMLObjectElement);
126 create_element_and_check("ol", HTMLOListElement);
127 create_element_and_check("optgroup", HTMLOptGroupElement);
128 create_element_and_check("option", HTMLOptionElement);
129 create_element_and_check("output", HTMLOutputElement);
130 create_element_and_check("p", HTMLParagraphElement);
131 create_element_and_check("param", HTMLParamElement);
132 create_element_and_check("pre", HTMLPreElement);
133 create_element_and_check("progress", HTMLProgressElement);
134 create_element_and_check("q", HTMLQuoteElement);
135 create_element_and_check("rp", HTMLElement);
136 create_element_and_check("rt", HTMLElement);
137 create_element_and_check("ruby", HTMLElement);
138 create_element_and_check("s", HTMLElement);
139 create_element_and_check("samp", HTMLElement);
140 create_element_and_check("script", HTMLScriptElement);
141 create_element_and_check("section", HTMLElement);
142 create_element_and_check("select", HTMLSelectElement);
143 create_element_and_check("small", HTMLElement);
144 create_element_and_check("source", HTMLSourceElement);
145 create_element_and_check("spacer", HTMLElement);
146 create_element_and_check("span", HTMLSpanElement);
147 create_element_and_check("strike", HTMLElement);
148 create_element_and_check("style", HTMLStyleElement);
149 create_element_and_check("sub", HTMLElement);
150 create_element_and_check("summary", HTMLElement);
151 create_element_and_check("sup", HTMLElement);
152 create_element_and_check("table", HTMLTableElement);
153 create_element_and_check("tbody", HTMLTableSectionElement);
154 create_element_and_check("td", HTMLTableDataCellElement);
155 create_element_and_check("template", HTMLTemplateElement);
156 create_element_and_check("textarea", HTMLTextAreaElement);
157 create_element_and_check("th", HTMLTableHeaderCellElement);
158 create_element_and_check("time", HTMLTimeElement);
159 create_element_and_check("title", HTMLTitleElement);
160 create_element_and_check("tr", HTMLTableRowElement);
161 create_element_and_check("tt", HTMLElement);
162 create_element_and_check("track", HTMLTrackElement);
163 create_element_and_check("u", HTMLElement);
164 create_element_and_check("ul", HTMLUListElement);
165 create_element_and_check("var", HTMLElement);
166 create_element_and_check("video", HTMLVideoElement);
167 create_element_and_check("unknown", HTMLUnknownElement);
168 create_element_and_check("wbr", HTMLElement);
169 }, "");
170
171 test(function() {
172 var fragment = document.createDocumentFragment();
173 var copy = fragment.cloneNode();
174 check_copy(fragment, copy, DocumentFragment);
175 }, "createDocumentFragment");
176
177 test(function() {
178 var text = document.createTextNode("hello world");
179 var copy = text.cloneNode();
180 check_copy(text, copy, Text);
181 assert_equals(text.data, copy.data);
182 assert_equals(text.wholeText, copy.wholeText);
183 }, "createTextNode");
184
185 test(function() {
186 var comment = document.createComment("a comment");
187 var copy = comment.cloneNode();
188 check_copy(comment, copy, Comment);
189 assert_equals(comment.data, copy.data);
190 }, "createComment");
191
192 test(function() {
193 var el = document.createElement("foo");
194 el.setAttribute("a", "b");
195 el.setAttribute("c", "d");
196 var c = el.cloneNode();
197 check_copy(el, c, Element);
198 }, "createElement with attributes")
199
200 test(function() {
201 var el = document.createElementNS("http://www.w3.org/1999/xhtml", "foo:div");
202 var c = el.cloneNode();
203 check_copy(el, c, HTMLDivElement);
204 }, "createElementNS HTML")
205
206 test(function() {
207 var el = document.createElementNS("http://www.example.com/", "foo:div");
208 var c = el.cloneNode();
209 check_copy(el, c, Element);
210 }, "createElementNS non-HTML")
211
212 test(function() {
213 var pi = document.createProcessingInstruction("target", "data");
214 var copy = pi.cloneNode();
215 check_copy(pi, copy, ProcessingInstruction);
216 assert_equals(pi.data, copy.data);
217 assert_equals(pi.target, pi.target);
218 }, "createProcessingInstruction");
219
220 test(function() {
221 var doctype = document.implementation.createDocumentType("html", "public", " system");
222 var copy = doctype.cloneNode();
223 check_copy(doctype, copy, DocumentType);
224 assert_equals(doctype.name, copy.name);
225 assert_equals(doctype.publicId, copy.publicId);
226 assert_equals(doctype.systemId, copy.systemId);
227 }, "implementation.createDocumentType");
228
229 test(function() {
230 var doc = document.implementation.createDocument(null, null);
231 var copy = doc.cloneNode();
232 check_copy(doc, copy, Document);
233 assert_equals(doc.contentType, copy.contentType);
234 }, "implementation.createDocument");
235
236 test(function() {
237 var html = document.implementation.createHTMLDocument("title");
238 var copy = html.cloneNode();
239 check_copy(html, copy, Document);
240 assert_equals(copy.title, "");
241 }, "implementation.createHTMLDocument");
242
243 test(function() {
244 var parent = document.createElement("div");
245 var child1 = document.createElement("div");
246 var child2 = document.createElement("div");
247 var grandChild = document.createElement("div");
248
249 child2.appendChild(grandChild);
250 parent.appendChild(child1);
251 parent.appendChild(child2);
252
253 var deep = true;
254 var copy = parent.cloneNode(deep);
255
256 check_copy(parent, copy, HTMLDivElement);
257 assert_equals(copy.childNodes.length, 2);
258
259 check_copy(child1, copy.childNodes[0], HTMLDivElement);
260 assert_equals(copy.childNodes[0].childNodes.length, 0);
261
262 check_copy(child2, copy.childNodes[1], HTMLDivElement);
263 assert_equals(copy.childNodes[1].childNodes.length, 1);
264 check_copy(grandChild, copy.childNodes[1].childNodes[0], HTMLDivElement);
265
266 deep = false;
267 copy = parent.cloneNode(deep);
268
269 check_copy(parent, copy, HTMLDivElement);
270 assert_equals(copy.childNodes.length, 0);
271 }, "node with children");
272 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698