Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255

This commit is contained in:
James Graham 2015-03-27 09:15:38 +00:00
parent b2a5225831
commit 1a81b18b9f
12321 changed files with 544385 additions and 6 deletions

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Async property on a dynamically-created script is true by default</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test checks the Async property on a dynamically-created script element. By default it should be true." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-script-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
test(function() {assert_true(document.createElement("script").async)}, "Async property on a dynamically-created script is true by default");
</script>
</body>
</html>

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Changes to the 'async' attribute are reflected in the async property</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures changes to the 'async' attribute are reflected in the async property." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-script-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
test(function() {
var s = document.createElement("script");
s.async = false;
s.setAttribute('async', ''); /*Should change s.async to true*/
assert_true(s.async)
}, "Test 'async' attribute are reflected in the async property with setAttribute");
test(function() {
var s = document.createElement("script");
s.async = false;
s.setAttribute('async', ''); /*Should change s.async to true*/
s.removeAttribute('async'); /*Should change s.async to false*/
assert_false(s.async)
}, "Test 'async' attribute are reflected in the async property with removeAttribute");
</script>
</body>
</html>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>An async script does not block the parser while downloading</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures an async script does not block the parser while downloading." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-script-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("An async script does not block the parser while downloading");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "21")});
t.done();
}
var timer = setTimeout(timeout, 4000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script src="log.py?sec=3&id=1" async></script>
<script>
log('2');
</script>
</body>
</html>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>An async script executes as soon as possible after a download is complete</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures an async script executes as soon as possible after a download is complete." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-script-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("async script executes as soon as possible after a download is complete");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "21")});
t.done();
}
var timer = setTimeout(timeout, 4000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script src="log.py?sec=3&id=1" async></script>
<script src="log.py?sec=1&id=2" async></script>
</body>
</html>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>A script element with both async and defer set should execute asynchronously</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures a script element with both async and defer set should execute asynchronously." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-script-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("A script element with both async and defer set should execute asynchronously");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "2134")});
t.done();
}
var timer = setTimeout(timeout, 5000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script type="text/javascript" src="log.py?sec=1&id=1" defer async></script>
<script type="text/javascript">log('2');</script>
<script type="text/javascript" src="log.py?sec=3&id=3"></script>
<script type="text/javascript">log('4');</script>
</body>
</html>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>A dynamically created external script executes asynchronously</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures a dynamically created external script executes asynchronously." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#force-async"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("dynamically created external script executes asynchronously");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "321")});
t.done();
}
var timer = setTimeout(timeout, 4000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script type="text/javascript">
var one = document.createElement("script");
one.src="log.py?sec=3&id=1";
document.head.appendChild(one);
var two = document.createElement("script");
two.src="log.py?sec=1&id=2";
document.head.appendChild(two);
log('3');
</script>
</body>
</html>

View file

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<title>Ordered async script execution when script.async == false</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures Ordered async script execution when script.async == false" />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#script-processing-src-sync"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("Ordered async script execution when script.async == false");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "312")});
t.done();
}
var timer = setTimeout(timeout, 8000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script type="text/javascript">
var one = document.createElement("script");
one.src="log.py?sec=3&id=1";
one.async = false;
document.head.appendChild(one);
var two = document.createElement("script");
two.src="log.py?sec=1&id=2";
two.async = false;
document.head.appendChild(two);
</script>
<script type="text/javascript">
log('3');
</script>
</body>
</html>

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Async script element execution delays the window's load event</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures an async script element's execution delays the window's load event." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#delay-the-load-event"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script type="text/javascript">
var t = async_test("Async script element execution delays the window's load event");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "213")});
t.done();
}
var timer = setTimeout(timeout, 8000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
<span id="testresult"></span>
<script type="text/javascript">
window.addEventListener("load", function() {
log("3");
timeout();
}, false);
var s1 = document.createElement("script");
s1.src = "log.py?sec=2&id=1";
document.head.appendChild(s1);
</script>
<script type="text/javascript">
log('2');
</script>
</body>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Document.write() silently fails from an Async script</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures Document.write() silently fails from an Async script." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
var t = async_test("Document.write() silently fails from an Async script");
var log = t.step_func(function() {
document.write("<span id='writtenText'/>");
assert_equals(null, document.getElementById('writtenText'));
t.done();
});
</script>
</head>
<body>
<div id=log></div>
<script type="text/javascript" src="log.py?sec=1&id=1" async></script>
</body>
</html>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Removing an async script before execution</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="This test ensures that an async script still executes if it is removed from a markup before the download is complete. The other two scripts that come after it in insertion order should execute as well." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
var t = async_test("Removing an async script before execution");
function timeout()
{
t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "4123")});
t.done();
}
var timer = setTimeout(timeout, 8000);
function log(text)
{
var textNode = document.createTextNode(text);
document.getElementById("testresult").appendChild(textNode);
}
</script>
</head>
<body>
<div id=log></div>
<span id="testresult"></span>
<script type="text/javascript">
var s1 = document.createElement("script");
s1.src="log.py?sec=2&id=1";
s1.async = false;
document.body.appendChild(s1);
var s2 = document.createElement("script");
s2.src="log.py?sec=1&id=2";
s2.async = false;
document.body.appendChild(s2);
var s3 = document.createElement("script");
s3.id = "s3";
s3.src="log.py?sec=0&id=3";
s3.async = false;
document.body.appendChild(s3);
//Remove s1 (Should still execute)
document.body.removeChild(s1);
</script>
<script type="text/javascript">log('4');</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>An empty parser-inserted script element should return async=true</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta description="An empty parser-inserted script element should return async=true." />
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<script></script>
<script type="text/javascript">
test(function() { assert_true(document.getElementsByTagName("script")[2].async)}, "An empty parser-inserted script element should return async=true");
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
[
{
"id": "scriptinglanguages",
"original_id": "scriptingLanguages"
},
{
"id": "restrictions-for-contents-of-script-elements",
"original_id": "restrictions-for-contents-of-script-elements"
},
{
"id": "inline-documentation-for-external-scripts",
"original_id": "inline-documentation-for-external-scripts"
},
{
"id": "scripttagxslt",
"original_id": "scriptTagXSLT"
}
]

