blob: 5c2b9e6f46027d6d01a2a74fe00cd27b820189ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<!DOCTYPE html>
<html>
<head>
<title>CSSOM - Extensions to the Document Interface: StyleSheetList length reflects dynamically loaded and unloaded sheets</title>
<link rel="author" title="Jesse Bounds" href="mailto:jesse@codeforamerica.org">
<link rel="help" href="http://www.w3.org/TR/cssom-1/#extensions-to-the-document-interface">
<link rel="help" href="http://www.w3.org/TR/cssom-1/#the-stylesheetlist-interface">
<link rel="help" href="http://www.w3.org/TR/cssom-1/#css-style-sheet-collections">
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<meta name="flags" content="dom">
<meta name="assert" content="The styleSheets length attribute must reflect the number of sheets at page load and after dynamically">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></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
async_test(function(t) {
// 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");
fileReference.onerror = t.step_func_done(function() {
// assert that there is 1 styleSheet in the styleSheets property
assert_equals(styleSheets.length, 1, "styleSheets.length is incorrect:");
});
// load the css file reference into the head section
var head = document.getElementsByTagName("HEAD")[0];
head.appendChild(fileReference);
}, "stylesheet-1.css should be loaded and styleSheets.length === 1");
</script>
</body>
</html>
|