-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
window-function-name-getter-precedence.html
69 lines (62 loc) · 2.43 KB
/
window-function-name-getter-precedence.html
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
<!-- webkit-test-runner [ ShowModalDialogEnabled=true ] -->
<!DOCTYPE html>
<html>
<head>
<script src="resources/WindowProperties.js"></script>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function log(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, printOnlyOnFailure)
{
var evalA;
try {
evalA = eval(a);
} catch(e) {
evalA = e;
}
if (evalA == b) {
if (!printOnlyOnFailure)
log("PASS: " + a + " should be " + b + " and is.", "green");
} else
log("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
}
function testFunction(functionName)
{
var element = document.createElement('div');
element.id = functionName;
document.body.appendChild(element);
// showModalDialog only works on mac in the DRT. So run this test only if its defined and print output only on failure.
// This'll keep the output consistent on all platforms.
if (functionName == "showModalDialog") {
if (window.showModalDialog != undefined)
shouldBe("typeof window." + functionName, "function", true);
} else
shouldBe("typeof window." + functionName, "function");
document.body.removeChild(element);
}
function runTests()
{
for (var func in windowFunctions) {
testFunction(windowFunctions[func])
}
window.myFunction = function() { return "myFunction"; }
testFunction("myFunction");
window.__proto__.myPrototypeFunction = function() { return "myPrototypeFunction"; }
testFunction("myPrototypeFunction");
}
</script>
</head>
<body onload="runTests();">
<p>This tests that functions of the window object and it's prototype have precedence in lookup over elements with id's of the same name.</p>
<pre id="console"></pre>
</body>
</html>