Bumping manifests a=b2g-bump
[gecko.git] / dom / base / test / test_window_indexing.html
blobb560db16be1961da9e6d9cb2e103d7edde508810
2 <!DOCTYPE HTML>
3 <html>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=823228
6 -->
7 <head>
8 <meta charset="utf-8">
9 <title>Test for Bug 823228</title>
10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=823228">Mozilla Bug 823228</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
17 <iframe name="x" id="x"></iframe>
18 <iframe name="y" id="y"></iframe>
19 </div>
20 <pre id="test">
21 </pre>
22 <script type="application/javascript">
24 /** Test for Bug 823228 **/
25 is(window, window.frames, "These better be equal");
26 ok("0" in window, "We have a subframe");
27 ok("1" in window, "We have two subframes");
28 ok(!("2" in window), "But we don't have three subframes");
29 window[2] = "myString";
30 ok(!("2" in window), "Should not be able to set indexed expando");
31 Object.getPrototypeOf(window)[3] = "Hey there";
32 ok("3" in window, "Should be walking up the proto chain");
34 is(window[0].name, "x", "First frame is x");
35 is(window[1].name, "y", "Second frame is y");
36 is(window[2], undefined, "We should still not have our expando");
37 is(window[3], "Hey there", "We should still have our prop on the proto chain");
39 var x = $("x");
40 var y = $("y");
42 is(x.contentWindow, window[0], "First frame should have correct window");
43 is(y.contentWindow, window[1], "Second frame should have correct window");
45 // set() hook test
46 window[1] = "FAIL";
47 is(window[1].name, "y", "Second frame is still y");
48 y.parentNode.removeChild(y);
49 ok(!("1" in window), "We no longer have two subframes");
50 is(window[1], undefined, "We should not have a value here");
52 // defineProperty() hook test
53 x.parentNode.appendChild(y);
54 Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
55 writable: true })
56 y.parentNode.removeChild(y);
57 ok(!("1" in window), "We no longer have two subframes, again");
58 is(window[1], undefined, "We should not have a value here either");
60 // More set() hook test
61 window[1] = "FAIL3";
62 ok(!("1" in window), "We shouldn't allow indexed expandos");
63 is(window[1], undefined, "We should not have a value for an indexed expando");
64 var desc = Object.getOwnPropertyDescriptor(window, "1");
65 is(desc, undefined, "We really really shouldn't have indexed expandos");
67 x.parentNode.appendChild(y);
68 is(window[1], y.contentWindow, "Second frame should now be visible");
69 desc = Object.getOwnPropertyDescriptor(window, "1");
70 ok(desc.configurable, "Subframe should be configurable");
71 ok(desc.enumerable, "Subframe should be configurable");
72 ok(!desc.writable, "Subframe should not be writable");
73 is(desc.value, y.contentWindow, "Subframe should have correct value");
75 y.parentNode.removeChild(y);
76 is(window[1], undefined, "And now we should be back to no [1] property");
78 // And more defineProperty()
79 Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
80 writable: true })
81 ok(!("1" in window), "Defining indexed properties really just shouldn't work");
82 is(window[1], undefined, "Defining past end of list should not work");
84 // Enumeration tests
85 x.parentNode.appendChild(y);
87 var names = Object.getOwnPropertyNames(window);
88 is(names[0], "0", "Must start with 0");
89 is(names[1], "1", "Must continue with 1");
90 is(names.indexOf("2"), -1, "And 2, an attempted expando, should not be in there");
91 is(names.indexOf("3"), -1, "But no 3; that's on the proto");
93 names = [];
94 for (var name in window) {
95 names.push(name);
97 is(names[0], "0", "Enumeration must start with 0");
98 is(names[1], "1", "Enumeration must continue with 1");
99 is(names.indexOf("2"), -1, "Enumeration: but no expando 2");
100 isnot(names.indexOf("3"), -1, "Enumeration: and then 3, defined on the proto");
101 is(names.indexOf("4"), -1, "But no 4 around");
103 // Delete tests
104 is(delete window[1], false, "Deleting supported index should return false");
105 is(window[1], y.contentWindow, "Shouldn't be able to delete a supported index");
106 y.parentNode.removeChild(y);
107 is(window[1], undefined,
108 "And now we should have no property here");
109 is(delete window[1], true, "Deleting unsupported index should return true");
110 is(window[1], undefined,
111 "And we shouldn't have things magically appear due to delete");
112 </script>
113 </body>
114 </html>