Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / global-constructors.html
1 <html>
2 <head>
3 <style>
4   * {
5     color: black;
6   }
7 </style>
8 <script>
9 function print(message, color) 
10 {
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);
17 }
18
19 function shouldBe(a, b)
20 {
21     var evalA;
22     try {
23         evalA = eval(a);
24     } catch(e) {
25         evalA = e;
26     }
27     if (evalA != b)
28         print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
29 }
30
31 function test() 
32 {
33     if (window.testRunner)
34         testRunner.dumpAsText();
35
36     domParser = new DOMParser();
37     shouldBe("DOMParser.prototype.isPrototypeOf(domParser)", true);
38     
39     xmlHttpRequest = new XMLHttpRequest();
40     shouldBe("XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest)", true);
41     
42     xmlSerializer = new XMLSerializer();
43     shouldBe("XMLSerializer.prototype.isPrototypeOf(xmlSerializer)", true);
44     
45     xsltProcessor = new XSLTProcessor();
46     shouldBe("XSLTProcessor.prototype.isPrototypeOf(xsltProcessor)", true);
47
48     shouldBe("window.Document.prototype.isPrototypeOf(document)", true);
49     shouldBe("window.HTMLDocument.prototype.isPrototypeOf(document)", true);
50     
51     element = document.body;
52     shouldBe("window.Node.prototype.isPrototypeOf(element)", true);
53     shouldBe("window.Element.prototype.isPrototypeOf(element)", true);
54     shouldBe("window.HTMLElement.prototype.isPrototypeOf(element)", true);
55     
56     range = document.createRange();
57     shouldBe("window.Range.prototype.isPrototypeOf(range)", true);
58     
59     cssRule = document.styleSheets[0].cssRules[0];
60     shouldBe("window.CSSRule.prototype.isPrototypeOf(cssRule)", true);
61     
62     cssPrimitiveValue = cssRule.style.getPropertyCSSValue("color");
63     shouldBe("window.CSSValue.prototype.isPrototypeOf(cssPrimitiveValue)", true);
64     shouldBe("window.CSSPrimitiveValue.prototype.isPrototypeOf(cssPrimitiveValue)", true);
65
66     cssStyleDeclaration = cssRule.style;
67     shouldBe("window.CSSStyleDeclaration.prototype.isPrototypeOf(cssStyleDeclaration)", true);
68
69     event = document.createEvent("MutationEvents");
70     shouldBe("window.Event.prototype.isPrototypeOf(event)", true);
71     shouldBe("window.MutationEvent.prototype.isPrototypeOf(event)", true);
72
73     xmldoc = document.implementation.createDocument(null, null, null);
74     shouldBe("window.XMLDocument.prototype.isPrototypeOf(xmldoc)", true);
75     
76     fragment = document.createDocumentFragment();
77     shouldBe("window.DocumentFragment.prototype.isPrototypeOf(fragment)", true);
78     
79     xpathevaluator = new XPathEvaluator();
80     shouldBe("window.XPathEvaluator.prototype.isPrototypeOf(xpathevaluator)", true);
81     
82     xpathresult = xpathevaluator.evaluate('/', document, null, 0, null);
83     shouldBe("window.XPathResult.prototype.isPrototypeOf(xpathresult)", true);
84     
85     try {
86       nodeFilter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, function () {}, false).filter;
87     } catch(e) {}
88     shouldBe("window.NodeFilter.prototype.isPrototypeOf(nodeFilter)", true);
89
90     originalNodePrototype = window.Node.prototype;
91     
92     delete window.Node.prototype;
93     print("[Deleted window.Node.prototype]");
94     shouldBe("window.Node.prototype", originalNodePrototype);
95     
96     originalNodeConstructor = window.Node;    
97
98     // Shadow window.Node
99     window.Node = 1;
100     print("[Set window.Node = 1]");
101     shouldBe("window.Node", 1);
102     
103     // Unshadow window.Node
104     delete window.Node;
105     print("[Deleted window.Node]");
106     shouldBe("window.Node", originalNodeConstructor);
107
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);
114     
115 }
116 </script>
117 </head>
118
119 <body onload="test();">
120 <p>This page tests global constructor objects like window.HTMLDocument. If it passes, you'll
121    see no lines with the text FAIL below.
122 </p>
123 <hr>
124 <div id='console'></div>
125
126 </body>
127 </html>