View file

@ -0,0 +1,13 @@
import time
def main(request, response):
response.headers.append("Content-Type", "text/javascript")
try:
script_id = int(request.GET.first("id"))
delay = int(request.GET.first("sec"))
except:
response.set_error(400, "Invalid parameter")
time.sleep(int(delay))
return "log('%s')" % script_id

View file

@ -0,0 +1,55 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>script beforescriptexecute/afterscriptexecute events</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/#the-script-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t1 = async_test("'beforescriptexecute'/'afterscriptexecute' events have been fired"),
t2 = async_test("default prevented 'beforescriptexecute' event aborts script execution"),
a = false,
b = false;
var before = function(e) {
b = true;
test(function(){
assert_true(e.isTrusted);
assert_true(e.bubbles);
assert_true(e.cancelable);
}, "'beforescriptexecute' event is trusted, bubbles and is cancelable");
};
var after = function(e) {
a = true;
test(function(){
assert_true(e.isTrusted);
assert_true(e.bubbles);
assert_false(e.cancelable);
}, "'afterscriptexecute' event is trusted, bubbles and isn't cancelable");
};
var prevent_default = function(e) {
t2.step(function() {
e.preventDefault();
assert_true(e.defaultPrevented);
});
};
document.body.onload = function() {
t1.step(function() {
assert_true(a && b);
});
t1.done();
t2.done();
};
</script>
<script onbeforescriptexecute=before(event) onafterscriptexecute=after(event)>
document.querySelector("script");
</script>
<script onbeforescriptexecute=prevent_default(event)>
t2.step(function() {
assert_unreached("script execution not aborted by default prevented 'beforescriptexecute' event");
});
</script>

View file

@ -0,0 +1,93 @@
<!DOCTYPE html>
<title>Scripts with for and event attributes</title>
<link rel="author" title="Matheus Kerschbaum" href="mailto:matjk7@gmail.com">
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var expected = [
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
true,
true,
false,
true,
true,
];
var run = expected.map(function() { return false });
</script>
<script for="w&#x130;ndow" event="onload">
run[0] = true;
</script>
<script for="window" event="onload x">
run[1] = true;
</script>
<script for="window" event="onload(x">
run[2] = true;
</script>
<script for="window" event="onload(x)">
run[3] = true;
</script>
<script for="window" event="onclick">
run[4] = true;
</script>
<script for="" event="onload">
run[5] = true;
</script>
<script for="window" event="">
run[6] = true;
</script>
<script for="" event="">
run[7] = true;
</script>
<script for="&#xa0;window" event="onload">
run[8] = true;
</script>
<script for="window&#xa0;" event="onload">
run[9] = true;
</script>
<script for="window" event="&#xa0;onload">
run[10] = true;
</script>
<script for="window" event="onload&#xa0;">
run[11] = true;
</script>
<script for=" window " event=" onload ">
run[12] = true;
</script>
<script for=" window " event=" onload() ">
run[13] = true;
</script>
<script for="object" event="handler">
run[14] = true;
</script>
<script event="handler">
run[15] = true;
</script>
<script for="object">
run[16] = true;
</script>
<script>
test(function() {
for (var i = 0; i < run.length; ++i) {
test(function() {
var script = document.querySelectorAll("script[for], script[event]")[i];
assert_equals(run[i], expected[i],
"script for=" + format_value(script.getAttribute("for")) +
" event=" + format_value(script.getAttribute("event")));
}, "Script " + i);
}
});
</script>

View file

@ -0,0 +1,22 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Scripts with for and event attributes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var run = false;
</script>
<script for="window" event="bar">
// This script should not run, but should not cause a parse error either.
run = true;
</script>
<script>
test(function() {
assert_false(run, "Script was unexpectedly run.")
}, "Scripts with for and event attributes should not run.")
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>Script: combinations of @type and @language</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var run = false;
</script>
<script type="" language="foo">
run = true;
</script>
<script>
test(function() {
assert_equals(run, true);
}, "A script with empty type should run");
</script>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>Script @type: unknown parameters</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#scriptingLanguages">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<script type="text/javascript;charset=UTF-8">
test(function() {
assert_unreached("'charset' should have prevented this script from executing.");
})
</script>
<script type="text/javascript;x-test=abc">
test(function() {
assert_unreached("'x-test' should have prevented this script from executing.");
})
</script>
</div>
<script>
test(function() {
assert_true(true)
})
</script>

View file

