3 <style type=
"text/css">
4 .pass { color: green
; }
7 <style type=
"text/css">
16 function printOut(msg
) {
17 var console
= document
.getElementById("console");
18 var span
= document
.createElement('span');
19 span
.innerHTML
= msg
+ '<br>';
20 console
.appendChild(span
);
23 function resultStringifier(result
)
26 return "<b>the empty string</b>";
27 else if (result
=== undefined)
28 return "<b>undefined</b>";
29 else if (result
=== null)
31 return "the string '" + result
+ "'";
34 function nullTestElementAttribute(elementType
, element
, attr
, expected
)
39 if (element
[attr
] === expected
)
40 result
= "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected
) + ".";
42 result
= "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected
) + " but was " + resultStringifier(element
[attr
]) + ".";
44 result
+= " [tested " + elementType
+ "." + attr
+ "]";
49 if (window
.testRunner
)
50 testRunner
.dumpAsText();
52 var rules
= document
.styleSheets
[1].cssRules
;
55 var mediaRule
= rules
[1];
56 var keyframesRule
= rules
[2];
57 var pageRule
= rules
[3];
58 var style
= rule
.style
;
59 var mediaList
= mediaRule
.media
;
66 // 'null' is not a valid rule, so the setter does nothing.
67 {name
: 'cssText', expectedNull
: '.foo { color: black; }'}
71 type
: 'CSSKeyframesRule',
72 elementToUse
: keyframesRule
,
74 {name
: 'name', expectedNull
: 'null'}
79 elementToUse
: pageRule
,
81 {name
: 'selectorText', expectedNull
: '@page null'}
88 {name
: 'selectorText', expectedNull
: 'null'}
92 type
: 'CSSStyleDeclaration',
95 // cssText detects syntax errors, such as JS null, and sets the value to the empty string.
96 {name
: 'cssText', expectedNull
: ''}
101 elementToUse
: mediaList
,
103 {name
: 'mediaText', expectedNull
: ''}
108 for (element
in listing
) {
109 var type
= listing
[element
].type
;
110 var elementToUse
= listing
[element
].elementToUse
;
111 var attrs
= listing
[element
].attributes
;
112 for (attr
in attrs
) {
113 nullTestElementAttribute(type
, elementToUse
, attrs
[attr
].name
, attrs
[attr
].expectedNull
);
120 <body onload=
"runTests()">
121 <p>This test setting various attributes of a CSSOM elements to JavaScript null.
</p>
122 <div id=
"console"></div>