diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element')
14 files changed, 790 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/content-attribute.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/content-attribute.html new file mode 100644 index 0000000000..b4c11b841f --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/content-attribute.html @@ -0,0 +1,114 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Content attribute of template element is read-only</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Content attribute of template element is read-only"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test empty template'); + + +test(function() { + var doc = newHTMLDocument(); + var template = doc.createElement('template'); + var el1 = doc.createElement('div'); + var el2 = doc.createElement('span'); + el1.appendChild(el2); + + template.content.appendChild(el1); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test not empty template populated by appendchild()'); + + +test(function() { + var doc = newHTMLDocument(); + doc.body.innerHTML = '<template>Text<div>DIV</div></template>'; + + var template = doc.querySelector('template'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test not empty template populated by innerHTML'); + + +test(function() { + var doc = newHTMLDocument(); + doc.body.innerHTML = '<template id="template1" content="Some text as a content"></template>'; + + var template = doc.querySelector('#template1'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test that custom content attribute named \'content\' doesn\'t ' + + 'make content IDL attribute writable'); + + +test(function() { + var doc = newHTMLDocument(); + doc.body.innerHTML = '<template id="template1" content="<div id=div1>Div content</div>"></template>'; + + var template = doc.querySelector('#template1'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + + assert_equals(template.content.childNodes.length, 0, + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test that custom content attribute named \'content\' doesn\'t ' + + 'affect content IDL attribute'); + + +testInIFrame('../resources/template-contents-attribute.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var template = doc.body.querySelector('template'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, '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'); + + +testInIFrame('../resources/template-contents.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var template = doc.body.querySelector('template'); + + assert_readonly(template, 'content', + 'Content attribute of template element should be read-only'); + +}, 'Content attribute of template element is read-only. ' + + 'Test content attribute of a document loaded from a file'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/node-document-changes.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/node-document-changes.html new file mode 100644 index 0000000000..0c60c10738 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/node-document-changes.html @@ -0,0 +1,192 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: When node's document changes its owner document should be changed</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<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"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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 doc1 = newHTMLDocument(); + var template = doc1.createElement('template'); + + assert_equals(template.ownerDocument, doc1, 'Wrong template node owner document'); + assert_not_equals(template.content.ownerDocument, doc1, + 'Wrong template content owner document'); + + var doc2 = newHTMLDocument(); + var template2 = doc2.createElement('template'); + doc2.body.appendChild(template); + + assert_equals(template.ownerDocument, template2.ownerDocument, + 'Template node owner document should be changed'); + assert_equals(template.content.ownerDocument, template2.content.ownerDocument, + 'Template content owner document should be changed'); + +}, 'Changing of template element\'s node document. ' + + 'Test that ownerDocument of an empty template and its content changes'); + +test(function() { + var doc1 = newHTMLDocument(); + doc1.body.innerHTML = '<template id="tmpl"><div>Div content</div> And some more text</template>'; + + var template = doc1.querySelector('#tmpl'); + + assert_equals(template.ownerDocument, doc1, + 'Wrong template node owner document'); + assert_not_equals(template.content.ownerDocument, doc1, + 'Wrong template content owner document'); + + var doc2 = newHTMLDocument(); + var template2 = doc2.createElement('template'); + doc2.body.appendChild(template); + + assert_equals(template.ownerDocument, template2.ownerDocument, + 'Template node owner document should be changed'); + assert_equals(template.content.ownerDocument, template2.content.ownerDocument, + 'Template content owner document should be changed'); + + assert_equals(template.content.querySelector('div').ownerDocument, + template2.content.ownerDocument, + 'Template content descendants owner document should be changed'); + +}, 'Changing of template element\'s node document. ' + + 'Test that ownerDocument of a not empty template and its content changes'); + +test(function() { + var doc1 = newHTMLDocument(); + doc1.body.innerHTML = '' + + '<template id="tmpl"><div>Div content</div> And some more text' + + '<template id="tmpl2"><div>Template content</div></template>' + + '</template>'; + + var template = doc1.querySelector('#tmpl'); + + assert_equals(template.ownerDocument, doc1, 'Wrong template node owner document'); + assert_not_equals(template.content.ownerDocument, doc1, + 'Wrong template content owner document'); + + var nestedTemplate = template.content.querySelector('#tmpl2'); + + assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument, + 'Wrong nested template node owner document'); + assert_equals(nestedTemplate.content.ownerDocument, template.content.ownerDocument, + 'Wrong nested template content owner document'); + + var doc2 = newHTMLDocument(); + var template2 = doc2.createElement('template'); + doc2.body.appendChild(template); + + assert_equals(template.ownerDocument, template2.ownerDocument, + 'Template node owner document should be changed'); + assert_equals(template.content.ownerDocument, template2.content.ownerDocument, + 'Template content owner document should be changed'); + assert_equals(template.content.querySelector('div').ownerDocument, + template2.content.ownerDocument, + 'Template content descendants owner document should be changed'); + + assert_equals(nestedTemplate.ownerDocument, + template2.content.ownerDocument, + 'Nested template node owner document should be changed'); + assert_equals(nestedTemplate.content.ownerDocument, + template2.content.ownerDocument, + 'Nested template content owner document should be changed'); + assert_equals(nestedTemplate.content.querySelector('div').ownerDocument, + template2.content.ownerDocument, + 'Owner document of the nested template content descendants should be changed'); + +}, 'Changing of template element\'s node document. ' + + 'Test that ownerDocument of nested template and its content changes'); + +testInIFrame('../resources/template-contents.html', function(context) { + var doc1 = context.iframes[0].contentDocument; + + var template = doc1.body.querySelector('template'); + + var doc2 = newHTMLDocument(); + var template2 = doc2.createElement('template'); + doc2.body.appendChild(template); + + assert_equals(template.ownerDocument, template2.ownerDocument, + 'Template node owner document should be changed'); + assert_equals(template.content.ownerDocument, + template2.content.ownerDocument, + 'Template content owner document should be changed'); + assert_equals(template.content.querySelector('div').ownerDocument, + template2.content.ownerDocument, + 'Template content descendants owner document should be changed'); + +}, 'Changing of template element\'s node document. ' + + 'Test document loaded from a file'); + +testInIFrame('../resources/template-contents.html', function(context) { + var doc1 = context.iframes[0].contentDocument; + + var doc2 = newHTMLDocument(); + var template = doc2.createElement('template'); + var div = doc2.createElement('div'); + template.content.appendChild(div); + + doc1.body.appendChild(template); + + assert_not_equals(template.ownerDocument, doc2, + 'Template node owner document should be changed'); + assert_not_equals(template.content.ownerDocument, doc2, + 'Template content owner document should be changed'); + assert_not_equals(div.ownerDocument, doc2, + 'Template content descendants owner document should be changed'); + + assert_equals(template.ownerDocument, doc1, + 'Template node owner document should be changed'); + // doc1 has browsing context so it cannot be template.content.ownerDocument + assert_not_equals(template.content.ownerDocument, doc1, + 'Template content owner document should be a new document'); + assert_equals(div.ownerDocument, template.content.ownerDocument, + 'Template content descendants owner document should be ' + + 'template content document owner'); + +}, 'Changing of template element\'s node document. ' + + 'Adobt template element into a document that has a browsing context'); + +testInIFrame('../resources/template-contents.html', function(context) { + var doc1 = context.iframes[0].contentDocument; + + var template = doc1.querySelector('template'); + var div = template.content.querySelector('div'); + var templateContentOwner = template.content.ownerDocument; + + var doc2 = document; + + doc2.body.appendChild(template); + + assert_not_equals(template.ownerDocument, doc1, + 'Template node owner document should be changed'); + assert_not_equals(template.content.ownerDocument, templateContentOwner, + 'Template content owner document should be changed'); + assert_not_equals(div.ownerDocument, templateContentOwner, + 'Template content descendants owner document should be changed'); + + assert_equals(template.ownerDocument, doc2, + 'Template node owner document should be changed'); + // doc2 has browsing context, so it cannot be template.content.ownerDocument + assert_not_equals(template.content.ownerDocument, doc2, + 'Template content owner document should be a new document'); + assert_equals(div.ownerDocument, template.content.ownerDocument, + 'Template content descendants owner document should be ' + + 'template content document owner'); + +}, 'Changing of template element\'s node document. ' + + 'Test the case when both old and new owner documents of template element ' + + 'have browsing context'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-as-a-descendant.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-as-a-descendant.html new file mode 100644 index 0000000000..caa1beab47 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-as-a-descendant.html @@ -0,0 +1,135 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Template element as a descendant of the body element.</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Template element can be a descendant of the body element"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-template-element"> +<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"> + +function templateIsAChild(element) { + element.innerHTML = '<template>some text</template>'; + + assert_not_equals(element.querySelector('template'), null, + 'Template element should be a descendant of the ' + element.tagName + ' element'); +} + +function templateIsDisallowedAsAChild(element) { + element.innerHTML = '<template>some text</template>'; + + assert_equals(element.querySelector('template'), null, + 'Template element should not be allowed as a descendant of the ' + element.tagName + ' element'); +} + +function templateIsAnIndirectChild(element) { + element.innerHTML = '<div><template>some text</template></div>'; + + assert_not_equals(element.querySelector('template'), null, + 'Template element should be a descendant of the ' + element.tagName + ' element'); +} + +function templateIsDisallowedAsAnIndirectChild(element) { + element.innerHTML = '<div><template>some text</template></div>'; + + assert_equals(element.querySelector('template'), null, + 'Template element should not be allowed as indirect descendant of the ' + element.tagName + ' element'); +} + +function templateIsAnAppendedChild(doc, element) { + var template = doc.createElement('template'); + + element.appendChild(template); + + assert_not_equals(element.querySelector('template'), null, + 'Template element should be a descendant of the ' + element.tagName + ' element'); +} + +function templateIsAnAppendedIndirectChild(doc, element) { + var template = doc.createElement('template'); + var div = doc.createElement('div'); + div.appendChild(template); + + element.appendChild(div); + + assert_not_equals(element.querySelector('template'), null, + 'Template element should be a descendant of the ' + element.tagName + ' element'); +} + +var doc = newHTMLDocument(); +var frameset = doc.createElement('frameset'); + +var parameters = [['Template element as a descendant of the BODY element. ' + + 'Template element is created by innerHTML', + doc.body], + ['Template element as a descendant of the HEAD element. ' + + 'Template element is created by innerHTML', + doc.head], + ]; +// Template element as a descendant of the HEAD and BODY elements +generate_tests(templateIsAChild, parameters); + +parameters = [['Template element as a descendant of the FRAMESET element. ' + + 'Template element is created by innerHTML', + frameset], + ]; +// Template element should be disallowed as a descendant of the FRAMESET elements +generate_tests(templateIsDisallowedAsAChild, parameters); + + +parameters = [['Template element as an indirect descendant of the BODY element. ' + + 'Template element is created by innerHTML', + doc.body], + ['Template element as an indirect descendant of the HEAD element. ' + + 'Template element is created by innerHTML', + doc.head], + ]; +// Template element as an indirect descendant of the HEAD, BODY and FRAMESET elements +generate_tests(templateIsAnIndirectChild, parameters); + +parameters = [['Template element as an indirect descendant of the FRAMESET element. ' + + 'Template element is created by innerHTML', + frameset], + ]; +// Template element should be disallowed as an indirect descendant of the FRAMESET elements +generate_tests(templateIsDisallowedAsAnIndirectChild, parameters); + + + +parameters = [['Template element as a descendant of the BODY element. ' + + 'Template element is appended by appendChild()', + doc, doc.body], + ['Template element as a descendant of the HEAD element. ' + + 'Template element is appended by appendChild()', + doc, doc.head], + ['Template element as a descendant of the FRAMESET element. ' + + 'Template element is appended by appendChild()', + doc, frameset] + ]; +// Template element as a descendant of the HEAD, BODY and FRAMESET elements +generate_tests(templateIsAnAppendedChild, parameters); + + + +parameters = [['Template element as an indirect descendant of the BODY element. ' + + 'Template element is appended by appendChild()', + doc, doc.body], + ['Template element as an indirect descendant of the HEAD element. ' + + 'Template element is appended by appendChild()', + doc, doc.head], + ['Template element as an indirect descendant of the FRAMESET element. ' + + 'Template element is appended by appendChild()', + doc, frameset] + ]; +// Template element as a descendant of the HEAD, BODY and FRAMESET elements +generate_tests(templateIsAnAppendedIndirectChild, parameters); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-construction-in-inactive-document-crash.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-construction-in-inactive-document-crash.html new file mode 100644 index 0000000000..496a47b2c5 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-construction-in-inactive-document-crash.html @@ -0,0 +1,5 @@ +<iframe id="i"></iframe> +<script> +i.contentDocument.documentElement.appendChild(document.body); +</script> +<template><script></script></template> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html new file mode 100644 index 0000000000..823c0c830f --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html @@ -0,0 +1,81 @@ +<!DOCTYPE html> +<meta name="author" title="Takayoshi Kochi" href="mailto:kochi@chromium.org"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<div id="parent"> + <template id="tmpl"><span>Happy Templating!</span></template> +</div> +<script> +test(() => { + var parent = document.getElementById('parent'); + var tmpl = document.getElementById('tmpl'); + + assert_equals(tmpl.innerHTML, '<span>Happy Templating!</span>'); + var span = tmpl.content.querySelector('span'); + + // Hierarchy checks at various combinations. + assert_throws_dom('HierarchyRequestError', () => { + tmpl.content.appendChild(parent); + }, 'Template content should throw if any of ancestor is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + tmpl.content.appendChild(tmpl); + }, 'Template content should throw if its host is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + span.appendChild(parent); + }, 'Template content child should throw if any of ancestor is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + span.appendChild(tmpl); + }, 'Template content child should throw template\'s host is being appended.'); +}, "Template content should throw when its ancestor is being appended."); + +test(() => { + var parent = document.getElementById('parent'); + var tmpl = document.getElementById('tmpl'); + + assert_equals(tmpl.innerHTML, '<span>Happy Templating!</span>'); + var span = tmpl.content.querySelector('span'); + + var tmpl_doc = tmpl.content.ownerDocument; + assert_equals(tmpl.ownerDocument, document); + assert_not_equals(tmpl_doc, document); + + var new_doc = document.implementation.createHTMLDocument(); + assert_not_equals(new_doc, document); + assert_not_equals(new_doc, tmpl_doc); + + // Try moving tmpl.content to new_doc and check the results. + const tmplContentNodeDocument = tmpl.content.ownerDocument; + const tmplContentAdoptResult = new_doc.adoptNode(tmpl.content); + assert_equals(tmpl.content, tmplContentAdoptResult); + assert_equals(tmpl.ownerDocument, document); + assert_equals(tmpl.content.ownerDocument, tmplContentNodeDocument); + + // Hierarchy checks at various combinations. + assert_throws_dom('HierarchyRequestError', () => { + tmpl.content.appendChild(parent); + }, 'Template content should throw if any of ancestor is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + tmpl.content.appendChild(tmpl); + }, 'Template content should throw if its host is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + span.appendChild(parent); + }, 'Template content child should throw if any of ancestor is being appended.'); + assert_throws_dom('HierarchyRequestError', () => { + span.appendChild(tmpl); + }, 'Template content child should throw template\'s host is being appended.'); + + // Sanity check: template.content before and after move. + var tmpl_content_reference = tmpl.content; + assert_equals(tmpl.content.firstChild, span, + '<span> should be kept until it is removed, even after ' + + 'adopted to another document.'); + new_doc.body.appendChild(tmpl.content); + assert_equals(tmpl.content.firstChild, null, + '<span> should be removed from template content.'); + assert_equals(tmpl_content_reference, tmpl.content, + 'template.content should be identical before and after ' + + 'moving its children.'); +}, 'Template content should throw exception when its ancestor in ' + + 'a different document but connected via host is being append.'); +</script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-in-inactive-document-crash.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-in-inactive-document-crash.html new file mode 100644 index 0000000000..66c564c77a --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-in-inactive-document-crash.html @@ -0,0 +1,7 @@ +<iframe id="i"></iframe> +<script> +var t = i.contentDocument.createElement("template"); +i.contentDocument.documentElement.appendChild(t); +i.remove(); +t.content; +</script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-move-to-inactive-document-crash.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-move-to-inactive-document-crash.html new file mode 100644 index 0000000000..89c56d1663 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-move-to-inactive-document-crash.html @@ -0,0 +1,7 @@ +<div id="d"> +<iframe id="i"></iframe> +<template id="t"> </template> +</div> +<script> +i.contentDocument.documentElement.appendChild(d); +</script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-node-document.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-node-document.html new file mode 100644 index 0000000000..da76c6b04f --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content-node-document.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Node document of the template content attribute must be template contents owner</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Node document of the template content attribute must be template contents owner"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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'); + var nestedTemplate = doc.createElement('template'); + template.appendChild(nestedTemplate); + + assert_equals(nestedTemplate.content.ownerDocument, template.content.ownerDocument, + 'Wrong node document of the template content attribute'); + +}, 'Node document of the template content attribute must be template contents owner. ' + + 'Nested template element created by createElement'); + + +test(function() { + var doc = newHTMLDocument(); + doc.body.innerHTML = '<template><template></template></template>'; + var template = doc.querySelector('template'); + var nestedTemplate = template.content.querySelector('template'); + + assert_equals(nestedTemplate.content.ownerDocument, template.content.ownerDocument, + 'Wrong node document of the template content attribute'); + +}, 'Node document of the template content attribute must be template contents owner. ' + + 'Nested template element created by innerHTML'); + +testInIFrame('../resources/two-templates.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var template1 = doc.querySelector('#template1'); + var template2 = doc.querySelector('#template2'); + + // when there is a browsing context, template contents owner is only accessible via template.content.ownerDocument + // because template contents owner is bounded to document + // verify that multiple templates share the same instance of template contents owner + + assert_equals(template1.content.ownerDocument, template2.content.ownerDocument, + 'Wrong node document of the template content attribute'); +}, 'Node document of the template content attribute must be template contents owner. ' + + 'Load HTML file with multiple template elements'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content.html new file mode 100644 index 0000000000..b9e790daf8 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-content.html @@ -0,0 +1,63 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: HTML elements in template content</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="author" title="Aleksei Yu. Semenov" href="a.semenov@unipro.ru"> +<meta name="assert" content="Template may contain any element, except the html element, the head element, the body element, or the frameset element"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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"> + +HTML5_ELEMENTS.forEach(function(value) { + if (value !== 'body' && value !== 'html' && value !== 'head' && value !== 'frameset') { + + test(function() { + var doc = newHTMLDocument(); + var template = doc.createElement('template'); + var element = doc.createElement(value); + template.content.appendChild(element); + var valueToTest = template.content.querySelector(value); + + doc.body.appendChild(template); + + assert_not_equals(valueToTest, null); + }, 'Template may contain ' + value + ' element'); + + } +}); + + + +var parameters = []; + +HTML5_ELEMENTS.forEach(function(value) { + if (value !== 'body' && value !== 'html' && value !== 'head' && value !== 'frameset') { + + test(function() { + var doc = newHTMLDocument(); + + if (isVoidElement(value)) { + doc.body.innerHTML = '<template><' + value + '/></template>'; + } else { + doc.body.innerHTML = '<template><' + value + '></' + value + '></template>'; + } + + var template = doc.querySelector('template'); + var element = template.content.querySelector(value); + + assert_not_equals(element, null); + }, 'Template may contain ' + value + ' element. ' + + 'The template element and contents are added via body.innerHTML'); + + } +}); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-body.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-body.html new file mode 100644 index 0000000000..70028c5ecd --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-body.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Template element as a descendant of the body element.</title> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Template element can be a descendant of the body element"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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"> + +testInIFrame('../resources/template-contents.html', function(ctx) { + var doc = ctx.iframes[0].contentDocument; + + assert_not_equals(doc.body.querySelector('template'), null, + 'Template element should be a descendant of the body element'); + +}, 'Template element as a descendant of the body element. Test loading from a file'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-frameset.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-frameset.html new file mode 100644 index 0000000000..ce20a7413e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-frameset.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Template element as a descendant of the frameset element.</title> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Template element can not be a descendant of the frameset element"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#parsing-main-inframeset"> +<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"> + +testInIFrame('../resources/template-descendant-frameset.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var frameset = doc.querySelector('frameset'); + + assert_equals(frameset.querySelector('template'), null, + 'Template element should not be a descendant of the frameset element'); + +}, 'Template element as a descendant of the frameset element. Test loading from a file'); + + +testInIFrame('../resources/template-descendant-frameset.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var frameset = doc.querySelector('frameset'); + + frameset.innerHTML = ''; + assert_equals(doc.querySelector('template'), null, + 'Initial conditions are not satisfied'); + + frameset.innerHTML = '<template>some text</template>'; + + assert_equals(frameset.querySelector('template'), null, + 'Template element should not be a descendant of the frameset element'); + +}, 'Template element as a descendant of the frameset element. ' + + 'Test template element is assigned to frameset\'s innerHTML)'); + + +testInIFrame('../resources/template-descendant-frameset.html', function(context) { + var doc = context.iframes[0].contentDocument; + + var frameset = doc.querySelector('frameset'); + + var template = doc.createElement('template'); + frameset.appendChild(template); + + assert_equals(frameset.querySelectorAll('template').length, 1, + 'Template element should be a descendant of the frameset element'); + +}, 'Template element as a descendant of the frameset element. ' + + 'Test template element appended to frameset by appendChild()'); + + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-head.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-head.html new file mode 100644 index 0000000000..611ec50bb4 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-descendant-head.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<html> +<head> +<title>HTML Templates: Template element as a descendant of the head element.</title> +<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> +<meta name="assert" content="Template element can be a descendant of the head element"> +<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> +<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"> + +testInIFrame('../resources/template-descendant-head.html', function(context) { + var doc = context.iframes[0].contentDocument; + + assert_not_equals(doc.head.querySelector('template'), null, + 'Template element should be a descendant of the head element'); + +}, 'Template element as a descendant of the head element. Test loading from a file'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-element-clone-into-inactive-document-crash.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-element-clone-into-inactive-document-crash.html new file mode 100644 index 0000000000..56b199d1eb --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-element-clone-into-inactive-document-crash.html @@ -0,0 +1,7 @@ +<template id="t"> </template> +<iframe id="i"></iframe> +<script> +var doc = i.contentDocument; +i.remove(); +doc.importNode(t, true); +</script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-set-inner-html-in-inactive-document-crash.html b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-set-inner-html-in-inactive-document-crash.html new file mode 100644 index 0000000000..79a76ee76f --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-template-element/template-element/template-set-inner-html-in-inactive-document-crash.html @@ -0,0 +1,6 @@ +<iframe id="i"></iframe> +<script> + var doc = i.contentDocument; + i.remove(); + doc.createElement("template").innerHTML = ""; +</script> |