@ -0,0 +1,98 @@
<!DOCTYPE html>
<title>Script @type: JavaScript types</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#scriptingLanguages">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
function testAttribute(attr, val, shouldRun) {
test(function() {
assert_false(ran, "ran variable not reset");
var script = document.createElement("script");
script.setAttribute(attr, val);
script.textContent = "ran = true;"
document.body.appendChild(script);
assert_equals(ran, shouldRun);
}, "Script should" + (shouldRun ? "" : "n't") + " run with " + attr + "=" + format_value(val));
ran = false
}
function testType(type) {
testAttribute("type", type, true);
}
function testLanguage(lang) {
testAttribute("language", lang, true);
}
function testTypeIgnored(type) {
testAttribute("type", type, false);
}
function testLanguageIgnored(lang) {
testAttribute("language", lang, false);
}
var application = [
"ecmascript",
"javascript",
"x-ecmascript",
"x-javascript"
];
var text = [
"ecmascript",
"javascript",
"javascript1.0",
"javascript1.1",
"javascript1.2",
"javascript1.3",
"javascript1.4",
"javascript1.5",
"jscript",
"livescript",
"x-ecmascript",
"x-javascript"
];
var spaces = [" ", "\t", "\n", "\r", "\f"];
var ran = false;
// Type attribute
testType("");
testTypeIgnored(" ");
application.map(function(t) { return "application/" + t; }).forEach(testType);
application.map(function(t) { return ("application/" + t).toUpperCase(); }).forEach(testType);
spaces.forEach(function(s) {
application.map(function(t) { return "application/" + t + s; }).forEach(testType);
application.map(function(t) { return s + "application/" + t; }).forEach(testType);
})
application.map(function(t) { return "application/" + t + "\0"; }).forEach(testTypeIgnored);
application.map(function(t) { return "application/" + t + "\0foo"; }).forEach(testTypeIgnored);
text.map(function(t) { return "text/" + t; }).forEach(testType);
text.map(function(t) { return ("text/" + t).toUpperCase(); }).forEach(testType);
spaces.forEach(function(s) {
text.map(function(t) { return "text/" + t + s; }).forEach(testType);
text.map(function(t) { return s + "text/" + t; }).forEach(testType);
})
text.map(function(t) { return "text/" + t + "\0"; }).forEach(testTypeIgnored);
text.map(function(t) { return "text/" + t + "\0foo"; }).forEach(testTypeIgnored);
// Language attribute
testLanguage("");
testLanguageIgnored(" ");
text.forEach(testLanguage);
text.map(function(t) { return t.toUpperCase(); }).forEach(testLanguage);
text.map(function(t) { return t + " "; }).forEach(testLanguageIgnored);
text.map(function(t) { return " " + t; }).forEach(testLanguageIgnored);
text.map(function(t) { return t + "xyz"; }).forEach(testLanguageIgnored);
text.map(function(t) { return "xyz" + t; }).forEach(testLanguageIgnored);
text.map(function(t) { return t + "\0"; }).forEach(testLanguageIgnored);
text.map(function(t) { return t + "\0foo"; }).forEach(testLanguageIgnored);
</script>

View file

@ -0,0 +1,36 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Script inside noembed, noframes and iframe</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var run = [];
</script>
<div id="test">
<noembed>
<script>
run.push("noembed");
</script>
</noembed>
<noframes>
<script>
run.push("noframes");
</script>
</noframes>
<iframe>
<script>
run.push("iframe");
</script>
</iframe>
</div>
<script>
test(function() {
assert_array_equals(run, ["noembed", "noframes", "iframe"], "Haven't run.");
});
</script>
</body>
</html>

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>Script: setting onload to a string</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
test(function() {
var s = document.createElement("script");
assert_equals(s.onload, null);
var dummy = function() {};
s.onload = dummy;
assert_equals(s.onload, dummy);
s.onload = "w('load DOM appended')";
assert_equals(s.onload, null);
}, "Setting onload to a string should convert to null.");
</script>

View file

@ -0,0 +1,53 @@
<!doctype html>
<meta charset=utf-8>
<title>HTMLScriptElement.text</title>
<link rel=help href="https://html.spec.whatwg.org/multipage/#dom-script-text">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var script;
setup(function() {
script = document.createElement("script")
script.appendChild(document.createComment("COMMENT"))
script.appendChild(document.createTextNode(" TEXT "))
script.appendChild(document.createProcessingInstruction("P", "I"))
script.appendChild(document.createElement("a"))
.appendChild(document.createTextNode("ELEMENT"))
})
test(function() {
assert_equals(script.text, " TEXT ")
assert_equals(script.textContent, " TEXT ELEMENT")
}, "Getter")
test(function() {
script.text = " text "
assert_equals(script.text, " text ")
assert_equals(script.textContent, " text ")
assert_equals(script.firstChild.nodeType, Node.TEXT_NODE)
assert_equals(script.firstChild.data, " text ")
assert_equals(script.firstChild, script.lastChild)
assert_array_equals(script.childNodes, [script.firstChild])
}, "Setter (non-empty string)")
test(function() {
script.text = ""
assert_equals(script.text, "")
assert_equals(script.textContent, "")
assert_equals(script.firstChild, null)
}, "Setter (empty string)")
test(function() {
script.text = null
assert_equals(script.text, "null")
assert_equals(script.textContent, "null")
assert_equals(script.firstChild.nodeType, Node.TEXT_NODE)
assert_equals(script.firstChild.data, "null")
assert_equals(script.firstChild, script.lastChild)
}, "Setter (null)")
test(function() {
script.text = undefined
assert_equals(script.text, "undefined")
assert_equals(script.textContent, "undefined")
assert_equals(script.firstChild.nodeType, Node.TEXT_NODE)
assert_equals(script.firstChild.data, "undefined")
assert_equals(script.firstChild, script.lastChild)
}, "Setter (undefined)")
</script>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTMLScriptElement.text</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-script-text"/>
<script src="/resources/testharness.js"/>
<script src="/resources/testharnessreport.js"/>
</head>
<body>
<div id="log"></div>
<script>
<x>7;</x>
<![CDATA[
var x = "y";
]]>
</script>
<script>
var script;
setup(function() {
script = document.body.getElementsByTagName("script")[0];
})
test(function() {
assert_equals(script.text, '\n\n\n var x = "y";\n\n')
assert_equals(script.textContent, '\n7;\n\n var x = "y";\n\n')
}, "Getter with CDATA section")
</script>
</body>
</html>

