| <html> |
| <head> |
| <style type="text/css"> |
| .pass { color: green; } |
| .fail { color: red; } |
| </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 === null) |
| return "<b>null</b>"; |
| else if (result === undefined) |
| return "<b>undefined</b>"; |
| return "the string '" + result + "'"; |
| } |
| |
| function nullTestDocumentAttribute(documentType, doc, attr, expected, expectedExceptionCode) |
| { |
| var result; |
| try { |
| doc[attr] = null; |
| if (expectedExceptionCode != undefined) |
| result = "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode + " but threw nothing."; |
| else if (doc[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(doc[attr]) + "."; |
| |
| } catch (ex) { |
| if (ex.code == expectedExceptionCode) |
| result = "<span class='pass'>TEST SUCCEEDED:</span> Got the expected exception (" + ex.code + ")."; |
| else |
| result = "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode + " but threw " + ex.code + "."; |
| } |
| |
| result += " [tested " + documentType + "." + attr + "]"; |
| printOut(result); |
| } |
| |
| function runTests() |
| { |
| if (window.testRunner) |
| testRunner.dumpAsText(); |
| |
| // Others to test: |
| // Functions |
| |
| var xmlDoc = document.implementation.createDocument(null, null, null); |
| var htmlDoc = document.implementation.createHTMLDocument('A Title'); |
| htmlDoc.body = htmlDoc.createElement('body'); |
| |
| var listing = [ |
| { |
| typeName: 'Document', |
| docToUse: xmlDoc, |
| attributes: [ |
| {name: 'xmlVersion', expectedExceptionCode: 9} |
| ] |
| }, |
| { |
| typeName: 'HTMLDocument', |
| docToUse: htmlDoc, |
| attributes: [ |
| {name: 'title', expectedNull: 'null'}, |
| {name: 'cookie', expectedNull: ''}, |
| {name: 'bgColor', expectedNull: ''}, |
| {name: 'fgColor', expectedNull: ''}, |
| {name: 'alinkColor', expectedNull: ''}, |
| {name: 'linkColor', expectedNull: ''}, |
| {name: 'vlinkColor', expectedNull: ''}, |
| {name: 'dir', expectedNull: ''}, |
| {name: 'designMode', expectedNull: 'off'} |
| ] |
| } |
| ]; |
| |
| for (doc in listing) { |
| var typeName = listing[doc].typeName; |
| var docToUse = listing[doc].docToUse; |
| var attrs = listing[doc].attributes; |
| for (attr in attrs) { |
| nullTestDocumentAttribute(typeName, docToUse, attrs[attr].name, attrs[attr].expectedNull, attrs[attr].expectedExceptionCode); |
| } |
| printOut(''); |
| } |
| } |
| </script> |
| </head> |
| <body onload="runTests()"> |
| <p>This test setting various attributes of documents to JavaScript null.</p> |
| <div id="console"></div> |
| </body> |
| </html> |