tor-browser

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

html-collection.html (2720B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta name='author' title='Google' href='http://www.google.com'>
      5 <meta name='assert' content='document attributes that returns HTMLCollection should not expose nodes in shadow tree.'>
      6 <link rel='help' href='https://w3c.github.io/webcomponents/spec/shadow/'>
      7 <script src='/resources/testharness.js'></script>
      8 <script src='/resources/testharnessreport.js'></script>
      9 </head>
     10 <body>
     11 <template id='collection-template'>
     12  <img>
     13  <embed></embed>
     14  <applet></applet>
     15  <object type='application/x-java-applet'></object>
     16  <a href='http://example.com'></a>
     17  <a name='test'></a>
     18  <form name='test'></form>
     19  <script></script>
     20 </template>
     21 <div id='doc'></div>
     22 <div id='host-open'></div>
     23 <div id='host-closed'></div>
     24 </body>
     25 <script>
     26 'use strict';
     27 
     28 function fillTemplate(root, prefix) {
     29    var tmpl = document.getElementById('collection-template');
     30    root.appendChild(document.importNode(tmpl.content, true));
     31    for (var i = 0; i < root.childNodes.length; ++i) {
     32        var el = root.childNodes[i];
     33        if (el.nodeType != 1)
     34            continue;
     35        el.id = prefix + el.tagName.toLowerCase();
     36    }
     37 }
     38 
     39 // Construct subtree with 'doc-*' ids.
     40 var doc = document.getElementById('doc');
     41 fillTemplate(doc, 'doc-');
     42 
     43 // Construct shadow subtree with 'shadow-*' ids.
     44 var host = document.getElementById('host-open');
     45 var shadow = host.attachShadow({mode: 'open'});
     46 fillTemplate(shadow, 'shadow-open-');
     47 
     48 host = document.getElementById('host-closed');
     49 shadow = host.attachShadow({mode: 'closed'});
     50 fillTemplate(shadow, 'shadow-closed-');
     51 
     52 function testCollection(collection) {
     53    var elements = document[collection];
     54    assert_greater_than(elements.length, 0, 'document.' + collection + ' should have at least 1 element.');
     55    for (var i = 0; i < elements.length; ++i) {
     56        if (elements[i].id) {
     57            assert_equals(elements[i].id.indexOf('shadow-'), -1, 'document.' + collection + ' should not contain elements in shadow tree.');
     58        }
     59    }
     60 }
     61 
     62 var testParams = [
     63    ['document.scripts should not contain shadow nodes', 'scripts'],
     64    ['document.all should not contain shadow nodes', 'all'],
     65    ['document.forms should not contain shadow nodes', 'forms'],
     66    ['document.images should not contain shadow nodes', 'images'],
     67    ['document.links should not contain shadow nodes', 'links'],
     68    ['document.anchors should not contain shadow nodes', 'anchors'],
     69    ['document.embeds should not contain shadow nodes', 'embeds'],
     70    ['document.plugins should not contain shadow nodes', 'plugins']];
     71 
     72 generate_tests(testCollection, testParams);
     73 
     74 test(() => {
     75  assert_equals(document.applets.length, 0);
     76 }, 'document.applets should not contain any nodes');
     77 
     78 </script>
     79 </html>