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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/ParentNode/prepend.html

Issue 2783813003: Move tests for ChildNode and ParentNode to dom/child_node/ and dom/parent_node/. (Closed)
Patch Set: Created 3 years, 8 months 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 <script src="../../../resources/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <script>
5
6 test(function () {
7 var node = document.createElement('div');
8 assert_true('prepend' in node);
9 var prepend = 'mine';
10 var getAttribute = 'mine';
11 with (node) {
12 assert_true(prepend === 'mine');
13 assert_false(getAttribute === 'mine');
14 }
15 assert_true('Symbol' in window);
16 var unscopables = Object.getPrototypeOf(node)[Symbol.unscopables];
17 assert_true(unscopables.prepend);
18 }, 'ChildNode.prepend() unscopable');
19
20 function test_prepend(node, nodeName) {
21
22 test(function() {
23 var parent = node.cloneNode();
24 parent.prepend();
25 assert_array_equals(parent.childNodes, []);
26 }, nodeName + '.prepend() without any argument, on a parent having no child. ');
27
28 test(function() {
29 var parent = node.cloneNode();
30 parent.prepend(null);
31 assert_equals(parent.childNodes[0].textContent, 'null');
32 }, nodeName + '.prepend() with null as an argument, on a parent having no ch ild.');
33
34 test(function() {
35 var parent = node.cloneNode();
36 parent.prepend(undefined);
37 assert_equals(parent.childNodes[0].textContent, 'undefined');
38 }, nodeName + '.prepend() with undefined as an argument, on a parent having no child.');
39
40 test(function() {
41 var parent = node.cloneNode();
42 parent.prepend('text');
43 assert_equals(parent.childNodes[0].textContent, 'text');
44 }, nodeName + '.prepend() with only text as an argument, on a parent having no child.');
45
46 test(function() {
47 var parent = node.cloneNode();
48 var x = document.createElement('x');
49 parent.prepend(x);
50 assert_array_equals(parent.childNodes, [x]);
51 }, nodeName + '.prepend() with only one element as an argument, on a parent having no child.');
52
53 test(function() {
54 var parent = node.cloneNode();
55 var child = document.createElement('test');
56 parent.appendChild(child);
57 parent.prepend(null);
58 assert_equals(parent.childNodes[0].textContent, 'null');
59 assert_equals(parent.childNodes[1], child);
60 }, nodeName + '.prepend() with null as an argument, on a parent having a chi ld.');
61
62 test(function() {
63 var parent = node.cloneNode();
64 var x = document.createElement('x');
65 var child = document.createElement('test');
66 parent.appendChild(x);
67 parent.appendChild(child);
68 parent.prepend(child, x);
69 assert_array_equals(parent.childNodes, [child, x]);
70 }, nodeName + '.prepend() with all children as arguments, on a parent having two children.');
71
72 test(function() {
73 var parent = node.cloneNode();
74 var x = document.createElement('x');
75 var child = document.createElement('test');
76 parent.appendChild(child);
77 parent.prepend(x, 'text');
78 assert_equals(parent.childNodes[0], x);
79 assert_equals(parent.childNodes[1].textContent, 'text');
80 assert_equals(parent.childNodes[2], child);
81 }, nodeName + '.prepend() with one element and text as argument, on a parent having a child.');
82
83 test(function() {
84 var parent = node.cloneNode();
85 var doc2 = document.implementation.createDocument("http://www.w3.org/199 9/xhtml", "html");
86 assert_throws('HierarchyRequestError', () => { parent.prepend(doc2, "foo ") });
87 assert_equals(parent.firstChild, null);
88 }, nodeName + '.prepend() with a Document as an argument should throw.');
89 }
90
91 test_prepend(document.createElement('div'), 'Element');
92 test_prepend(document.createDocumentFragment(), 'DocumentFrgment');
93 </script>
94 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698