blob: f9c23a3eaf515af14742b8e2e0b23b1f171007d9 [file] [log] [blame]
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<div id="element" name="element_name"></div>
<script>
description('This test checks that all but a handful of dom constructors throw exceptions, and the rest return reasonable objects. It also tests that those constructors have higher precedence than a document element with the same ID or name.');
var element = document.getElementById("element");
// These objects should throw an exception when their constructor is called
// with no arguments. (Some of them may have working constructors that require
// arguments to be valid.)
var objects_exception = [
'Attr', 'CharacterData', 'CDATASection', 'Comment', 'Document',
'DocumentFragment', 'DocumentType', 'Element', 'Entity',
'EntityReference', 'HTMLDocument', 'Node', 'Notation',
'ProcessingInstruction', 'Text', 'HTMLAnchorElement',
'HTMLAppletElement', 'HTMLAreaElement', 'HTMLBaseElement',
'HTMLBaseFontElement', 'HTMLBlockquoteElement', 'HTMLBodyElement',
'HTMLBRElement', 'HTMLButtonElement', 'HTMLCanvasElement',
'HTMLDirectoryElement', 'HTMLDivElement', 'HTMLDListElement',
'HTMLEmbedElement', 'HTMLFieldSetElement', 'HTMLFontElement',
'HTMLFormElement', 'HTMLFrameElement', 'HTMLFrameSetElement',
'HTMLHeadingElement', 'HTMLHeadElement', 'HTMLHRElement',
'HTMLHtmlElement', 'HTMLIFrameElement', 'HTMLImageElement',
'HTMLInputElement', 'HTMLIsIndexElement', 'HTMLLabelElement',
'HTMLLegendElement', 'HTMLLIElement', 'HTMLLinkElement',
'HTMLMapElement', 'HTMLMarqueeElement', 'HTMLMenuElement',
'HTMLMetaElement', 'HTMLModElement', 'HTMLObjectElement',
'HTMLOListElement', 'HTMLOptGroupElement', 'HTMLOptionElement',
'HTMLParagraphElement', 'HTMLParamElement', 'HTMLPreElement',
'HTMLQuoteElement', 'HTMLScriptElement', 'HTMLSelectElement',
'HTMLStyleElement', 'HTMLTableCaptionElement',
'HTMLTableColElement', 'HTMLTableElement',
'HTMLTableSectionElement', 'HTMLTableCellElement',
'HTMLTableRowElement', 'HTMLTextAreaElement', 'HTMLTitleElement',
'HTMLUListElement', 'HTMLElement', 'CanvasRenderingContext2D',
'Clipboard', 'Counter', 'CSSCharsetRule', 'CSSFontFaceRule',
'CSSImportRule', 'CSSMediaRule', 'CSSPageRule',
'CSSPrimitiveValue', 'CSSRule', 'CSSRuleList',
'CSSStyleDeclaration', 'CSSStyleRule', 'CSSStyleSheet',
'CSSValue', 'CSSValueList', 'DOMImplementation', 'Event',
'HTMLCollection', 'KeyboardEvent', 'MediaList', 'MimeType',
'MimeTypeArray', 'MouseEvent', 'MutationEvent', 'NamedNodeMap',
'NodeFilter', 'NodeList', 'OverflowEvent', 'Plugin',
'PluginArray', 'Range', 'Rect', 'StyleSheet', 'StyleSheetList',
'TextEvent', 'UIEvent', 'WheelEvent', 'XPathResult', 'BarInfo',
'CanvasGradient', 'CanvasPattern', 'Console', 'DOMSelection',
'DOMWindow', 'History', 'HTMLOptionsCollection', 'Location',
'Navigator', 'NodeIterator', 'RGBColor', 'Screen', 'TreeWalker',
'XPathExpression', 'Worker'
];
// These objects should have a working constructor.
var objects_constructor = [
'DOMParser', 'XMLHttpRequest', 'XMLSerializer', 'XPathEvaluator',
'XSLTProcessor'
];
// These objects should have no constructor.
var objects_no_constructor = [
'EventTargetNode', 'UndetectableHTMLCollection',
'XPathNSResolver', 'EventTarget', 'EventListener', 'NPObject',
'HTMLAllCollection'
];
// These objects should have a working constructor, but their constructed
// object names differ. This is therefore a map from constructor name to
// constructed object.
var objects_different_constructor = {
'Audio': 'HTMLAudioElement',
'Option': 'HTMLOptionElement',
'Image': 'HTMLImageElement'
}
function TryAllocate(node) {
var Cons = this[node];
if (!Cons) return 'no constructor';
try { return new Cons() + ''; }
catch (e) { return 'exception'; }
}
function check(name, expected) {
actual = TryAllocate(node);
if (actual == expected) {
document.write("PASS: " + name + " '" + expected + "'<br>");
} else {
document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
actual + "'<br>");
}
}
for (var i = 0; i < objects_exception.length; i++) {
var obj = objects_exception[i];
shouldBe("TryAllocate('" + obj + "')", "'exception'");
}
for (var i = 0; i < objects_no_constructor.length; i++) {
var obj = objects_no_constructor[i];
shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
}
for (var i = 0; i < objects_constructor.length; i++) {
var obj = objects_constructor[i];
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.id = obj;
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.id = "element";
element.name = obj;
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.name = "element_name";
}
for (var obj in objects_different_constructor) {
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.id = obj;
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.id = "element";
element.name = obj;
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.name = "element_name";
}
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>