View file

@ -0,0 +1,148 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: Parsing XHTML: Node's node document</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="Parsing XHTML: Node's node document must be set to that of the element to which it will be appended">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#parsing-xhtml-documents">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function() {
var doc = newXHTMLDocument();
doc.body = doc.createElement('body');
doc.body.innerHTML = '<template id="tmpl"></template>';
var template = doc.querySelector('#tmpl');
assert_not_equals(template, null, 'Template element should not be null');
assert_not_equals(template.content, undefined,
'Content attribute of template element should not be undefined');
assert_not_equals(template.content, null,
'Content attribute of template element should not be null');
assert_equals(template.ownerDocument, doc.body.ownerDocument,
'Wrong template node owner document');
assert_equals(template.content.ownerDocument, doc,
'Wrong template content owner document');
}, 'Parsing XHTML: Node\'s node document must be set to that of the element '
+ 'to which it will be appended. Test empty template');
test(function() {
var doc = newXHTMLDocument();
doc.body = doc.createElement('body');
doc.body.innerHTML = '<template id="tmpl"><div>Div content</div></template>';
var template = doc.querySelector('#tmpl');
assert_equals(template.ownerDocument, doc.body.ownerDocument,
'Wrong template node owner document');
assert_not_equals(template, null, 'Template element should not be null');
assert_not_equals(template.content, undefined,
'Content attribute of template element should not be undefined');
assert_not_equals(template.content, null,
'Content attribute of template element should not be null');
var div = template.content.querySelector('div');
assert_equals(template.content.ownerDocument, div.ownerDocument,
'Wrong DIV node owner document');
}, 'Parsing XHTML: Node\'s node document must be set to that of the element '
+ 'to which it will be appended. Test not empty template');
test(function() {
var doc = newXHTMLDocument();
doc.body = doc.createElement('body');
doc.body.innerHTML = ''
+ '<template id="tmpl"><div>Div content</div> And some more text'
+ '<template id="tmpl2"><div>Template content</div></template>'
+ '</template>';
var template = doc.querySelector('#tmpl');
assert_not_equals(template, null, 'Template element should not be null');
assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
assert_not_equals(template.content, undefined,
'Content attribute of template element should not be undefined');
assert_not_equals(template.content, null,
'Content attribute of template element should not be null');
var nestedTemplate = template.content.querySelector('#tmpl2');
assert_not_equals(nestedTemplate, null, 'Nested template element should not be null');
assert_not_equals(nestedTemplate.content, undefined,
'Content attribute of nested template element should not be undefined');
assert_not_equals(nestedTemplate.content, null,
'Content attribute of nested template element should not be null');
assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument,
'Wrong nested template node owner document');
var div = nestedTemplate.content.querySelector('div');
assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument,
'Wrong DIV node owner document');
}, 'Parsing XHTML: Node\'s node document must be set to that of the element '
+ 'to which it will be appended. Test nested templates');
testInIFrame('../resources/template-child-nodes-div.xhtml', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
assert_not_equals(template.content, undefined,
'Content attribute of template element should not be undefined');
assert_not_equals(template.content, null,
'Content attribute of template element should not be null');
var div = template.content.querySelector('div');
assert_equals(template.content.ownerDocument, div.ownerDocument,
'Wrong DIV node owner document');
}, 'Parsing XHTML: Node\'s node document must be set to that of the element '
+ 'to which it will be appended. Test loading XHTML document from a file');
testInIFrame('../resources/template-child-nodes-nested.xhtml', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
var nestedTemplate = template.content.querySelector('template');
assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument,
'Wrong template node owner document');
var div = nestedTemplate.content.querySelector('div');
assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument,
'Wrong DIV node owner document');
}, 'Parsing XHTML: Node\'s node document must be set to that of the element '
+ 'to which it will be appended. Test loading of XHTML document '
+ 'with nested templates from a file');
</script>
</body>
</html>

View file

@ -0,0 +1,103 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: Child nodes of template element in XHTML documents</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="Child nodes of template element in XHTML documents are always appended to the template content (instead of template itself)">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#parsing-xhtml-documents">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function() {
var doc = newXHTMLDocument();
doc.body = doc.createElement('body');
doc.body.innerHTML = '<template id="tmpl1">'
+ '<div id="div1">This is div inside template</div>'
+ '<div id="div2">This is another div inside template</div>'
+ '</template>';
var template = doc.querySelector('#tmpl1');
assert_equals(template.childNodes.length, 0,
'Wrong number of template child nodes');
assert_equals(template.content.childNodes.length, 2,
'Wrong number of template content child nodes');
}, 'Child nodes of template element in XHTML documents must be appended to template content');
test(function() {
var doc = newXHTMLDocument();
doc.body = doc.createElement('body');
doc.body.innerHTML = '<template id="tmpl1">'
+ '<div id="div1">This is div inside template</div>'
+ '<div id="div2">This is another div inside template</div>'
+ '<template id="tmpl2">'
+ '<div id="div3">This is div inside nested template</div>'
+ '<div id="div4">This is another div inside nested template</div>'
+ '</template>' + '</template>';
var template = doc.querySelector('#tmpl1');
assert_equals(template.childNodes.length, 0,
'Wrong number of template child nodes');
assert_equals(template.content.childNodes.length, 3,
'Wrong number of template content child nodes');
var nestedTemplate = template.content.querySelector('#tmpl2');
assert_equals(nestedTemplate.childNodes.length, 0,
'Wrong number of template child nodes');
assert_equals(nestedTemplate.content.childNodes.length, 2,
'Wrong number of nested template content child nodes');
}, 'Child nodes of nested template element in XHTML documents must be appended to template content');
testInIFrame('../resources/template-child-nodes-div.xhtml', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_equals(template.childNodes.length, 0,
'Wrong number of template child nodes');
assert_equals(template.content.querySelectorAll('div').length, 2,
'Wrong number of template content child nodes');
}, 'Child nodes of template element in XHTML documents must be appended to template content. '
+ 'Test loading XHTML document from a file');
testInIFrame('../resources/template-child-nodes-nested.xhtml', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_equals(template.childNodes.length, 0,
'Wrong number of template child nodes');
var nestedTemplate = template.content.querySelector('template');
assert_equals(nestedTemplate.childNodes.length, 0,
'Wrong number of template child nodes');
assert_equals(nestedTemplate.content.querySelectorAll('div').length, 2,
'Wrong number of template content child nodes');
}, 'Child nodes of nested template element in XHTML documents must be appended to template content. '
+ 'Test loading XHTML document from a file');
</script>
</body>
</html>

