tor-browser

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

ownerdocument-001.html (4478B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Shadow DOM Test: Upper-boundary encapsuration on ownerDocument: basic tests</title>
      5 <link rel="author" title="Aleksei Yu. Semenov" href="mailto:sgrekhov@unipro.ru">
      6 <link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
      7 <link rel="author" title="Mikhail Fursov" href="mailto:mfursov@unipro.ru">
      8 <link rel="author" title="Yuta Kitamura" href="mailto:yutak@google.com">
      9 <link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#upper-boundary-encapsulation">
     10 <meta name="assert" content="Upper-boundary encapsulation: The ownerDocument property of all nodes in shadow tree refers to the document of the shadow host.">
     11 <script src="/resources/testharness.js"></script>
     12 <script src="/resources/testharnessreport.js"></script>
     13 <script src="../../../../html/resources/common.js"></script>
     14 </head>
     15 <body>
     16 <div id="log"></div>
     17 <script>
     18 test(function () {
     19    var doc = document.implementation.createHTMLDocument('Test');
     20    doc.body.innerHTML = '<div>A<div>B</div>C<div><span>D</span></div>E</div>';
     21    var nodeIterator = doc.createNodeIterator(doc.body,
     22                                              NodeFilter.SHOW_ELEMENT, null);
     23    var node;
     24    while (node = nodeIterator.nextNode()) {
     25        var shadowRoot = node.attachShadow({mode: 'open'});
     26        assert_equals(shadowRoot.ownerDocument, doc);
     27    }
     28 }, 'ownerDocument property of a shadow root should be the document of the ' +
     29   'shadow host, regardless of the location of the shadow host.');
     30 
     31 test(function () {
     32    var MAX_DEPTH = 16;
     33    var doc = document.implementation.createHTMLDocument('Test');
     34    var tail = doc.body;
     35    for (var depth = 1; depth <= MAX_DEPTH; ++depth) {
     36        var div = doc.createElement('div');
     37        div.id = 'depth-' + depth;
     38        tail.appendChild(div);
     39        tail = div;
     40    }
     41 
     42    for (var depth = 1; depth <= MAX_DEPTH; ++depth) {
     43        var host = doc.getElementById('depth-' + depth);
     44        var shadowRoot = host.attachShadow({mode: 'open'});
     45        assert_equals(shadowRoot.ownerDocument, doc,
     46                      'ownerDocument mismatch for #depth-' + depth);
     47    }
     48 }, 'ownerDocument property of elements in a shadow tree should match ' +
     49   'the document of the shadow host, regardless of the element\'s location ' +
     50   'in a shadow tree.');
     51 
     52 test(function () {
     53    var doc = document.implementation.createHTMLDocument('Test');
     54    var shadowRoot = doc.body.attachShadow({mode: 'open'});
     55    var div = doc.createElement('div');
     56    shadowRoot.appendChild(div);
     57    assert_equals(div.ownerDocument, doc);
     58 }, 'Elements added to a shadow tree should automatically get a valid ' +
     59   'ownerDocument.');
     60 
     61 test(function () {
     62    var doc1 = document.implementation.createHTMLDocument('Test 1');
     63    var doc2 = document.implementation.createHTMLDocument('Test 2');
     64    var shadowRoot = doc1.body.attachShadow({mode: 'open'});
     65    var div = doc2.createElement('div');
     66    shadowRoot.appendChild(div);
     67    assert_equals(div.ownerDocument, doc1);
     68 }, 'ownerDocument property of an element in a shadow tree should be the ' +
     69   'document of the shadow host, even if the host element is created from ' +
     70   'another document.');
     71 
     72 test(function () {
     73    var doc1 = document.implementation.createHTMLDocument('Test 1');
     74    var doc2 = document.implementation.createHTMLDocument('Test 2');
     75    var shadowRoot = doc1.body.attachShadow({mode: 'open'});
     76    doc2.body.innerHTML =
     77        '<div id="root">A<div>B</div>C<div><span>D</span></div>E</div>';
     78    shadowRoot.appendChild(doc2.getElementById('root'));
     79    var nodeIterator = doc1.createNodeIterator(
     80        shadowRoot.getElementById('root'), 0xFFFFFFFF, null);
     81    var node;
     82    while (node = nodeIterator.nextNode()) {
     83        assert_equals(node.ownerDocument, doc1);
     84    }
     85 }, 'All children nodes of a shadow root get a valid ownerDocument when ' +
     86   'added to a shadow tree.');
     87 
     88 test(function () {
     89    var doc1 = document.implementation.createHTMLDocument('Test 1');
     90    var doc2 = document.implementation.createHTMLDocument('Test 2');
     91    var shadowRoot = doc1.body.attachShadow({mode: 'open'});
     92    doc2.body.innerHTML = '<div id="parent"><div id="child"></div></div>';
     93    shadowRoot.appendChild(doc2.getElementById('child'));
     94    assert_equals(doc2.getElementById('parent').ownerDocument, doc2);
     95 }, 'ownerDocument property of a node should remain the same, even if its ' +
     96   'child is adopted into a shadow tree.');
     97 </script>
     98 </body>
     99 </html>