summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/ChildNode-before.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/dom/nodes/ChildNode-before.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/dom/nodes/ChildNode-before.html')
-rw-r--r--testing/web-platform/tests/dom/nodes/ChildNode-before.html166
1 files changed, 166 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/nodes/ChildNode-before.html b/testing/web-platform/tests/dom/nodes/ChildNode-before.html
new file mode 100644
index 0000000000..8659424465
--- /dev/null
+++ b/testing/web-platform/tests/dom/nodes/ChildNode-before.html
@@ -0,0 +1,166 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>ChildNode.before</title>
+<link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-before">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+function test_before(child, nodeName, innerHTML) {
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before();
+ assert_equals(parent.innerHTML, innerHTML);
+ }, nodeName + '.before() without any argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before(null);
+ var expected = 'null' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with null as an argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before(undefined);
+ var expected = 'undefined' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with undefined as an argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before('');
+ assert_equals(parent.firstChild.data, '');
+ }, nodeName + '.before() with the empty string as an argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before('text');
+ var expected = 'text' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with only text as an argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ var x = document.createElement('x');
+ parent.appendChild(child);
+ child.before(x);
+ var expected = '<x></x>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with only one element as an argument.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ var x = document.createElement('x');
+ parent.appendChild(child);
+ child.before(x, 'text');
+ var expected = '<x></x>text' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with one element and text as arguments.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ parent.appendChild(child);
+ child.before('text', child);
+ var expected = 'text' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with context object itself as the argument.');
+
+ test(function() {
+ var parent = document.createElement('div')
+ var x = document.createElement('x');
+ parent.appendChild(child);
+ parent.appendChild(x);
+ child.before(x, child);
+ var expected = '<x></x>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with context object itself and node as the arguments, switching positions.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ var x = document.createElement('x');
+ var y = document.createElement('y');
+ var z = document.createElement('z');
+ parent.appendChild(y);
+ parent.appendChild(child);
+ parent.appendChild(x);
+ child.before(x, y, z);
+ var expected = '<x></x><y></y><z></z>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with all siblings of child as arguments.');
+
+ test(function() {
+ var parent = document.createElement('div')
+ var x = document.createElement('x');
+ var y = document.createElement('y');
+ var z = document.createElement('z');
+ parent.appendChild(x);
+ parent.appendChild(y);
+ parent.appendChild(z);
+ parent.appendChild(child);
+ child.before(y, z);
+ var expected = '<x></x><y></y><z></z>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with some siblings of child as arguments; no changes in tree; viable sibling is first child.');
+
+ test(function() {
+ var parent = document.createElement('div')
+ var v = document.createElement('v');
+ var x = document.createElement('x');
+ var y = document.createElement('y');
+ var z = document.createElement('z');
+ parent.appendChild(v);
+ parent.appendChild(x);
+ parent.appendChild(y);
+ parent.appendChild(z);
+ parent.appendChild(child);
+ child.before(y, z);
+ var expected = '<v></v><x></x><y></y><z></z>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with some siblings of child as arguments; no changes in tree.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ var x = document.createElement('x');
+ var y = document.createElement('y');
+ parent.appendChild(x);
+ parent.appendChild(y);
+ parent.appendChild(child);
+ child.before(y, x);
+ var expected = '<y></y><x></x>' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() when pre-insert behaves like prepend.');
+
+ test(function() {
+ var parent = document.createElement('div');
+ var x = document.createElement('x');
+ parent.appendChild(x);
+ parent.appendChild(document.createTextNode('1'));
+ var y = document.createElement('y');
+ parent.appendChild(y);
+ parent.appendChild(child);
+ child.before(x, '2');
+ var expected = '1<y></y><x></x>2' + innerHTML;
+ assert_equals(parent.innerHTML, expected);
+ }, nodeName + '.before() with one sibling of child and text as arguments.');
+
+ test(function() {
+ var x = document.createElement('x');
+ var y = document.createElement('y');
+ x.before(y);
+ assert_equals(x.previousSibling, null);
+ }, nodeName + '.before() on a child without any parent.');
+}
+
+test_before(document.createComment('test'), 'Comment', '<!--test-->');
+test_before(document.createElement('test'), 'Element', '<test></test>');
+test_before(document.createTextNode('test'), 'Text', 'test');
+
+</script>
+</html>