View file

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: serialize template contents instead of template element</title>
<meta name="author" title="Aleksei Yu. Semenov" href="a.semenov@unipro.ru">
<meta name="assert" content="Template contents should be serialized instead of template element if serializing template element in XHTML document">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#serializing-xhtml-documents">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function () {
var doc = newXHTMLDocument();
var template = doc.createElement('template');
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
template.content.appendChild(div);
assert_equals(template.outerHTML, '<template xmlns="http://www.w3.org/1999/xhtml"><div id="div1">some text</div></template>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element');
test(function () {
var doc = newXHTMLDocument();
var template = doc.createElement('template');
var nestedTemplate = doc.createElement('template');
template.content.appendChild(nestedTemplate);
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
nestedTemplate.content.appendChild(div);
assert_equals(template.outerHTML, '<template xmlns="http://www.w3.org/1999/xhtml"><template><div id="div1">some text</div></template></template>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element. '
+ 'Test nested template');
test(function () {
var doc = newXHTMLDocument();
var template = doc.createElement('template');
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
template.content.appendChild(div);
doc.body = doc.createElement('body');
doc.body.appendChild(template);
assert_equals(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body><template><div id="div1">some text</div></template></body></html>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element. '
+ 'Test serializing whole document');
</script>
</body>
</html>

View file

@ -0,0 +1,6 @@
<!DOCTYPE html>
<title>Template Reftest Reference</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"/>
<body>
<p>Test passes if there's no anything below this line.</p>
</body>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Template Test: check that template content is invisible by default</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#css-additions">
<meta name="assert" content="Test checks that the template contents are hidden implicitly">
<link rel="match" href="css-user-agent-style-sheet-test-001-ref.html">
<body>
<p>Test passes if there's no anything below this line.</p>
<template>
<span style="color:red">Test fails if you can see this text</span>
</template>
</body>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Template Test: check that template content is invisible by default</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#css-additions">
<meta name="assert" content="The template element itself must be hidden by default">
<link rel="match" href="css-user-agent-style-sheet-test-001-ref.html">
<body>
<p>Test passes if there's no anything below this line.</p>
<template style="border: 1px solid; width: 100px; height: 100px">
<span style="color:red">Test fails if you can see this text or border around it</span>
</template>
</body>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>HTML Templates: template content is invisible by default</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#css-additions">
<meta name="assert" content="The template element itself must be hidden by default">
<link rel="match" href="css-user-agent-style-sheet-test-001-ref.html">
<style>
template {
border: 1px solid;
width: 100px;
height: 100px;
}
</style>
<body>
<p>Test passes if there's no anything below this line.</p>
<template>
<span style="color:red">Test fails if you can see this text or border around it</span>
</template>
</body>

View file

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: Clone template node: All the children of template content are copied if 'copy children flag' set to true</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="Clone template node: all the children of template content are copied if 'copy children flag' set to true">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#node-clone-additions">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode(true);
assert_not_equals(copy.content, undefined, 'Template clone content attribute should not be undefined');
assert_not_equals(copy.content, null, 'Template clone content attribute should not be null');
assert_equals(copy.content.childNodes.length, 2,
'Wrong number of template content\'s copy child nodes');
assert_not_equals(copy.content.querySelector('#div1'), null,
'Template child node should be copied');
assert_not_equals(copy.content.querySelector('#div2'), null,
'Template child node should be copied');
}, 'Clone template node. Test call to cloneNode(true)');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode();
assert_not_equals(copy.content, undefined, 'Template clone content attribute should not be undefined');
assert_not_equals(copy.content, null, 'Template clone content attribute should not be null');
assert_equals(copy.content.childNodes.length, 0,
'Wrong number of template content\'s copy child nodes');
}, 'Clone template node. Test call to cloneNode() with the default parameter '
+ '(false by default)');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode(false);
assert_not_equals(copy.content, undefined, 'Template clone content attribute is undefined');
assert_not_equals(copy.content, null, 'Template clone content attribute is null');
assert_equals(copy.content.childNodes.length, 0,
'Wrong number of template content\'s copy child nodes');
}, 'Clone template node. Test call to cloneNode(false)');
</script>
</body>
</html>

View file

