2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / fast / dom / global-constructors.html
blob523c63fd7a55228c31ce041514b500806667fdbe
1 <html>
2 <head>
3 <style>
4 * {
5 color: black;
7 </style>
8 <script>
9 function print(message, color)
11 var paragraph = document.createElement("div");
12 paragraph.appendChild(document.createTextNode(message));
13 paragraph.style.fontFamily = "monospace";
14 if (color)
15 paragraph.style.color = color;
16 document.getElementById("console").appendChild(paragraph);
19 function shouldBe(a, b)
21 var evalA;
22 try {
23 evalA = eval(a);
24 } catch(e) {
25 evalA = e;
27 if (evalA == b)
28 print("PASS: " + a + " should be " + b + " and is.", "green");
29 else
30 print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
33 function test()
35 if (window.layoutTestController)
36 layoutTestController.dumpAsText();
38 domParser = new DOMParser();
39 shouldBe("DOMParser.prototype.isPrototypeOf(domParser)", true);
41 xmlHttpRequest = new XMLHttpRequest();
42 shouldBe("XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest)", true);
44 xmlSerializer = new XMLSerializer();
45 shouldBe("XMLSerializer.prototype.isPrototypeOf(xmlSerializer)", true);
47 xsltProcessor = new XSLTProcessor();
48 shouldBe("XSLTProcessor.prototype.isPrototypeOf(xsltProcessor)", true);
50 shouldBe("window.Document.prototype.isPrototypeOf(document)", true);
51 shouldBe("window.HTMLDocument.prototype.isPrototypeOf(document)", true);
53 element = document.body;
54 shouldBe("window.Node.prototype.isPrototypeOf(element)", true);
55 shouldBe("window.Element.prototype.isPrototypeOf(element)", true);
56 shouldBe("window.HTMLElement.prototype.isPrototypeOf(element)", true);
58 range = document.createRange();
59 shouldBe("window.Range.prototype.isPrototypeOf(range)", true);
61 cssRule = document.styleSheets[0].cssRules[0];
62 shouldBe("window.CSSRule.prototype.isPrototypeOf(cssRule)", true);
64 cssPrimitiveValue = cssRule.style.getPropertyCSSValue("color");
65 shouldBe("window.CSSValue.prototype.isPrototypeOf(cssPrimitiveValue)", true);
66 shouldBe("window.CSSPrimitiveValue.prototype.isPrototypeOf(cssPrimitiveValue)", true);
68 cssStyleDeclaration = cssRule.style;
69 shouldBe("window.CSSStyleDeclaration.prototype.isPrototypeOf(cssStyleDeclaration)", true);
71 event = document.createEvent("MutationEvents");
72 shouldBe("window.Event.prototype.isPrototypeOf(event)", true);
73 shouldBe("window.MutationEvent.prototype.isPrototypeOf(event)", true);
75 xmldoc = document.implementation.createDocument(null, null, null);
76 shouldBe("window.XMLDocument.prototype.isPrototypeOf(xmldoc)", true);
78 fragment = document.createDocumentFragment();
79 shouldBe("window.DocumentFragment.prototype.isPrototypeOf(fragment)", true);
81 xpathevaluator = new XPathEvaluator();
82 shouldBe("window.XPathEvaluator.prototype.isPrototypeOf(xpathevaluator)", true);
84 xpathresult = xpathevaluator.evaluate('/', document, null, 0, null);
85 shouldBe("window.XPathResult.prototype.isPrototypeOf(xpathresult)", true);
87 try {
88 nodeFilter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, function () {}, false).filter;
89 } catch(e) {}
90 shouldBe("window.NodeFilter.prototype.isPrototypeOf(nodeFilter)", true);
92 delete window.Node.prototype;
93 print("[Deleted window.Node.prototype]");
94 shouldBe("window.Node.prototype", undefined);
96 originalNodeConstructor = window.Node;
98 // Shadow window.Node
99 window.Node = 1;
100 print("[Set window.Node = 1]");
101 shouldBe("window.Node", 1);
103 // Unshadow window.Node
104 delete window.Node;
105 print("[Deleted window.Node]");
106 shouldBe("window.Node", originalNodeConstructor);
108 // Attempt to shadow window.Node with a frame named 'Node'
109 var iframe = document.createElement('iframe');
110 iframe.setAttribute('name', "Node");
111 document.body.appendChild(iframe);
112 print("[Added an iframe named 'Node']");
113 shouldBe("window.Node", originalNodeConstructor);
116 </script>
117 </head>
119 <body onload="test();">
120 <p>This page tests global constructor objects like window.HTMLDocument. If it passes, you'll
121 see a series of 'PASS' messages below.
122 </p>
123 <hr>
124 <div id='console'></div>
126 </body>
127 </html>