Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / w3c / web-platform-tests / html-templates / template-element / node-document-changes.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>HTML Templates: When node's document changes its owner document should be changed</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="When a template element's node document changes, the template element's content DocumentFragment must be adopted into the new node document's template contents owner document">
8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element">
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">
13 </head>
14 <body>
15 <div id="log"></div>
16 <script type="text/javascript">
17
18
19 test(function() {
20     var doc1 = newHTMLDocument();
21     var template = doc1.createElement('template');
22
23     assert_equals(template.ownerDocument, doc1, 'Wrong template node owner document');
24     assert_equals(template.content.ownerDocument, doc1,
25             'Wrong template content owner document');
26
27     var doc2 = newHTMLDocument();
28     var template2 = doc2.createElement('template');
29     doc2.body.appendChild(template);
30
31     assert_equals(template.ownerDocument, template2.ownerDocument,
32             'Template node owner document should be changed');
33     assert_equals(template.content.ownerDocument, template2.content.ownerDocument,
34             'Template content owner document should be changed');
35
36 }, 'Changing of template element\'s node document. ' +
37     'Test that ownerDocument of an empty template and its content changes');
38
39
40 test(function() {
41     var doc1 = newHTMLDocument();
42     doc1.body.innerHTML = '<template id="tmpl"><div>Div content</div> And some more text</template>';
43
44     var template = doc1.querySelector('#tmpl');
45
46     assert_equals(template.ownerDocument, doc1,
47             'Wrong template node owner document');
48     assert_equals(template.content.ownerDocument, doc1,
49             'Wrong template content owner document');
50
51     var doc2 = newHTMLDocument();
52     var template2 = doc2.createElement('template');
53     doc2.body.appendChild(template);
54
55     assert_equals(template.ownerDocument, template2.ownerDocument,
56             'Template node owner document should be changed');
57     assert_equals(template.content.ownerDocument, template2.content.ownerDocument,
58             'Template content owner document should be changed');
59
60     assert_equals(template.content.querySelector('div').ownerDocument,
61             template2.content.ownerDocument,
62             'Template content descendants owner document should be changed');
63
64 }, 'Changing of template element\'s node document. ' +
65     'Test that ownerDocument of a not empty template and its content changes');
66
67
68 test(function() {
69     var doc1 = newHTMLDocument();
70     doc1.body.innerHTML = ''
71             + '<template id="tmpl"><div>Div content</div> And some more text'
72             + '<template id="tmpl2"><div>Template content</div></template>'
73             + '</template>';
74
75     var template = doc1.querySelector('#tmpl');
76
77     assert_equals(template.ownerDocument, doc1, 'Wrong template node owner document');
78     assert_equals(template.content.ownerDocument, doc1,
79             'Wrong template content owner document');
80
81     var nestedTemplate = template.content.querySelector('#tmpl2');
82
83     assert_equals(nestedTemplate.ownerDocument, doc1,
84             'Wrong nested template node owner document');
85     assert_equals(nestedTemplate.content.ownerDocument, doc1,
86             'Wrong nested template content owner document');
87
88     var doc2 = newHTMLDocument();
89     var template2 = doc2.createElement('template');
90     doc2.body.appendChild(template);
91
92     assert_equals(template.ownerDocument, template2.ownerDocument,
93             'Template node owner document should be changed');
94     assert_equals(template.content.ownerDocument, template2.content.ownerDocument,
95             'Template content owner document should be changed');
96     assert_equals(template.content.querySelector('div').ownerDocument,
97             template2.content.ownerDocument,
98             'Template content descendants owner document should be changed');
99
100     assert_equals(nestedTemplate.ownerDocument,
101             template2.content.ownerDocument,
102             'Nested template node owner document should be changed');
103     assert_equals(nestedTemplate.content.ownerDocument,
104             template2.content.ownerDocument,
105             'Nested template content owner document should be changed');
106     assert_equals(nestedTemplate.content.querySelector('div').ownerDocument,
107             template2.content.ownerDocument,
108             'Owner document of the nested template content descendants should be changed');
109
110 }, 'Changing of template element\'s node document. ' +
111     'Test that ownerDocument of nested template and its content changes');
112
113
114 testInIFrame('../resources/template-contents.html', function(context) {
115     var doc1 = context.iframes[0].contentDocument;
116
117     var template = doc1.body.querySelector('template');
118
119     var doc2 = newHTMLDocument();
120     var template2 = doc2.createElement('template');
121     doc2.body.appendChild(template);
122
123     assert_equals(template.ownerDocument, template2.ownerDocument,
124             'Template node owner document should be changed');
125     assert_equals(template.content.ownerDocument,
126             template2.content.ownerDocument,
127             'Template content owner document should be changed');
128     assert_equals(template.content.querySelector('div').ownerDocument,
129             template2.content.ownerDocument,
130             'Template content descendants owner document should be changed');
131
132 }, 'Changing of template element\'s node document. ' +
133     'Test document loaded from a file');
134
135
136 testInIFrame('../resources/template-contents.html', function(context) {
137     var doc1 = context.iframes[0].contentDocument;
138
139     var doc2 = newHTMLDocument();
140     var template = doc2.createElement('template');
141     var div = doc2.createElement('div');
142     template.content.appendChild(div);
143
144     doc1.body.appendChild(template);
145
146     assert_not_equals(template.ownerDocument, doc2,
147             'Template node owner document should be changed');
148     assert_not_equals(template.content.ownerDocument, doc2,
149             'Template content owner document should be changed');
150     assert_not_equals(div.ownerDocument, doc2,
151             'Template content descendants owner document should be changed');
152
153     assert_equals(template.ownerDocument, doc1,
154             'Template node owner document should be changed');
155     // doc1 has browsing context so it cannot be template.content.ownerDocument
156     assert_not_equals(template.content.ownerDocument, doc1,
157             'Template content owner document should be a new document');
158     assert_equals(div.ownerDocument, template.content.ownerDocument,
159             'Template content descendants owner document should be ' +
160             'template content document owner');
161
162 }, 'Changing of template element\'s node document. ' +
163     'Adobt template element into a document that has a browsing context');
164
165
166 testInIFrame('../resources/template-contents.html', function(context) {
167     var doc1 = context.iframes[0].contentDocument;
168
169     var template = doc1.querySelector('template');
170     var div = template.content.querySelector('div');
171     var templateContentOwner = template.content.ownerDocument;
172
173     var doc2 = document;
174
175     doc2.body.appendChild(template);
176
177
178     assert_not_equals(template.ownerDocument, doc1,
179             'Template node owner document should be changed');
180     assert_not_equals(template.content.ownerDocument, templateContentOwner,
181             'Template content owner document should be changed');
182     assert_not_equals(div.ownerDocument, templateContentOwner,
183             'Template content descendants owner document should be changed');
184
185     assert_equals(template.ownerDocument, doc2,
186             'Template node owner document should be changed');
187     // doc2 has browsing context, so it cannot be template.content.ownerDocument
188     assert_not_equals(template.content.ownerDocument, doc2,
189             'Template content owner document should be a new document');
190     assert_equals(div.ownerDocument, template.content.ownerDocument,
191             'Template content descendants owner document should be ' +
192             'template content document owner');
193
194 }, 'Changing of template element\'s node document. ' +
195     'Test the case when both old and new owner documents of template element ' +
196     'have browsing context');
197
198 </script>
199 </body>
200 </html>