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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<html>
<head>
<style type="text/css">
.pass { color: green; }
.fail { color: red; }
</style>
<style type="text/css">
.foo { color: black; }
@media screen {
.bar { color: blue; }
}
@keyframes name { }
@page { }
</style>
<!-- @charset must be the first rule per spec, and additionally
with no leading whitespace per our parser. -->
<style>@charset "UTF-8";</style>
<script>
function printOut(msg) {
var console = document.getElementById("console");
var span = document.createElement('span');
span.innerHTML = msg + '<br>';
console.appendChild(span);
}
function resultStringifier(result)
{
if (result === "")
return "<b>the empty string</b>";
else if (result === undefined)
return "<b>undefined</b>";
else if (result === null)
return "<b>null</b>";
return "the string '" + result + "'";
}
function nullTestElementAttribute(elementType, element, attr, expected)
{
element[attr] = null;
var result;
if (element[attr] === expected)
result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
else
result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
result += " [tested " + elementType + "." + attr + "]";
printOut(result);
}
function runTests() {
if (window.testRunner)
testRunner.dumpAsText();
var rules = document.styleSheets[1].cssRules;
var rule = rules[0];
var mediaRule = rules[1];
var keyframesRule = rules[2];
var pageRule = rules[3];
var charsetRule = document.styleSheets[2].cssRules[0];
var style = rule.style;
var mediaList = mediaRule.media;
var listing = [
{
type: 'CSSRule',
elementToUse: rule,
attributes: [
// 'null' is not a valid rule, so the setter does nothing.
{name: 'cssText', expectedNull: '.foo { color: black; }'}
]
},
{
type: 'CSSCharsetRule',
elementToUse: charsetRule,
attributes: [
{name: 'encoding', expectedNull: 'null'}
]
},
{
type: 'CSSKeyframesRule',
elementToUse: keyframesRule,
attributes: [
{name: 'name', expectedNull: 'null'}
]
},
{
type: 'CSSPageRule',
elementToUse: pageRule,
attributes: [
{name: 'selectorText', expectedNull: '@page null'}
]
},
{
type: 'CSSStyleRule',
elementToUse: rule,
attributes: [
{name: 'selectorText', expectedNull: 'null'}
]
},
{
type: 'CSSStyleDeclaration',
elementToUse: style,
attributes: [
// cssText detects syntax errors, such as JS null, and sets the value to the empty string.
{name: 'cssText', expectedNull: ''}
]
},
{
type: 'MediaList',
elementToUse: mediaList,
attributes: [
{name: 'mediaText', expectedNull: ''}
]
}
];
for (element in listing) {
var type = listing[element].type;
var elementToUse = listing[element].elementToUse;
var attrs = listing[element].attributes;
for (attr in attrs) {
nullTestElementAttribute(type, elementToUse, attrs[attr].name, attrs[attr].expectedNull);
}
printOut('');
}
}
</script>
</head>
<body onload="runTests()">
<p>This test setting various attributes of a CSSOM elements to JavaScript null.</p>
<div id="console"></div>
</body>
</html>
|