dom/base/test/test_window_indexing.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial