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
=== null)
22 else if (result
=== undefined)
23 return "<b>undefined</b>";
24 return "the string '" + result
+ "'";
27 function nullTestDocumentAttribute(documentType
, doc
, attr
, expected
, expectedExceptionCode
)
32 if (expectedExceptionCode
!= undefined)
33 result
= "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode
+ " but threw nothing.";
34 else if (doc
[attr
] === expected
)
35 result
= "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected
) + ".";
37 result
= "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected
) + " but was " + resultStringifier(doc
[attr
]) + ".";
40 if (ex
.code
== expectedExceptionCode
)
41 result
= "<span class='pass'>TEST SUCCEEDED:</span> Got the expected exception (" + ex
.code
+ ").";
43 result
= "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode
+ " but threw " + ex
.code
+ ".";
46 result
+= " [tested " + documentType
+ "." + attr
+ "]";
52 if (window
.testRunner
)
53 testRunner
.dumpAsText();
58 var xmlDoc
= document
.implementation
.createDocument(null, null, null);
59 var htmlDoc
= document
.implementation
.createHTMLDocument('A Title');
60 htmlDoc
.body
= htmlDoc
.createElement('body');
67 {name
: 'xmlVersion', expectedExceptionCode
: 9},
68 {name
: 'documentURI', expectedNull
: null},
69 {name
: 'charset', expectedNull
: 'UTF-8'},
70 {name
: 'defaultCharset', expectedNull
: undefined},
71 {name
: 'characterSet', expectedNull
: 'UTF-8'},
72 {name
: 'inputEncoding', expectedNull
: 'UTF-8'},
73 {name
: 'selectedStylesheetSet', expectedNull
: null}
77 typeName
: 'HTMLDocument',
80 {name
: 'title', expectedNull
: ''},
81 {name
: 'cookie', expectedNull
: ''},
82 {name
: 'bgColor', expectedNull
: ''},
83 {name
: 'fgColor', expectedNull
: ''},
84 {name
: 'alinkColor', expectedNull
: ''},
85 {name
: 'linkColor', expectedNull
: ''},
86 {name
: 'vlinkColor', expectedNull
: ''},
87 {name
: 'dir', expectedNull
: ''},
88 {name
: 'designMode', expectedNull
: 'off'}
93 for (doc
in listing
) {
94 var typeName
= listing
[doc
].typeName
;
95 var docToUse
= listing
[doc
].docToUse
;
96 var attrs
= listing
[doc
].attributes
;
98 nullTestDocumentAttribute(typeName
, docToUse
, attrs
[attr
].name
, attrs
[attr
].expectedNull
, attrs
[attr
].expectedExceptionCode
);
105 <body onload=
"runTests()">
106 <p>This test setting various attributes of documents to JavaScript null.
</p>
107 <div id=
"console"></div>