tor-browser

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

ignore-body-token.html (4880B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>HTML Templates: In body insertion mode: parser should ignore BODY token</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="http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition">
      8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition">
      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 /*
     18 * According to http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-contents-insertion-mode
     19 * when parser is in "template content" mode and meets <body> tag it should be switched to
     20 * "in body" insertion mode.
     21 * According to http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition
     22 * this token (BODY) should be ignored
     23 */
     24 
     25 
     26 test(function() {
     27    var doc = newHTMLDocument();
     28    var template = doc.createElement('template');
     29 
     30    template.innerHTML = '<body></body>';
     31 
     32    doc.body.appendChild(template);
     33 
     34    assert_equals(template.content.childNodes.length, 0,
     35            'Template cannot contain BODY element');
     36 
     37 }, 'Ignore BODY token. Test empty BODY element assigned to template innerHTML');
     38 
     39 
     40 test(function() {
     41    var doc = newHTMLDocument();
     42    var template = doc.createElement('template');
     43 
     44    template.innerHTML = '<body><div>Some content</div></body>';
     45 
     46    doc.body.appendChild(template);
     47 
     48    assert_equals(template.content.childNodes.length, 1,
     49            'Wrong number of template content children');
     50    assert_equals(template.content.firstChild.nodeName, 'DIV',
     51            'Template should contain children of ignored BODY element');
     52 
     53 }, 'Ignore BODY token. Test not empty BODY element assigned to template innerHTML');
     54 
     55 
     56 test(function() {
     57    var doc = newHTMLDocument();
     58    var template = doc.createElement('template');
     59 
     60    template.innerHTML = '<body><div <div id="div1">Some content</div></body><div id="div2">Some valid content</div>';
     61 
     62    doc.body.appendChild(template);
     63 
     64    assert_equals(template.content.childNodes.length, 2,
     65            'Wrong number of template content children');
     66    assert_not_equals(template.content.querySelector('#div1'), null,
     67            'Template should contain children of the ignored BODY element');
     68    assert_not_equals(template.content.querySelector('#div2'), null,
     69            'Template should contain valid element');
     70 
     71 }, 'Ignore BODY token. '
     72        + 'Test BODY element and some valid element after BODY tag assigned to template innerHTML');
     73 
     74 
     75 test(function() {
     76    var doc = newHTMLDocument();
     77    var template = doc.createElement('template');
     78 
     79    template.innerHTML = '<div id="div1">Some valid content</div><body><div id="div2">Some content</div></body>';
     80 
     81    doc.body.appendChild(template);
     82 
     83    assert_equals(template.content.childNodes.length, 2,
     84            'Template cannot contain BODY element');
     85    assert_not_equals(template.content.querySelector('#div1'), null,
     86            'Template should contain valid element');
     87    assert_not_equals(template.content.querySelector('#div2'), null,
     88            'Template should contain children of the ignored BODY element');
     89 
     90 }, 'Ignore BODY token. '
     91        + 'Test BODY element and some valid element before BODY tag assigned to template innerHTML');
     92 
     93 
     94 test(function() {
     95    var doc = newHTMLDocument();
     96    var template = doc.createElement('template');
     97 
     98    template.innerHTML = '<template id="t2"><body><span>Body!<span></body></template>';
     99 
    100    doc.body.appendChild(template);
    101 
    102    assert_equals(template.content.childNodes.length, 1,
    103            'Template should contain nested template');
    104    assert_not_equals(template.content.querySelector('#t2'), null,
    105            'Template should contain nested element');
    106 
    107    var nestedTemplate = template.content.querySelector('#t2');
    108 
    109    assert_equals(nestedTemplate.content.childNodes.length, 1,
    110            'Template cannot contain BODY element');
    111    assert_equals(nestedTemplate.content.firstChild.nodeName, 'SPAN',
    112            'Template cannot contain BODY element');
    113 
    114 }, 'Ignore BODY token. '
    115    + 'Test template with not empty BODY element inside assigned to another '
    116    + 'template\'s innerHTML');
    117 
    118 
    119 testInIFrame('/html/semantics/scripting-1/the-template-element/resources/template-contents-body.html', function(context) {
    120    var doc = context.iframes[0].contentDocument;
    121 
    122    var template = doc.body.querySelector('template');
    123 
    124    assert_equals(template.content.childNodes.length, 0,
    125            'Template cannot contain BODY element');
    126 
    127 }, 'Ignore BODY token. '
    128    + 'Test loading a HTML file with BODY tag inside template');
    129 
    130 </script>
    131 </body>
    132 </html>