@ -0,0 +1,127 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: ownerDocument of cloned template content is set to template content owner</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="ownerDocument of cloned template content is set to template content owner">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#node-clone-additions">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
function checkOwnerDocument(node, doc) {
if ((node !== null) && (node !== undefined)) {
assert_equals(node.ownerDocument, doc,
'Wrong ownerDocument of the template copy\'s node ' + node.nodeName);
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType === Node.ELEMENT_NODE) {
checkOwnerDocument(node.childNodes[i], doc);
if (node.childNodes[i].nodeName === 'TEMPLATE') {
checkOwnerDocument(node.childNodes[i].content, doc);
}
}
}
}
}
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode(true);
assert_equals(copy.content.childNodes.length, 2,
'Wrong number of template content\'s copy child nodes');
checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
+ 'Test cloning with children');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode(false);
assert_equals(copy.content.childNodes.length, 0,
'Wrong number of template content\'s copy child nodes');
checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
+ 'Test cloning without children');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode();
assert_equals(copy.content.childNodes.length, 0,
'Wrong number of template content\'s copy child nodes');
checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
+ 'Test cloneNode() with no arguments (false by default)');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template id="tmpl1">' +
'<div id="div1">This is div inside template</div>' +
'<div id="div2">This is another div inside template</div>' +
'<template id="tmpl2">' +
'<div id="div3">This is div inside nested template</div>' +
'<div id="div4">This is another div inside nested template</div>' +
'</template>' +
'</template>';
var template = doc.querySelector('#tmpl1');
var copy = template.cloneNode(true);
assert_equals(copy.content.childNodes.length, 3,
'Wrong number of template content\'s copy child nodes');
checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
+ 'Test cloning nested template');
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.body.querySelector('template');
var copy = template.cloneNode(true);
checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
+ 'Test loading HTML document from file');
</script>
</body>
</html>

View file

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: The template contents owner document type is HTML document</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="The template contents owner document type is HTML document, if template is declared in HTML document">
<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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a HTML document');
}, 'The template contents owner document type is HTML document ' +
'(case when document has browsing context and the template ' +
'is created by HTML parser)');
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.createElement('template');
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');
}, 'The template contents owner document type is HTML document ' +
'(case when document has browsing context and the template ' +
'is created by createElement())');
test(function() {
var doc = newHTMLDocument();
var template = doc.createElement('template');
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');
}, 'The template contents owner document type is HTML document ' +
'(case when document has no browsing context and the template is created ' +
'by createElement())');
test(function() {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template><div>Hello!</div></template>';
var template = doc.querySelector('template');
assert_class_string(template.content.ownerDocument, 'HTMLDocument',
'Template content owner should be a 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)');
</script>
</body>
</html>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: The template contents owner document (no browsing context)</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="Even if template's enclosing document has no browsing context, it gets its own template contents owner">
<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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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_not_equals(template.content.ownerDocument, doc, 'Wrong template content owner');
}, 'Test the template contents owner document when enclosing document has '
+ 'no browsing content. Template element is created by createElement()');
test(function() {
var doc = newHTMLDocument();
doc.body.innerHTML = '<template><div>some text</div></template>';
var template = doc.querySelector('template');
assert_not_equals(template.content.ownerDocument, doc, 'Wrong template content owner');
}, 'Test the template contents owner document when enclosing document has '
+ 'no browsing content. Template element is created by innerHTML');
</script>
</body>
</html>

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: The template contents owner document (there's browsing context)</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="If template's enclosing document has browsing context, then templates content owner must be a new Document node without browsing context">
<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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
testInIFrame(null, function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.createElement('template');
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerText = 'Some text';
template.appendChild(div);
doc.body.appendChild(template);
// doc has browsing context. There should be another document as a template
// content owner
assert_not_equals(template.content.ownerDocument, doc, 'Wrong template owner document');
}, 'The template contents owner document must be different from template owner document,' +
' which has browsing context. Template element is created by createElement()');
testInIFrame(null, function(context) {
var doc = context.iframes[0].contentDocument;
doc.body.innerHTML = '<template><div>some text</div></template>';
var template = doc.querySelector('template');
// doc has browsing context. There should be another document as a template
// content owner
assert_not_equals(template.content.ownerDocument, doc, 'Wrong template owner document');
}, 'The template contents owner document must be different from template owner document,' +
' which has browsing context. Template element is created via innerHTML');
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
// doc has browsing context. There should be another document as a template
// content owner
assert_not_equals(template.content.ownerDocument, doc, 'Wrong template owner document');
}, 'The template contents owner document must be different from template owner document,' +
' which has browsing context. Template element is created by HTML parser');
</script>
</body>
</html>

View file

