tor-browser

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

template-as-a-descendant.html (5567B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>HTML Templates: Template element as a descendant of the body element.</title>
      5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
      6 <meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
      7 <meta name="assert" content="Template element can be a descendant of the body element">
      8 <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-template-element">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <script src='/html/resources/common.js'></script>
     12 </head>
     13 <body>
     14 <div id="log"></div>
     15 <script type="text/javascript">
     16 
     17 function templateIsAChild(element) {
     18    element.innerHTML = '<template>some text</template>';
     19 
     20    assert_not_equals(element.querySelector('template'), null,
     21        'Template element should be a descendant of the ' + element.tagName + ' element');
     22 }
     23 
     24 function templateIsDisallowedAsAChild(element) {
     25    element.innerHTML = '<template>some text</template>';
     26 
     27    assert_equals(element.querySelector('template'), null,
     28        'Template element should not be allowed as a descendant of the ' + element.tagName + ' element');
     29 }
     30 
     31 function templateIsAnIndirectChild(element) {
     32    element.innerHTML = '<div><template>some text</template></div>';
     33 
     34    assert_not_equals(element.querySelector('template'), null,
     35        'Template element should be a descendant of the ' + element.tagName + ' element');
     36 }
     37 
     38 function templateIsDisallowedAsAnIndirectChild(element) {
     39    element.innerHTML = '<div><template>some text</template></div>';
     40 
     41    assert_equals(element.querySelector('template'), null,
     42        'Template element should not be allowed as indirect descendant of the ' + element.tagName + ' element');
     43 }
     44 
     45 function templateIsAnAppendedChild(doc, element) {
     46    var template = doc.createElement('template');
     47 
     48    element.appendChild(template);
     49 
     50    assert_not_equals(element.querySelector('template'), null,
     51        'Template element should be a descendant of the ' + element.tagName + ' element');
     52 }
     53 
     54 function templateIsAnAppendedIndirectChild(doc, element) {
     55    var template = doc.createElement('template');
     56    var div = doc.createElement('div');
     57    div.appendChild(template);
     58 
     59    element.appendChild(div);
     60 
     61    assert_not_equals(element.querySelector('template'), null,
     62        'Template element should be a descendant of the ' + element.tagName + ' element');
     63 }
     64 
     65 var doc = newHTMLDocument();
     66 var frameset = doc.createElement('frameset');
     67 
     68 var parameters = [['Template element as a descendant of the BODY element. ' +
     69                   'Template element is created by innerHTML',
     70                   doc.body],
     71                  ['Template element as a descendant of the HEAD element. ' +
     72                   'Template element is created by innerHTML',
     73                   doc.head],
     74                   ];
     75 // Template element as a descendant of the HEAD and BODY elements
     76 generate_tests(templateIsAChild, parameters);
     77 
     78 parameters = [['Template element as a descendant of the FRAMESET element. ' +
     79               'Template element is created by innerHTML',
     80               frameset],
     81               ];
     82 // Template element should be disallowed as a descendant of the FRAMESET elements
     83 generate_tests(templateIsDisallowedAsAChild, parameters);
     84 
     85 
     86 parameters = [['Template element as an indirect descendant of the BODY element. ' +
     87               'Template element is created by innerHTML',
     88               doc.body],
     89              ['Template element as an indirect descendant of the HEAD element. ' +
     90               'Template element is created by innerHTML',
     91               doc.head],
     92               ];
     93 // Template element as an indirect descendant of the HEAD, BODY and FRAMESET elements
     94 generate_tests(templateIsAnIndirectChild, parameters);
     95 
     96 parameters = [['Template element as an indirect descendant of the FRAMESET element. ' +
     97               'Template element is created by innerHTML',
     98               frameset],
     99               ];
    100 // Template element should be disallowed as an indirect descendant of the FRAMESET elements
    101 generate_tests(templateIsDisallowedAsAnIndirectChild, parameters);
    102 
    103 
    104 
    105 parameters = [['Template element as a descendant of the BODY element. ' +
    106               'Template element is appended by appendChild()',
    107               doc, doc.body],
    108              ['Template element as a descendant of the HEAD element. ' +
    109               'Template element is appended by appendChild()',
    110               doc, doc.head],
    111               ['Template element as a descendant of the FRAMESET element. ' +
    112                'Template element is  appended by appendChild()',
    113                doc, frameset]
    114               ];
    115 // Template element as a descendant of the HEAD, BODY and FRAMESET elements
    116 generate_tests(templateIsAnAppendedChild, parameters);
    117 
    118 
    119 
    120 parameters = [['Template element as an indirect descendant of the BODY element. ' +
    121               'Template element is appended by appendChild()',
    122               doc, doc.body],
    123              ['Template element as an indirect descendant of the HEAD element. ' +
    124               'Template element is appended by appendChild()',
    125               doc, doc.head],
    126               ['Template element as an indirect descendant of the FRAMESET element. ' +
    127                'Template element is  appended by appendChild()',
    128                doc, frameset]
    129               ];
    130 // Template element as a descendant of the HEAD, BODY and FRAMESET elements
    131 generate_tests(templateIsAnAppendedIndirectChild, parameters);
    132 
    133 </script>
    134 </body>
    135 </html>