gecko/dom/base/test/test_window_indexing.html

117 lines
4.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=823228
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 823228</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=823228">Mozilla Bug 823228</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe name="x" id="x"></iframe>
<iframe name="y" id="y"></iframe>
</div>
<pre id="test">
</pre>
<script type="application/javascript">
/** Test for Bug 823228 **/
is(window, window.frames, "These better be equal");
ok("0" in window, "We have a subframe");
ok("1" in window, "We have two subframes");
ok(!("2" in window), "But we don't have three subframes");
window[2] = "myString";
ok("2" in window, "Should be able to set expando");
Object.getPrototypeOf(window)[3] = "Hey there";
ok("3" in window, "Should be walking up the proto chain");
is(window[0].name, "x", "First frame is x");
is(window[1].name, "y", "Second frame is y");
is(window[2], "myString", "We should still have our expando");
is(window[3], "Hey there", "We should still have our prop on the proto chain");
var x = $("x");
var y = $("y");
is(x.contentWindow, window[0], "First frame should have correct window");
is(y.contentWindow, window[1], "Second frame should have correct window");
// set() hook test
window[1] = "FAIL";
is(window[1].name, "y", "Second frame is still y");
y.parentNode.removeChild(y);
ok(!("1" in window), "We no longer have two subframes");
is(window[1], undefined, "We should not have a value here");
// defineProperty() hook test
x.parentNode.appendChild(y);
Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
writable: true })
y.parentNode.removeChild(y);
ok(!("1" in window), "We no longer have two subframes, again");
is(window[1], undefined, "We should not have a value here either");
// More set() hook test
window[1] = "PASS";
is(window[1], "PASS", "Should be able to set expando on window[1] now");
var desc = Object.getOwnPropertyDescriptor(window, "1");
ok(desc.configurable, "Expando should be configurable");
ok(desc.enumerable, "Expando should be configurable");
ok(desc.writable, "Expando should be writable");
is(desc.value, "PASS", "Expando should have correct value");
// Sneaky shadowing (get() hook)
x.parentNode.appendChild(y);
is(window[1], y.contentWindow, "Second frame should now shadow expando");
desc = Object.getOwnPropertyDescriptor(window, "1");
ok(desc.configurable, "Subframe should be configurable");
ok(desc.enumerable, "Subframe should be configurable");
ok(!desc.writable, "Subframe should not be writable");
is(desc.value, y.contentWindow, "Subframe should have correct value");
// And unshadowing
y.parentNode.removeChild(y);
is(window[1], "PASS", "And now we should be able to see the expando again");
// And more defineProperty()
Object.defineProperty(window, "1", { value: "PASS2", configurable: true,
writable: true })
is(window[1], "PASS2", "Defining past end of list should work");
// Enumeration tests
x.parentNode.appendChild(y);
var names = Object.getOwnPropertyNames(window);
is(names[0], "0", "Must start with 0");
is(names[1], "1", "Must continue with 1");
isnot(names.indexOf("2"), -1, "And then 2, defined earlier, should be in there");
is(names.indexOf("3"), -1, "But no 3; that's on the proto");
names = [];
for (var name in window) {
names.push(name);
}
is(names[0], "0", "Enumeration must start with 0");
is(names[1], "1", "Enumeration must continue with 1");
isnot(names.indexOf("2"), -1, "Enumeration: and then 2, defined earlier");
isnot(names.indexOf("3"), -1, "Enumeration: and then 3, defined on the proto");
is(names.indexOf("4"), -1, "But no 4 around");
// Delete tests
delete window[1];
is(window[1], y.contentWindow, "Shouldn't be able to delete a supported index");
y.parentNode.removeChild(y);
is(window[1], "PASS2",
"And shouldn't have deleted the thing we were shadowing either");
delete window[1];
is(window[1], undefined,
"But should be able to delete unshadowed things");
</script>
</body>
</html>