summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/definitions/template-contents.html
blob: 4a61dc8d3b851bb2d5b44a06925e56907d8727e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: The template contents is a DocumentFragment</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="The template contents must be a DocumentFragment">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#definitions">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='/html/resources/common.js'></script>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">


test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    doc.body.appendChild(template);

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a DocumentFragment');

    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (empty template)');


test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    template.innerHTML = '<div>This is a div</div><span>This is a span</span>';

    doc.body.appendChild(template);

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a DocumentFragment');

    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (non empty template)');



test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    template.innerHTML = '<div>This is a div</div>';

    doc.body.appendChild(template);

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');

}, 'The template contents must be a DocumentFragment (non empty template '
        + 'containing div which is an Element instance)');


test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    template.innerHTML = 'Some text';

    doc.body.appendChild(template);

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');

    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (not empty template '
        + 'containing text node)');


test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    template.innerHTML = '<template id="t2">Some text</template>';

    doc.body.appendChild(template);

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');
    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

    var nestedTemplate = template.content.querySelector("#t2");
    assert_equals(nestedTemplate.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Nested template content should be a documentFragment');

    assert_class_string(nestedTemplate.content, 'DocumentFragment',
            'Nested template content class should be a DocumentFragment');


}, 'The template contents must be a DocumentFragment (nested template '
        + 'containing a text node)');


testInIFrame('../resources/template-contents-empty.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.querySelector('template');

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');
    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');


}, 'The template contents must be a DocumentFragment (the empty template tag '
        + 'inside HTML file loaded in iframe)');


testInIFrame('../resources/template-contents.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.querySelector('template');

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');
    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (non empty template '
        + 'tag inside HTML file loaded in iframe)');


testInIFrame('../resources/template-contents-text.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.querySelector('template');

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');
    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (the template tag '
        + 'with some text inside HTML file loaded in iframe)');


testInIFrame('../resources/template-contents-nested.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.querySelector('template');

    assert_equals(template.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Template content should be a documentFragment');
    assert_class_string(template.content, 'DocumentFragment',
            'Template content class should be a DocumentFragment');

    var nestedTemplate = template.content.querySelector("template");

    assert_equals(nestedTemplate.content.nodeType, Node.DOCUMENT_FRAGMENT_NODE,
            'Nested template content should be a documentFragment');
    assert_class_string(nestedTemplate.content, 'DocumentFragment',
            'Nested template content class should be a DocumentFragment');

}, 'The template contents must be a DocumentFragment (the template tag '
        + 'with nested template tag inside HTML file loaded in iframe)');
</script>
</body>
</html>