servo/tests/wpt/css-tests/cssom-1_dev/xhtml1/ttwf-cssom-doc-ext-load-count.xht

68 lines
No EOL
3.1 KiB
HTML

<!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>CSSOM - Extensions to the Document Interface: StyleSheetList length reflects dynamically loaded and unloaded sheets</title>
<link href="mailto:jesse@codeforamerica.org" rel="author" title="Jesse Bounds" />
<link href="http://www.w3.org/TR/cssom-1/#extensions-to-the-document-interface" rel="help" />
<link href="http://www.w3.org/TR/cssom-1/#the-stylesheetlist-interface" rel="help" />
<link href="http://www.w3.org/TR/cssom-1/#css-style-sheet-collections" rel="help" />
<link href="stylesheet.css" type="text/css" rel="stylesheet" />
<meta content="dom" name="flags" />
<meta content="The styleSheets length attribute must reflect the number of sheets at page load and after dynamically" name="assert" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script id="metadata_cache">/*
{
"stylesheet.css should be loaded and styleSheets.length === 1": {},
"stylesheet.css should be unloaded and styleSheets.length === 0": {},
"stylesheet-1.css should be loaded and styleSheets.length === 1": {}
}
*/</script>
</head>
<body>
<div id="log"></div>
<script>
// Get the Document's styleSheets attribute
var styleSheets = document.styleSheets;
// Verify that the styleSheets list length is 1 due to "stylesheet.css" loaded in head section
test(function() {
assert_equals(styleSheets.length, 1, "styleSheets.length is incorrect:");
}, "stylesheet.css should be loaded and styleSheets.length === 1");
// Verify that the styleSheets list length is 0 after removing the loaded sheet from the DOM
test(function() {
// get the one and only sheet loaded
var sheet = styleSheets.item(0);
// remove the sheet from the DOM
sheet.ownerNode.parentNode.removeChild(sheet.ownerNode)
// assert that there are 0 styleSheets in the styleSheets property
assert_equals(styleSheets.length, 0, "styleSheets.length is incorrect:");
}, "stylesheet.css should be unloaded and styleSheets.length === 0");
// Verify that the styleSheets list length is back to 1 after loading a new sheet
test(function() {
// create a css file reference
var fileReference = document.createElement("link");
fileReference.setAttribute("rel", "stylesheet");
fileReference.setAttribute("type", "text/css");
fileReference.setAttribute("href", "stylesheet-1.css");
// load the css file reference into the head section
var head = document.getElementsByTagName("HEAD")[0];
head.appendChild(fileReference);
// assert that there is 1 styleSheet in the styleSheets property
assert_equals(styleSheets.length, 1, "styleSheets.length is incorrect:");
}, "stylesheet-1.css should be loaded and styleSheets.length === 1");
</script>
</body></html>