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