tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ChildNode-before.html (6394B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>ChildNode.before</title>
      4 <link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-before">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 
      9 function test_before(child, nodeName, innerHTML) {
     10 
     11    test(function() {
     12        var parent = document.createElement('div');
     13        parent.appendChild(child);
     14        child.before();
     15        assert_equals(parent.innerHTML, innerHTML);
     16    }, nodeName + '.before() without any argument.');
     17 
     18    test(function() {
     19        var parent = document.createElement('div');
     20        parent.appendChild(child);
     21        child.before(null);
     22        var expected = 'null' + innerHTML;
     23        assert_equals(parent.innerHTML, expected);
     24    }, nodeName + '.before() with null as an argument.');
     25 
     26    test(function() {
     27        var parent = document.createElement('div');
     28        parent.appendChild(child);
     29        child.before(undefined);
     30        var expected = 'undefined' + innerHTML;
     31        assert_equals(parent.innerHTML, expected);
     32    }, nodeName + '.before() with undefined as an argument.');
     33 
     34    test(function() {
     35        var parent = document.createElement('div');
     36        parent.appendChild(child);
     37        child.before('');
     38        assert_equals(parent.firstChild.data, '');
     39    }, nodeName + '.before() with the empty string as an argument.');
     40 
     41    test(function() {
     42        var parent = document.createElement('div');
     43        parent.appendChild(child);
     44        child.before('text');
     45        var expected = 'text' + innerHTML;
     46        assert_equals(parent.innerHTML, expected);
     47    }, nodeName + '.before() with only text as an argument.');
     48 
     49    test(function() {
     50        var parent = document.createElement('div');
     51        var x = document.createElement('x');
     52        parent.appendChild(child);
     53        child.before(x);
     54        var expected = '<x></x>' + innerHTML;
     55        assert_equals(parent.innerHTML, expected);
     56    }, nodeName + '.before() with only one element as an argument.');
     57 
     58    test(function() {
     59        var parent = document.createElement('div');
     60        var x = document.createElement('x');
     61        parent.appendChild(child);
     62        child.before(x, 'text');
     63        var expected = '<x></x>text' + innerHTML;
     64        assert_equals(parent.innerHTML, expected);
     65    }, nodeName + '.before() with one element and text as arguments.');
     66 
     67    test(function() {
     68        var parent = document.createElement('div');
     69        parent.appendChild(child);
     70        child.before('text', child);
     71        var expected = 'text' + innerHTML;
     72        assert_equals(parent.innerHTML, expected);
     73    }, nodeName + '.before() with context object itself as the argument.');
     74 
     75    test(function() {
     76        var parent = document.createElement('div')
     77        var x = document.createElement('x');
     78        parent.appendChild(child);
     79        parent.appendChild(x);
     80        child.before(x, child);
     81        var expected = '<x></x>' + innerHTML;
     82        assert_equals(parent.innerHTML, expected);
     83    }, nodeName + '.before() with context object itself and node as the arguments, switching positions.');
     84 
     85    test(function() {
     86        var parent = document.createElement('div');
     87        var x = document.createElement('x');
     88        var y = document.createElement('y');
     89        var z = document.createElement('z');
     90        parent.appendChild(y);
     91        parent.appendChild(child);
     92        parent.appendChild(x);
     93        child.before(x, y, z);
     94        var expected = '<x></x><y></y><z></z>' + innerHTML;
     95        assert_equals(parent.innerHTML, expected);
     96    }, nodeName + '.before() with all siblings of child as arguments.');
     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(x);
    104        parent.appendChild(y);
    105        parent.appendChild(z);
    106        parent.appendChild(child);
    107        child.before(y, z);
    108        var expected = '<x></x><y></y><z></z>' + innerHTML;
    109        assert_equals(parent.innerHTML, expected);
    110    }, nodeName + '.before() with some siblings of child as arguments; no changes in tree; viable sibling is first child.');
    111 
    112    test(function() {
    113        var parent = document.createElement('div')
    114        var v = document.createElement('v');
    115        var x = document.createElement('x');
    116        var y = document.createElement('y');
    117        var z = document.createElement('z');
    118        parent.appendChild(v);
    119        parent.appendChild(x);
    120        parent.appendChild(y);
    121        parent.appendChild(z);
    122        parent.appendChild(child);
    123        child.before(y, z);
    124        var expected = '<v></v><x></x><y></y><z></z>' + innerHTML;
    125        assert_equals(parent.innerHTML, expected);
    126    }, nodeName + '.before() with some siblings of child as arguments; no changes in tree.');
    127 
    128    test(function() {
    129        var parent = document.createElement('div');
    130        var x = document.createElement('x');
    131        var y = document.createElement('y');
    132        parent.appendChild(x);
    133        parent.appendChild(y);
    134        parent.appendChild(child);
    135        child.before(y, x);
    136        var expected = '<y></y><x></x>' + innerHTML;
    137        assert_equals(parent.innerHTML, expected);
    138    }, nodeName + '.before() when pre-insert behaves like prepend.');
    139 
    140    test(function() {
    141        var parent = document.createElement('div');
    142        var x = document.createElement('x');
    143        parent.appendChild(x);
    144        parent.appendChild(document.createTextNode('1'));
    145        var y = document.createElement('y');
    146        parent.appendChild(y);
    147        parent.appendChild(child);
    148        child.before(x, '2');
    149        var expected = '1<y></y><x></x>2' + innerHTML;
    150        assert_equals(parent.innerHTML, expected);
    151    }, nodeName + '.before() with one sibling of child and text as arguments.');
    152 
    153    test(function() {
    154        var x = document.createElement('x');
    155        var y = document.createElement('y');
    156        x.before(y);
    157        assert_equals(x.previousSibling, null);
    158    }, nodeName + '.before() on a child without any parent.');
    159 }
    160 
    161 test_before(document.createComment('test'), 'Comment', '<!--test-->');
    162 test_before(document.createElement('test'), 'Element', '<test></test>');
    163 test_before(document.createTextNode('test'), 'Text', 'test');
    164 
    165 </script>
    166 </html>