File: ChildNode-replaceWith.html

package info (click to toggle)
firefox-esr 52.8.1esr-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,983,244 kB
  • sloc: cpp: 4,810,275; ansic: 2,004,548; python: 451,282; java: 241,615; asm: 178,649; xml: 136,302; sh: 82,207; makefile: 22,575; perl: 15,783; objc: 4,389; yacc: 1,816; ada: 1,697; pascal: 1,519; lex: 1,257; cs: 879; exp: 499; php: 436; lisp: 258; awk: 152; sed: 51; ruby: 47; csh: 27
file content (110 lines) | stat: -rw-r--r-- 4,254 bytes parent folder | download | duplicates (35)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<meta charset=utf-8>
<title>ChildNode.replaceWith</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-replaceWith">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

function test_replaceWith(child, nodeName, innerHTML) {

    test(function() {
        var parent = document.createElement('div');
        parent.appendChild(child);
        child.replaceWith();
        assert_equals(parent.innerHTML, '');
    }, nodeName + '.replaceWith() without any argument.');

    test(function() {
        var parent = document.createElement('div');
        parent.appendChild(child);
        child.replaceWith(null);
        assert_equals(parent.innerHTML, 'null');
    }, nodeName + '.replaceWith() with null as an argument.');

    test(function() {
        var parent = document.createElement('div');
        parent.appendChild(child);
        child.replaceWith(undefined);
        assert_equals(parent.innerHTML, 'undefined');
    }, nodeName + '.replaceWith() with undefined as an argument.');

    test(function() {
        var parent = document.createElement('div');
        parent.appendChild(child);
        child.replaceWith('');
        assert_equals(parent.innerHTML, '');
    }, nodeName + '.replaceWith() with empty string as an argument.');

    test(function() {
        var parent = document.createElement('div');
        parent.appendChild(child);
        child.replaceWith('text');
        assert_equals(parent.innerHTML, 'text');
    }, nodeName + '.replaceWith() with only text as an argument.');

    test(function() {
        var parent = document.createElement('div');
        var x = document.createElement('x');
        parent.appendChild(child);
        child.replaceWith(x);
        assert_equals(parent.innerHTML, '<x></x>');
    }, nodeName + '.replaceWith() with only one element as an argument.');

    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.replaceWith(x, y, z);
        assert_equals(parent.innerHTML, '<x></x><y></y><z></z>');
    }, nodeName + '.replaceWith() with sibling of child as arguments.');

    test(function() {
        var parent = document.createElement('div');
        var x = document.createElement('x');
        parent.appendChild(child);
        parent.appendChild(x);
        parent.appendChild(document.createTextNode('1'));
        child.replaceWith(x, '2');
        assert_equals(parent.innerHTML, '<x></x>21');
    }, nodeName + '.replaceWith() with one sibling of child and text as arguments.');

    test(function() {
        var parent = document.createElement('div');
        var x = document.createElement('x');
        parent.appendChild(child);
        parent.appendChild(x);
        parent.appendChild(document.createTextNode('text'));
        child.replaceWith(x, child);
        assert_equals(parent.innerHTML, '<x></x>' + innerHTML + 'text');
    }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.');

    test(function() {
        var parent = document.createElement('div');
        var x = document.createElement('x');
        parent.appendChild(child);
        child.replaceWith(x, 'text');
        assert_equals(parent.innerHTML, '<x></x>text');
    }, nodeName + '.replaceWith() with one element and text as arguments.');

    test(function() {
        var parent = document.createElement('div');
        var x = document.createElement('x');
        var y = document.createElement('y');
        parent.appendChild(x);
        parent.appendChild(y);
        child.replaceWith(x, y);
        assert_equals(parent.innerHTML, '<x></x><y></y>');
    }, nodeName + '.replaceWith() on a parentless child with two elements as arguments.');
}

test_replaceWith(document.createComment('test'), 'Comment', '<!--test-->');
test_replaceWith(document.createElement('test'), 'Element', '<test></test>');
test_replaceWith(document.createTextNode('test'), 'Text', 'test');

</script>
</html>