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

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

Issue 1934123002: Implement DOM methods: prepend, append, after, before and replaceWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync test expectations Created 4 years, 7 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <meta charset=utf-8> 2 <script src="../../../resources/testharness.js"></script>
3 <title>ParentNode.prepend</title> 3 <script src="../../../resources/testharnessreport.js"></script>
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-parentnode-prepend">
5 <script src="../../../../resources/testharness.js"></script>
6 <script src="../../../../resources/testharnessreport.js"></script>
7 <script> 4 <script>
8 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() unscopeable');
19
9 function test_prepend(node, nodeName) { 20 function test_prepend(node, nodeName) {
10 21
11 test(function() { 22 test(function() {
12 var parent = node.cloneNode(); 23 var parent = node.cloneNode();
13 parent.prepend(); 24 parent.prepend();
14 assert_array_equals(parent.childNodes, []); 25 assert_array_equals(parent.childNodes, []);
15 }, nodeName + '.prepend() without any argument, on a parent having no child. '); 26 }, nodeName + '.prepend() without any argument, on a parent having no child. ');
16 27
17 test(function() { 28 test(function() {
18 var parent = node.cloneNode(); 29 var parent = node.cloneNode();
19 parent.prepend(null); 30 parent.prepend(null);
20 assert_equals(parent.childNodes[0].textContent, 'null'); 31 assert_equals(parent.childNodes[0].textContent, 'null');
21 }, nodeName + '.prepend() with null as an argument, on a parent having no ch ild.'); 32 }, nodeName + '.prepend() with null as an argument, on a parent having no ch ild.');
22 33
23 test(function() { 34 test(function() {
24 var parent = node.cloneNode(); 35 » var parent = node.cloneNode();
25 parent.prepend(undefined); 36 » parent.prepend(undefined);
26 assert_equals(parent.childNodes[0].textContent, 'undefined'); 37 » assert_equals(parent.childNodes[0].textContent, 'undefined');
27 }, nodeName + '.prepend() with undefined as an argument, on a parent having no child.'); 38 }, nodeName + '.prepend() with undefined as an argument, on a parent having no child.');
28 39
29 test(function() { 40 test(function() {
30 var parent = node.cloneNode(); 41 var parent = node.cloneNode();
31 parent.prepend('text'); 42 parent.prepend('text');
32 assert_equals(parent.childNodes[0].textContent, 'text'); 43 assert_equals(parent.childNodes[0].textContent, 'text');
33 }, nodeName + '.prepend() with only text as an argument, on a parent having no child.'); 44 }, nodeName + '.prepend() with only text as an argument, on a parent having no child.');
34 45
35 test(function() { 46 test(function() {
36 var parent = node.cloneNode(); 47 var parent = node.cloneNode();
37 var x = document.createElement('x'); 48 var x = document.createElement('x');
38 parent.prepend(x); 49 parent.prepend(x);
39 assert_array_equals(parent.childNodes, [x]); 50 assert_array_equals(parent.childNodes, [x]);
40 }, nodeName + '.prepend() with only one element as an argument, on a parent having no child.'); 51 }, nodeName + '.prepend() with only one element as an argument, on a parent having no child.');
41 52
42 test(function() { 53 test(function() {
43 var parent = node.cloneNode(); 54 var parent = node.cloneNode();
44 var child = document.createElement('test'); 55 var child = document.createElement('test');
45 parent.appendChild(child); 56 parent.appendChild(child);
46 parent.prepend(null); 57 parent.prepend(null);
47 assert_equals(parent.childNodes[0].textContent, 'null'); 58 assert_equals(parent.childNodes[0].textContent, 'null');
48 assert_equals(parent.childNodes[1], child); 59 assert_equals(parent.childNodes[1], child);
49 }, nodeName + '.prepend() with null as an argument, on a parent having a chi ld.'); 60 }, nodeName + '.prepend() with null as an argument, on a parent having a chi ld.');
50 61
51 test(function() { 62 test(function() {
52 var parent = node.cloneNode(); 63 var parent = node.cloneNode();
53 var x = document.createElement('x'); 64 var x = document.createElement('x');
54 var child = document.createElement('test'); 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');
55 parent.appendChild(child); 76 parent.appendChild(child);
56 parent.prepend(x, 'text'); 77 parent.prepend(x, 'text');
57 assert_equals(parent.childNodes[0], x); 78 assert_equals(parent.childNodes[0], x);
58 assert_equals(parent.childNodes[1].textContent, 'text'); 79 assert_equals(parent.childNodes[1].textContent, 'text');
59 assert_equals(parent.childNodes[2], child); 80 assert_equals(parent.childNodes[2], child);
60 }, nodeName + '.prepend() with one element and text as argument, on a parent having a child.'); 81 }, nodeName + '.prepend() with one element and text as argument, on a parent having a child.');
61 } 82 }
62 83
63 test_prepend(document.createElement('div'), 'Element'); 84 test_prepend(document.createElement('div'), 'Element');
64 test_prepend(document.createDocumentFragment(), 'DocumentFrgment'); 85 test_prepend(document.createDocumentFragment(), 'DocumentFrgment');
65 </script> 86 </script>
66 </html> 87 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698