Auto merge of #7531 - nox:template, r=Ms2ger

Implement <template>

All tests using iframes can't currently pass, same for innerHTML-related tests with <template> elements. The latter contradicts the spec, see the links below.

Apart from this, they work, AFAICT.

https://github.com/servo/html5ever/issues/164
https://www.w3.org/Bugs/Public/show_bug.cgi?id=27314

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7531)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-08 02:29:00 -06:00
commit 5a0be12e43
28 changed files with 268 additions and 57 deletions

View file

@ -6333,9 +6333,6 @@
[HTMLTemplateElement interface: existence and properties of interface object]
expected: FAIL
[HTMLTemplateElement interface: attribute content]
expected: FAIL
[HTMLCanvasElement interface: existence and properties of interface object]
expected: FAIL

View file

@ -267,3 +267,6 @@
[<picture><svg><!--<font face> tag breaks out of svg--><font face=""></font><source srcset="data:,b"></source></svg><img src="data:,a" data-expect="data:,b"></picture>]
expected: FAIL
[<picture><svg><!--<font face> tag breaks out of svg--></svg><font face=""></font><source srcset="data:,b"><img src="data:,a" data-expect="data:,b"></picture>]
expected: FAIL

View file

@ -0,0 +1,5 @@
[templates-copy-document-owner.html]
type: testharness
[ownerDocument of cloned template content is set to template content owner. Test loading HTML document from file]
expected: FAIL

View file

@ -0,0 +1,8 @@
[template-contents-owner-document-type.html]
type: testharness
[The template contents owner document type is HTML document (case when document has browsing context and the template is created by HTML parser)]
expected: FAIL
[The template contents owner document type is HTML document (case when document has browsing context and the template is created by createElement())]
expected: FAIL

View file

@ -0,0 +1,11 @@
[template-contents-owner-test-002.html]
type: testharness
[The template contents owner document must be different from template owner document, which has browsing context. Template element is created by createElement()]
expected: FAIL
[The template contents owner document must be different from template owner document, which has browsing context. Template element is created via innerHTML]
expected: FAIL
[The template contents owner document must be different from template owner document, which has browsing context. Template element is created by HTML parser]
expected: FAIL

View file

@ -0,0 +1,14 @@
[template-contents.html]
type: testharness
[The template contents must be a DocumentFragment (the empty template tag inside HTML file loaded in iframe)]
expected: FAIL
[The template contents must be a DocumentFragment (non empty template tag inside HTML file loaded in iframe)]
expected: FAIL
[The template contents must be a DocumentFragment (the template tag with some text inside HTML file loaded in iframe)]
expected: FAIL
[The template contents must be a DocumentFragment (the template tag with nested template tag inside HTML file loaded in iframe)]
expected: FAIL

View file

@ -0,0 +1,5 @@
[innerhtml.html]
type: testharness
[innerHTML of template element replaces all referenced by the content attribute. Test loading of HTML document from a file]
expected: FAIL

View file

@ -0,0 +1,8 @@
[content-attribute.html]
type: testharness
[Content attribute of template element is read-only. Text value of content attribute of template tag should be ignored, when loading document from a file]
expected: FAIL
[Content attribute of template element is read-only. Test content attribute of a document loaded from a file]
expected: FAIL

View file

@ -0,0 +1,11 @@
[node-document-changes.html]
type: testharness
[Changing of template element's node document. Test document loaded from a file]
expected: FAIL
[Changing of template element's node document. Adobt template element into a document that has a browsing context]
expected: FAIL
[Changing of template element's node document. Test the case when both old and new owner documents of template element have browsing context]
expected: FAIL

View file

@ -0,0 +1,8 @@
[template-as-a-descendant.html]
type: testharness
[Template element as a descendant of the FRAMESET element. Template element is created by innerHTML]
expected: FAIL
[Template element as an indirect descendant of the FRAMESET element. Template element is created by innerHTML]
expected: FAIL

View file

@ -0,0 +1,5 @@
[template-content-node-document.html]
type: testharness
[Node document of the template content attribute must be template contents owner. Load HTML file with multiple template elements]
expected: FAIL

View file

@ -0,0 +1,5 @@
[template-descendant-body.html]
type: testharness
[Template element as a descendant of the body element. Test loading from a file]
expected: FAIL

View file

@ -0,0 +1,11 @@
[template-descendant-frameset.html]
type: testharness
[Template element as a descendant of the frameset element. Test loading from a file]
expected: FAIL
[Template element as a descendant of the frameset element. Test template element is assigned to frameset's innerHTML)]
expected: FAIL
[Template element as a descendant of the frameset element. Test template element appended to frameset by appendChild()]
expected: FAIL

View file

@ -0,0 +1,5 @@
[template-descendant-head.html]
type: testharness
[Template element as a descendant of the head element. Test loading from a file]
expected: FAIL

View file

@ -17,9 +17,12 @@
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
var content_owner = template.content.ownerDocument;
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a HTML document');
assert_class_string(content_owner, 'Document',
'Template content owner should be a document');
assert_equals(content_owner.createElement('DIV').localName, 'div',
'Template content owner should be an HTML document');
}, 'The template contents owner document type is HTML document ' +
'(case when document has browsing context and the template ' +
@ -29,13 +32,16 @@ testInIFrame('../resources/template-contents.html', function(context) {
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.createElement('template');
var div = doc.createElement('div');
var content_owner = template.content.ownerDocument;
var div = doc.createElement('DIV');
template.appendChild(div);
doc.body.appendChild(template);
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a HTML document');
assert_class_string(content_owner, 'Document',
'Template content owner should be a document');
assert_equals(div.localName, 'div',
'Template content owner should be an HTML document');
}, 'The template contents owner document type is HTML document ' +
'(case when document has browsing context and the template ' +
@ -45,13 +51,16 @@ testInIFrame('../resources/template-contents.html', function(context) {
test(function() {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var div = doc.createElement('div');
var content_owner = template.content.ownerDocument;
var div = doc.createElement('DIV');
template.appendChild(div);
doc.body.appendChild(template);
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a HTML document');
assert_class_string(content_owner, 'Document',
'Template content owner should be a document');
assert_equals(div.localName, 'div',
'Template content owner should be an HTML document');
}, 'The template contents owner document type is HTML document ' +
'(case when document has no browsing context and the template is created ' +
@ -61,9 +70,12 @@ test(function() {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template><div>Hello!</div></template>';
var template = doc.querySelector('template');
var content_owner = template.content.ownerDocument;
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a HTML document');
assert_class_string(content_owner, 'Document',
'Template content owner should be a document');
assert_equals(content_owner.createElement('DIV').localName, 'div',
'Template content owner should be an HTML document');
}, 'The template contents owner document type is HTML document ' +
'(case when document has no browsing context and the template is created via innerHTML)');