| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>HTML Templates: ownerDocument of cloned template content is set to templa
te content owner</title> | |
| 5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> | |
| 6 <meta name="author" title="Aleksei Yu. Semenov" href="a.semenov@unipro.ru"> | |
| 7 <meta name="assert" content="ownerDocument of cloned template content is set to
template content owner"> | |
| 8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#nod
e-clone-additions"> | |
| 9 <script src="../../../../../../../resources/testharness.js"></script> | |
| 10 <script src="../../../../../../../resources/testharnessreport.js"></script> | |
| 11 <script src='/html/resources/common.js'></script> | |
| 12 <link rel="stylesheet" href="../../../../../../../resources/testharness.css"> | |
| 13 </head> | |
| 14 <body> | |
| 15 <div id="log"></div> | |
| 16 <script type="text/javascript"> | |
| 17 | |
| 18 function checkOwnerDocument(node, doc) { | |
| 19 if ((node !== null) && (node !== undefined)) { | |
| 20 assert_equals(node.ownerDocument, doc, | |
| 21 'Wrong ownerDocument of the template copy\'s node ' + node.nodeN
ame); | |
| 22 for (var i = 0; i < node.childNodes.length; i++) { | |
| 23 if (node.childNodes[i].nodeType === Node.ELEMENT_NODE) { | |
| 24 checkOwnerDocument(node.childNodes[i], doc); | |
| 25 if (node.childNodes[i].nodeName === 'TEMPLATE') { | |
| 26 checkOwnerDocument(node.childNodes[i].content, doc); | |
| 27 } | |
| 28 } | |
| 29 } | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 | |
| 34 test(function () { | |
| 35 var doc = newHTMLDocument(); | |
| 36 doc.body.innerHTML = '<template id="tmpl1">' + | |
| 37 '<div id="div1">This is div inside template</div>' + | |
| 38 '<div id="div2">This is another div inside template</div>' + | |
| 39 '</template>'; | |
| 40 | |
| 41 var template = doc.querySelector('#tmpl1'); | |
| 42 var copy = template.cloneNode(true); | |
| 43 | |
| 44 assert_equals(copy.content.childNodes.length, 2, | |
| 45 'Wrong number of template content\'s copy child nodes'); | |
| 46 checkOwnerDocument(copy.content, template.content.ownerDocument); | |
| 47 | |
| 48 }, 'ownerDocument of cloned template content is set to template content owner. ' | |
| 49 + 'Test cloning with children'); | |
| 50 | |
| 51 | |
| 52 | |
| 53 test(function () { | |
| 54 var doc = newHTMLDocument(); | |
| 55 doc.body.innerHTML = '<template id="tmpl1">' + | |
| 56 '<div id="div1">This is div inside template</div>' + | |
| 57 '<div id="div2">This is another div inside template</div>' + | |
| 58 '</template>'; | |
| 59 | |
| 60 var template = doc.querySelector('#tmpl1'); | |
| 61 var copy = template.cloneNode(false); | |
| 62 | |
| 63 assert_equals(copy.content.childNodes.length, 0, | |
| 64 'Wrong number of template content\'s copy child nodes'); | |
| 65 checkOwnerDocument(copy.content, template.content.ownerDocument); | |
| 66 | |
| 67 }, 'ownerDocument of cloned template content is set to template content owner. ' | |
| 68 + 'Test cloning without children'); | |
| 69 | |
| 70 | |
| 71 | |
| 72 test(function () { | |
| 73 var doc = newHTMLDocument(); | |
| 74 doc.body.innerHTML = '<template id="tmpl1">' + | |
| 75 '<div id="div1">This is div inside template</div>' + | |
| 76 '<div id="div2">This is another div inside template</div>' + | |
| 77 '</template>'; | |
| 78 | |
| 79 var template = doc.querySelector('#tmpl1'); | |
| 80 var copy = template.cloneNode(); | |
| 81 | |
| 82 assert_equals(copy.content.childNodes.length, 0, | |
| 83 'Wrong number of template content\'s copy child nodes'); | |
| 84 checkOwnerDocument(copy.content, template.content.ownerDocument); | |
| 85 | |
| 86 }, 'ownerDocument of cloned template content is set to template content owner. ' | |
| 87 + 'Test cloneNode() with no arguments (false by default)'); | |
| 88 | |
| 89 | |
| 90 | |
| 91 test(function () { | |
| 92 var doc = newHTMLDocument(); | |
| 93 doc.body.innerHTML = '<template id="tmpl1">' + | |
| 94 '<div id="div1">This is div inside template</div>' + | |
| 95 '<div id="div2">This is another div inside template</div>' + | |
| 96 '<template id="tmpl2">' + | |
| 97 '<div id="div3">This is div inside nested template</div>' + | |
| 98 '<div id="div4">This is another div inside nested template</div>' + | |
| 99 '</template>' + | |
| 100 '</template>'; | |
| 101 | |
| 102 var template = doc.querySelector('#tmpl1'); | |
| 103 var copy = template.cloneNode(true); | |
| 104 | |
| 105 assert_equals(copy.content.childNodes.length, 3, | |
| 106 'Wrong number of template content\'s copy child nodes'); | |
| 107 checkOwnerDocument(copy.content, template.content.ownerDocument); | |
| 108 | |
| 109 }, 'ownerDocument of cloned template content is set to template content owner. ' | |
| 110 + 'Test cloning nested template'); | |
| 111 | |
| 112 | |
| 113 | |
| 114 testInIFrame('../resources/template-contents.html', function(context) { | |
| 115 var doc = context.iframes[0].contentDocument; | |
| 116 | |
| 117 var template = doc.body.querySelector('template'); | |
| 118 var copy = template.cloneNode(true); | |
| 119 | |
| 120 checkOwnerDocument(copy.content, template.content.ownerDocument); | |
| 121 | |
| 122 }, 'ownerDocument of cloned template content is set to template content owner. ' | |
| 123 + 'Test loading HTML document from file'); | |
| 124 | |
| 125 </script> | |
| 126 </body> | |
| 127 </html> | |
| OLD | NEW |