@ -0,0 +1,173 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: innerHTML of template element replaces all referenced by the content attribute</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="innerHTML of template element replaces all referenced by the content attribute">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#innerhtml-on-templates">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function () {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var div1 = doc.createElement('div');
div1.setAttribute('id', 'div1');
template.content.appendChild(div1);
assert_not_equals(template.content.querySelector('#div1'), null,
'Element should present in template content');
template.innerHTML = '<div id="div2"></div>';
assert_equals(template.content.querySelector('#div1'), null,
'Template content should be replaced by innerHTML');
assert_not_equals(template.content.querySelector('#div2'), null,
'Element should present in template content');
}, 'innerHTML of template element replaces all referenced by the content attribute');
test(function () {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var nestedTemplate = doc.createElement('template');
template.content.appendChild(nestedTemplate);
var div1 = doc.createElement('div');
div1.setAttribute('id', 'div1');
nestedTemplate.content.appendChild(div1);
assert_not_equals(nestedTemplate.content.querySelector('#div1'), null,
'Element should present in template content');
nestedTemplate.innerHTML = '<div id="div2"></div>';
assert_equals(nestedTemplate.content.querySelector('#div1'), null,
'Template content should be replaced by innerHTML');
assert_not_equals(nestedTemplate.content.querySelector('#div2'), null,
'Element should present in template content');
}, 'innerHTML of template element replaces all referenced by the content attribute. '
+ 'Test nested template');
testInIFrame('../resources/template-contents.html', function(context) {
var doc = context.iframes[0].contentDocument;
var template = doc.querySelector('template');
assert_not_equals(template.content.querySelector('div'), null,
'Div element should present in template content');
template.innerHTML = '<span>span internals</span>';
assert_equals(template.content.querySelector('div'), null,
'div element should be replaced by span in template content');
assert_not_equals(template.content.querySelector('span'), null,
'span element should present in template content');
}, 'innerHTML of template element replaces all referenced by the content attribute. '
+ 'Test loading of HTML document from a file');
</script>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains several &lt;/template&gt; tag in HTML body without start one</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
</template>
<div>The file contains several &lt;/template&gt; tag in HTML body without start one</div>
</template></template>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
</template>
<title>The file contains several &lt;/template&gt; tag in HTML head without start one</title>
</template></template>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</template>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains frameset with the template and frameset end tag in it</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
</head>
<frameset>
<template></frameset></template>
</frameset>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains template element with open div tag, but without end div tag, in the head</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<template>
<div>Hello, template
</template>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains template element with open table, tr, td tags, but without end td, tr, table tags, in the head</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<template>
<table>
<tr>
<td>Hello, cell one!
</template>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html tabindex="5">
<head>
<title>The file contains html root element with attributes and some in the body</title>
<link rel="author" title="Sergey G. Grekhovv" href="mailto:sgrekhov@unipro.ru">
</head>
<body>
<template id="tmpl"><html class="htmlClass"></html></template><html id="htmlId" tabindex="5">
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Template tag with children div tags inside</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"/>
</head>
<body>
<p>Template tag with div tags inside</p>
<template>
<div>This is div inside template</div>
<div>This is another div inside template</div>
</template>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Template tag with children div tags inside another template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"/>
</head>
<body>
<p>Template tag with children div tags inside another template tag</p>
<template>
<template>
<div>This is div inside template</div>
<div>This is another div inside template</div>
</template>
</template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Empty template tag with attribute content</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template content='some text'></template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>BODY tag inside template</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template><body></body></template>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Div tag inside template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
<template>
<div>Hello, template
</template>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Empty template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template>
</template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>FRAMESET tag inside template</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template><frameset></frameset></template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>HEAD tag inside template</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template><head></head></template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML tag inside template</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<head>
<body>
<template><html></html></template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<title>Contains second template tag inside template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<body>
<template>
<template>
<div>Inside nested template</div>
</template>
</template>
</body>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains template element with open table, tr, td tags, without end td, tr, table tags</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
<template>
<table>
<tr>
<td>Hello, cell one!
</template>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Some text inside template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
<template>Some text</template>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Div tag inside template tag</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
<template>
<div>Hello, template</div>
</template>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Div tag inside template tag</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
</head>
<body>
<template>
<div>Hello, template</div>
</template>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Template tag inside frameset</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<frameset>
<template>
<div>Hello, template</div>
</template>
</frameset>
</html>

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Template tag inside head</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<template>
<div>Hello, template</div>
</template>
</head>
<body>
Nothing interesting here
</body>
</html>

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>The file contains two template elements</title>
<link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
</head>
<body>
<template id="template1">
<div>Hello, template</div>
</template>
<template id="template2">
<div>Hello, from second template</div>
</template>
</body>
</html>

View file

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: serialize template contents instead of template element</title>
<meta name="author" title="Aleksei Yu. Semenov" href="a.semenov@unipro.ru">
<meta name="assert" content="template contents should be serialized instead of template element if serializing template element">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#serializing-html-templates">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function () {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
template.content.appendChild(div);
assert_equals(template.outerHTML, '<template><div id="div1">some text</div></template>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element');
test(function () {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var nestedTemplate = doc.createElement('template');
template.content.appendChild(nestedTemplate);
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
nestedTemplate.content.appendChild(div);
assert_equals(template.outerHTML, '<template><template><div id="div1">some text</div></template></template>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element. '
+ 'Test nested template');
test(function () {
var doc = newHTMLDocument();
var template = doc.createElement('template');
var div = doc.createElement('div');
div.setAttribute('id', 'div1');
div.innerHTML = 'some text';
template.content.appendChild(div);
doc.body.appendChild(template);
assert_equals(doc.documentElement.outerHTML, '<html><head><title>Test Document</title></head><body><template><div id="div1">some text</div></template></body></html>',
'template element is serialized incorrectly');
}, 'Template contents should be serialized instead of template element if serializing template element. '
+ 'Test serializing whole document');
</script>
</body>
</html>

View file

@ -0,0 +1,115 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,200 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,115 @@
<!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="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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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 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 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 FRAMESET element. ' +
'Template element is created by innerHTML',
frameset]
];
generate_tests(templateIsAChild, parameters,
'Template element as a descendant of the HEAD, BODY and FRAMESET elements');
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 FRAMESET element. ' +
'Template element is created by innerHTML',
frameset]
];
generate_tests(templateIsAnIndirectChild, parameters,
'Template element as an indirect descendant of the HEAD, BODY and FRAMESET elements');
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]
];
generate_tests(templateIsAnAppendedChild, parameters,
'Template element as a descendant of the HEAD, BODY and FRAMESET elements');
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]
];
generate_tests(templateIsAnAppendedIndirectChild, parameters,
'Template element as a descendant of the HEAD, BODY and FRAMESET elements');
</script>
</body>
</html>

View file

