tor-browser

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

template-clone-children.html (3206B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>HTML Templates: Clone template node: All the children of template content are copied if 'copy children flag' set to true</title>
      5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
      6 <meta name="assert" content="Clone template node: all the children of template content are copied if 'copy children flag' set to true">
      7 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#node-clone-additions">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src='/html/resources/common.js'></script>
     11 </head>
     12 <body>
     13 <div id="log"></div>
     14 <script type="text/javascript">
     15 
     16 test(function () {
     17    var doc = newHTMLDocument();
     18    doc.body.innerHTML = '<template id="tmpl1">' +
     19        '<div id="div1">This is div inside template</div>' +
     20        '<div id="div2">This is another div inside template</div>' +
     21        '</template>';
     22 
     23    var template = doc.querySelector('#tmpl1');
     24    var copy = template.cloneNode(true);
     25 
     26    assert_not_equals(copy.content, undefined, 'Template clone content attribute should not be undefined');
     27    assert_not_equals(copy.content, null, 'Template clone content attribute should not be null');
     28 
     29    assert_equals(copy.content.childNodes.length, 2,
     30            'Wrong number of template content\'s copy child nodes');
     31    assert_not_equals(copy.content.querySelector('#div1'), null,
     32            'Template child node should be copied');
     33    assert_not_equals(copy.content.querySelector('#div2'), null,
     34            'Template child node should be copied');
     35 
     36 }, 'Clone template node. Test call to cloneNode(true)');
     37 
     38 
     39 
     40 test(function () {
     41    var doc = newHTMLDocument();
     42    doc.body.innerHTML = '<template id="tmpl1">' +
     43        '<div id="div1">This is div inside template</div>' +
     44        '<div id="div2">This is another div inside template</div>' +
     45        '</template>';
     46 
     47    var template = doc.querySelector('#tmpl1');
     48    var copy = template.cloneNode();
     49 
     50    assert_not_equals(copy.content, undefined, 'Template clone content attribute should not be undefined');
     51    assert_not_equals(copy.content, null, 'Template clone content attribute should not be null');
     52 
     53    assert_equals(copy.content.childNodes.length, 0,
     54            'Wrong number of template content\'s copy child nodes');
     55 
     56 }, 'Clone template node. Test call to cloneNode() with the default parameter '
     57    + '(false by default)');
     58 
     59 
     60 
     61 test(function () {
     62    var doc = newHTMLDocument();
     63    doc.body.innerHTML = '<template id="tmpl1">' +
     64        '<div id="div1">This is div inside template</div>' +
     65        '<div id="div2">This is another div inside template</div>' +
     66        '</template>';
     67 
     68    var template = doc.querySelector('#tmpl1');
     69    var copy = template.cloneNode(false);
     70 
     71    assert_not_equals(copy.content, undefined, 'Template clone content attribute is undefined');
     72    assert_not_equals(copy.content, null, 'Template clone content attribute is null');
     73 
     74    assert_equals(copy.content.childNodes.length, 0,
     75            'Wrong number of template content\'s copy child nodes');
     76 
     77 }, 'Clone template node. Test call to cloneNode(false)');
     78 
     79 
     80 </script>
     81 </body>
     82 </html>