4 <title>HTML Templates: ownerDocument of cloned template content is set to template 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/#node-clone-additions">
9 <script src="../../../../resources/testharness.js"></script>
10 <script src="../../../../resources/testharnessreport.js"></script>
11 <script src='../testcommon.js'></script>
12 <link rel="stylesheet" href="../../../../resources/testharness.css">
16 <script type="text/javascript">
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.nodeName);
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);
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>' +
41 var template = doc.querySelector('#tmpl1');
42 var copy = template.cloneNode(true);
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);
48 }, 'ownerDocument of cloned template content is set to template content owner. '
49 + 'Test cloning with children');
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>' +
60 var template = doc.querySelector('#tmpl1');
61 var copy = template.cloneNode(false);
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);
67 }, 'ownerDocument of cloned template content is set to template content owner. '
68 + 'Test cloning without children');
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>' +
79 var template = doc.querySelector('#tmpl1');
80 var copy = template.cloneNode();
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);
86 }, 'ownerDocument of cloned template content is set to template content owner. '
87 + 'Test cloneNode() with no arguments (false by default)');
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>' +
102 var template = doc.querySelector('#tmpl1');
103 var copy = template.cloneNode(true);
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);
109 }, 'ownerDocument of cloned template content is set to template content owner. '
110 + 'Test cloning nested template');
114 testInIFrame('../resources/template-contents.html', function(context) {
115 var doc = context.iframes[0].contentDocument;
117 var template = doc.body.querySelector('template');
118 var copy = template.cloneNode(true);
120 checkOwnerDocument(copy.content, template.content.ownerDocument);
122 }, 'ownerDocument of cloned template content is set to template content owner. '
123 + 'Test loading HTML document from file');