tor-browser

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

ParentNode-prepend.html (2718B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>ParentNode.prepend</title>
      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 src="pre-insertion-validation-hierarchy.js"></script>
      8 <script>
      9 preInsertionValidateHierarchy("prepend");
     10 
     11 function test_prepend(node, nodeName) {
     12    test(function() {
     13        const parent = node.cloneNode();
     14        parent.prepend();
     15        assert_array_equals(parent.childNodes, []);
     16    }, nodeName + '.prepend() without any argument, on a parent having no child.');
     17 
     18    test(function() {
     19        const parent = node.cloneNode();
     20        parent.prepend(null);
     21        assert_equals(parent.childNodes[0].textContent, 'null');
     22    }, nodeName + '.prepend() with null as an argument, on a parent having no child.');
     23 
     24    test(function() {
     25        const parent = node.cloneNode();
     26        parent.prepend(undefined);
     27        assert_equals(parent.childNodes[0].textContent, 'undefined');
     28    }, nodeName + '.prepend() with undefined as an argument, on a parent having no child.');
     29 
     30    test(function() {
     31        const parent = node.cloneNode();
     32        parent.prepend('text');
     33        assert_equals(parent.childNodes[0].textContent, 'text');
     34    }, nodeName + '.prepend() with only text as an argument, on a parent having no child.');
     35 
     36    test(function() {
     37        const parent = node.cloneNode();
     38        const x = document.createElement('x');
     39        parent.prepend(x);
     40        assert_array_equals(parent.childNodes, [x]);
     41    }, nodeName + '.prepend() with only one element as an argument, on a parent having no child.');
     42 
     43    test(function() {
     44        const parent = node.cloneNode();
     45        const child = document.createElement('test');
     46        parent.appendChild(child);
     47        parent.prepend(null);
     48        assert_equals(parent.childNodes[0].textContent, 'null');
     49        assert_equals(parent.childNodes[1], child);
     50    }, nodeName + '.prepend() with null as an argument, on a parent having a child.');
     51 
     52    test(function() {
     53        const parent = node.cloneNode();
     54        const x = document.createElement('x');
     55        const child = document.createElement('test');
     56        parent.appendChild(child);
     57        parent.prepend(x, 'text');
     58        assert_equals(parent.childNodes[0], x);
     59        assert_equals(parent.childNodes[1].textContent, 'text');
     60        assert_equals(parent.childNodes[2], child);
     61    }, nodeName + '.prepend() with one element and text as argument, on a parent having a child.');
     62 }
     63 
     64 test_prepend(document.createElement('div'), 'Element');
     65 test_prepend(document.createDocumentFragment(), 'DocumentFragment');
     66 </script>
     67 </html>