3 <style type=
"text/css">
4 .pass { color: green
; }
10 var console
= document
.getElementById("console");
11 var span
= document
.createElement('span');
12 span
.innerHTML
= msg
+ '<br>';
13 console
.appendChild(span
);
16 function resultStringifier(result
)
19 return "<b>the empty string</b>";
20 else if (result
=== undefined)
21 return "<b>undefined</b>";
22 else if (result
=== null)
24 return "the string '" + result
+ "'";
27 function nullTestElementAttribute(elementType
, element
, attr
, expected
)
32 if (element
[attr
] === expected
)
33 result
= "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected
) + ".";
35 result
= "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected
) + " but was " + resultStringifier(element
[attr
]) + ".";
37 result
+= " [tested " + elementType
+ "." + attr
+ "]";
43 if (window
.testRunner
)
44 testRunner
.dumpAsText();
46 var canvas
= document
.createElement('canvas');
47 var context
= canvas
.getContext("2d");
51 type
: 'CanvasRenderingContext2D',
52 elementToUse
: context
,
54 {name
: 'globalCompositeOperation', expectedNull
: 'source-over'},
55 {name
: 'lineCap', expectedNull
: 'butt'},
56 {name
: 'lineJoin', expectedNull
: 'miter'},
57 {name
: 'shadowColor', expectedNull
: 'rgba(0, 0, 0, 0)'}
62 for (element
in listing
) {
63 var type
= listing
[element
].type
;
64 var elementToUse
= listing
[element
].elementToUse
;
65 var attrs
= listing
[element
].attributes
;
67 nullTestElementAttribute(type
, elementToUse
, attrs
[attr
].name
, attrs
[attr
].expectedNull
);
74 <body onload=
"runTests()">
75 <p>This test setting various attributes of a CanvasRenderingContext2D to JavaScript null.
</p>
76 <div id=
"console"></div>