summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/global-constructors.html
blob: 25c56e07eab0a3f4a2b382f53ecf1df38c41ed64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html>
<head>
<style>
  * {
    color: black;
  }
</style>
<script>
function print(message, color) 
{
    var paragraph = document.createElement("div");
    paragraph.appendChild(document.createTextNode(message));
    paragraph.style.fontFamily = "monospace";
    if (color)
        paragraph.style.color = color;
    document.getElementById("console").appendChild(paragraph);
}

function shouldBe(a, b)
{
    var evalA;
    try {
        evalA = eval(a);
    } catch(e) {
        evalA = e;
    }
    if (evalA != b)
        print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
}

function test() 
{
    if (window.testRunner)
        testRunner.dumpAsText();

    domParser = new DOMParser();
    shouldBe("DOMParser.prototype.isPrototypeOf(domParser)", true);
    
    xmlHttpRequest = new XMLHttpRequest();
    shouldBe("XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest)", true);
    
    xmlSerializer = new XMLSerializer();
    shouldBe("XMLSerializer.prototype.isPrototypeOf(xmlSerializer)", true);
    
    xsltProcessor = new XSLTProcessor();
    shouldBe("XSLTProcessor.prototype.isPrototypeOf(xsltProcessor)", true);

    shouldBe("window.Document.prototype.isPrototypeOf(document)", true);
    shouldBe("window.HTMLDocument.prototype.isPrototypeOf(document)", true);
    
    element = document.body;
    shouldBe("window.Node.prototype.isPrototypeOf(element)", true);
    shouldBe("window.Element.prototype.isPrototypeOf(element)", true);
    shouldBe("window.HTMLElement.prototype.isPrototypeOf(element)", true);
    
    range = document.createRange();
    shouldBe("window.Range.prototype.isPrototypeOf(range)", true);
    
    cssRule = document.styleSheets[0].cssRules[0];
    shouldBe("window.CSSRule.prototype.isPrototypeOf(cssRule)", true);

    cssStyleDeclaration = cssRule.style;
    shouldBe("window.CSSStyleDeclaration.prototype.isPrototypeOf(cssStyleDeclaration)", true);

    event = document.createEvent("MutationEvents");
    shouldBe("window.Event.prototype.isPrototypeOf(event)", true);
    shouldBe("window.MutationEvent.prototype.isPrototypeOf(event)", true);

    xmldoc = document.implementation.createDocument(null, null, null);
    shouldBe("window.XMLDocument.prototype.isPrototypeOf(xmldoc)", true);
    
    fragment = document.createDocumentFragment();
    shouldBe("window.DocumentFragment.prototype.isPrototypeOf(fragment)", true);
    
    xpathevaluator = new XPathEvaluator();
    shouldBe("window.XPathEvaluator.prototype.isPrototypeOf(xpathevaluator)", true);
    
    xpathresult = xpathevaluator.evaluate('/', document, null, 0, null);
    shouldBe("window.XPathResult.prototype.isPrototypeOf(xpathresult)", true);
    
    try {
      nodeFilter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, function () {}, false).filter;
    } catch(e) {}
    shouldBe("window.NodeFilter.prototype.isPrototypeOf(nodeFilter)", true);

    originalNodePrototype = window.Node.prototype;
    
    delete window.Node.prototype;
    print("[Deleted window.Node.prototype]");
    shouldBe("window.Node.prototype", originalNodePrototype);
    
    originalNodeConstructor = window.Node;    

    // Shadow window.Node
    window.Node = 1;
    print("[Set window.Node = 1]");
    shouldBe("window.Node", 1);
    
    // Unshadow window.Node
    delete window.Node;
    print("[Deleted window.Node]");
    shouldBe("window.Node", originalNodeConstructor);

    // Attempt to shadow window.Node with a frame named 'Node'
    var iframe = document.createElement('iframe');
    iframe.setAttribute('name', "Node");
    document.body.appendChild(iframe);
    print("[Added an iframe named 'Node']");
    shouldBe("window.Node", originalNodeConstructor);
    
}
</script>
</head>

<body onload="test();">
<p>This page tests global constructor objects like window.HTMLDocument. If it passes, you'll
   see no lines with the text FAIL below.
</p>
<hr>
<div id='console'></div>

</body>
</html>