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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/ChildNode/before.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 child = document.createElement('p');
8 assert_true('before' in child);
9 var before = 'mine';
10 var getAttribute = 'mine';
11 with (child) {
12 assert_true(before === 'mine');
13 assert_false(getAttribute === 'mine');
14 }
15 assert_true('Symbol' in window);
16 var unscopables = Object.getPrototypeOf(child)[Symbol.unscopables];
17 assert_true(unscopables.before);
18 }, 'ChildNode.before() unscopable');
19
20 function test_before(nodeName) {
21 var child;
22 var innerHTML;
23 if (nodeName == 'Comment') {
24 child = document.createComment('test');
25 innerHTML = '<!--test-->';
26 } else if (nodeName == 'Element') {
27 child = document.createElement('test');
28 innerHTML = '<test></test>';
29 } else {
30 child = document.createTextNode('test');
31 innerHTML = 'test';
32 }
33
34 test(function() {
35 var parent = document.createElement('div');
36 parent.appendChild(child);
37 child.before();
38 assert_equals(parent.innerHTML, innerHTML);
39 }, nodeName + '.before() without any argument.');
40
41 test(function() {
42 var parent = document.createElement('div');
43 parent.appendChild(child);
44 child.before(null);
45 var expected = 'null' + innerHTML;
46 assert_equals(parent.innerHTML, expected);
47 }, nodeName + '.before() with null as an argument.');
48
49 test(function() {
50 var parent = document.createElement('div');
51 parent.appendChild(child);
52 child.before(undefined);
53 var expected = 'undefined' + innerHTML;
54 assert_equals(parent.innerHTML, expected);
55 }, nodeName + '.before() with undefined as an argument.');
56
57 test(function() {
58 var parent = document.createElement('div');
59 parent.appendChild(child);
60 child.before('');
61 assert_equals(parent.firstChild.data, '');
62 }, nodeName + '.before() with the empty string as an argument.');
63
64 test(function() {
65 var parent = document.createElement('div');
66 parent.appendChild(child);
67 child.before('text');
68 var expected = 'text' + innerHTML;
69 assert_equals(parent.innerHTML, expected);
70 }, nodeName + '.before() with only text as an argument.');
71
72 test(function() {
73 var parent = document.createElement('div');
74 var x = document.createElement('x');
75 parent.appendChild(child);
76 child.before(x);
77 var expected = '<x></x>' + innerHTML;
78 assert_equals(parent.innerHTML, expected);
79 }, nodeName + '.before() with only one element as an argument.');
80
81 test(function() {
82 var parent = document.createElement('div');
83 var x = document.createElement('x');
84 parent.appendChild(child);
85 child.before(x, 'text');
86 var expected = '<x></x>text' + innerHTML;
87 assert_equals(parent.innerHTML, expected);
88 }, nodeName + '.before() with one element and text as arguments.');
89
90 test(function() {
91 var parent = document.createElement('div');
92 parent.appendChild(child);
93 child.before('text', child);
94 var expected = 'text' + innerHTML;
95 assert_equals(parent.innerHTML, expected);
96 }, nodeName + '.before() with context object itself as the argument.');
97
98 test(function() {
99 var parent = document.createElement('div');
100 var x = document.createElement('x');
101 var y = document.createElement('y');
102 var z = document.createElement('z');
103 parent.appendChild(y);
104 parent.appendChild(child);
105 parent.appendChild(x);
106 child.before(x, y, z);
107 var expected = '<x></x><y></y><z></z>' + innerHTML;
108 assert_equals(parent.innerHTML, expected);
109 }, nodeName + '.before() with all siblings of child as arguments.');
110
111 test(function() {
112 var parent = document.createElement('div');
113 var x = document.createElement('x');
114 var y = document.createElement('y');
115 parent.appendChild(x);
116 parent.appendChild(y);
117 parent.appendChild(child);
118 child.before(y, x);
119 var expected = '<y></y><x></x>' + innerHTML;
120 assert_equals(parent.innerHTML, expected);
121 }, nodeName + '.before() when pre-insert behaves like prepend.');
122
123 test(function() {
124 var parent = document.createElement('div');
125 var x = document.createElement('x');
126 parent.appendChild(x);
127 parent.appendChild(document.createTextNode('1'));
128 var y = document.createElement('y');
129 parent.appendChild(y);
130 parent.appendChild(child);
131 child.before(x, '2');
132 var expected = '1<y></y><x></x>2' + innerHTML;
133 assert_equals(parent.innerHTML, expected);
134 }, nodeName + '.before() with one sibling of child and text as arguments.');
135
136 test(function() {
137 var x = document.createElement('x');
138 var y = document.createElement('y');
139 x.before(y);
140 assert_equals(x.previousSibling, null);
141 }, nodeName + '.before() on a child without any parent.');
142
143 test(function() {
144 var parent = document.createElement('div');
145 parent.appendChild(child);
146 var doc2 = document.implementation.createDocument("http://www.w3.org/199 9/xhtml", "html");
147 assert_throws('HierarchyRequestError', () => { child.before(doc2, "foo") });
148 assert_equals(parent.firstChild, child);
149 }, nodeName + '.before() with a Document as an argument should throw.');
150 }
151
152 test_before('Comment');
153 test_before('Element');
154 test_before('Text');
155
156 </script>
157 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698