@ -0,0 +1,60 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,78 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
var parameters = [];
HTML5_ELEMENTS.forEach(function(value) {
if (value !== 'body' && value !== 'html' && value !== 'head' && value !== 'frameset') {
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);
parameters.push([
'Template may contain ' + value + ' element',
valueToTest,
null
]);
}
});
generate_tests(assert_not_equals, parameters,
'Template may contain any element, except the html element, '
+ 'the head element, the body element, or the frameset element');
var parameters = [];
HTML5_ELEMENTS.forEach(function(value) {
if (value !== 'body' && value !== 'html' && value !== 'head' && value !== 'frameset') {
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);
parameters.push([
'Template may contain ' + value + ' element. '
+'The template element and contents are added via body.innerHTML',
element,
null
]);
}
});
generate_tests(assert_not_equals, parameters,
'Template may contain any element, except the html element, '
+ 'the head element, the body element, or the frameset element. '
+'The template element and contents are added via body.innerHTML');
</script>
</body>
</html>

View file

@ -0,0 +1,27 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,63 @@
<!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 be a descendant of 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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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_not_equals(frameset.querySelector('template'), null,
'Template element should 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_not_equals(frameset.querySelector('template'), null,
'Template element should 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, 2,
'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>

View file

@ -0,0 +1,27 @@
<!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='../testcommon.js'></script>
<link rel="stylesheet" href="/resources/testharness.css">
</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>

View file

@ -0,0 +1,191 @@
/*
Distributed under both the W3C Test Suite License [1] and the W3C
3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
policies and contribution forms [3].
[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
[3] http://www.w3.org/2004/10/27-testcases
*/
"use strict";
var HTML5_ELEMENTS = [ 'a', 'abbr', 'address', 'area', 'article', 'aside',
'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br',
'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup',
'command', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div',
'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure',
'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header',
'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd',
'keygen', 'label', 'legend', 'li', 'link', 'map', 'mark', 'menu',
'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup',
'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rp', 'rt',
'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source',
'span', 'strong', 'style', 'sub', 'table', 'tbody', 'td', 'textarea',
'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul',
'var', 'video', 'wbr' ];
// only void (without end tag) HTML5 elements
var HTML5_VOID_ELEMENTS = [ 'area', 'base', 'br', 'col', 'command', 'embed',
'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source',
'track', 'wbr' ];
// https://html.spec.whatwg.org/multipage/multipage/forms.html#form-associated-element
var HTML5_FORM_ASSOCIATED_ELEMENTS = [ 'button', 'fieldset', 'input', 'keygen',
'label', 'object', 'output', 'select', 'textarea' ];
function newDocument() {
var d = document.implementation.createDocument();
return d;
}
function newHTMLDocument() {
var d = document.implementation.createHTMLDocument('Test Document');
return d;
}
function newXHTMLDocument() {
var doctype = document.implementation.createDocumentType('html',
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd');
var d = document.implementation.createDocument(
'http://www.w3.org/1999/xhtml', 'html', doctype);
return d;
}
function newIFrame(context, src) {
if (typeof (context) === 'undefined'
|| typeof (context.iframes) !== 'object') {
assert_unreached('Illegal context object in newIFrame');
}
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
if (typeof (src) != 'undefined') {
iframe.src = src;
}
document.body.appendChild(iframe);
context.iframes.push(iframe);
assert_true(typeof (iframe.contentWindow) != 'undefined'
&& typeof (iframe.contentWindow.document) != 'undefined'
&& iframe.contentWindow.document != document,
'Failed to create new rendered document');
return iframe;
}
function newRenderedHTMLDocument(context) {
var frame = newIFrame(context);
var d = frame.contentWindow.document;
return d;
}
function newContext() {
return {
iframes : []
};
}
function cleanContext(context) {
context.iframes.forEach(function(e) {
e.parentNode.removeChild(e);
});
}
// run given test function in context
// the context is cleaned up after test completes.
function inContext(f) {
return function() {
var context = newContext();
try {
f(context);
} finally {
cleanContext(context);
}
};
}
// new context and iframe are created and url (if supplied) is asigned to
// iframe.src
// function f is bound to the iframe onload event or executed directly after
// iframe creation
// the context is passed to function as argument
function testInIFrame(url, f, testName, testProps) {
if (url) {
var t = async_test(testName, testProps);
t.step(function() {
var context = newContext();
var iframe = newIFrame(context, url);
iframe.onload = t.step_func(function() {
try {
f(context);
t.done();
} finally {
cleanContext(context);
}
});
});
} else {
test(inContext(function(context) {
newRenderedHTMLDocument(context);
f(context);
}), testName, testProps);
}
}
function assert_nodelist_contents_equal_noorder(actual, expected, message) {
assert_equals(actual.length, expected.length, message);
var used = [];
for ( var i = 0; i < expected.length; i++) {
used.push(false);
}
for (i = 0; i < expected.length; i++) {
var found = false;
for ( var j = 0; j < actual.length; j++) {
if (used[j] == false && expected[i] == actual[j]) {
used[j] = true;
found = true;
break;
}
}
if (!found) {
assert_unreached(message + ". Fail reason: element not found: "
+ expected[i]);
}
}
}
function isVisible(el) {
return el.offsetTop != 0;
}
function isVoidElement(elementName) {
return HTML5_VOID_ELEMENTS.indexOf(elementName) >= 0;
}
function checkTemplateContent(d, obj, html, id, nodeName) {
obj.innerHTML = '<template id="tmpl">' + html + '</template>';
var t = d.querySelector('#tmpl');
if (id != null) {
assert_equals(t.content.childNodes.length, 1, 'Element ' + nodeName
+ ' should present among template nodes');
assert_equals(t.content.firstChild.id, id, 'Wrong element ID');
}
if (nodeName != null) {
assert_equals(t.content.firstChild.nodeName, nodeName.toUpperCase(),
'Wrong node name');
}
}
function checkBodyTemplateContent(d, html, id, nodeName) {
checkTemplateContent(d, d.body, html, id, nodeName);
}
function checkHeadTemplateContent(d, html, id, nodeName) {
checkTemplateContent(d, d.head, html, id, nodeName);
}