dom/base/test/test_window_indexing.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/test/test_window_indexing.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +
     1.5 +<!DOCTYPE HTML>
     1.6 +<html>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=823228
     1.9 +-->
    1.10 +<head>
    1.11 +  <meta charset="utf-8">
    1.12 +  <title>Test for Bug 823228</title>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=823228">Mozilla Bug 823228</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +  <iframe name="x" id="x"></iframe>
    1.21 +  <iframe name="y" id="y"></iframe>
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +</pre>
    1.25 +  <script type="application/javascript">
    1.26 +
    1.27 +  /** Test for Bug 823228 **/
    1.28 +  is(window, window.frames, "These better be equal");
    1.29 +  ok("0" in window, "We have a subframe");
    1.30 +  ok("1" in window, "We have two subframes");
    1.31 +  ok(!("2" in window), "But we don't have three subframes");
    1.32 +  window[2] = "myString";
    1.33 +  ok(!("2" in window), "Should not be able to set indexed expando");
    1.34 +  Object.getPrototypeOf(window)[3] = "Hey there";
    1.35 +  ok("3" in window, "Should be walking up the proto chain");
    1.36 +
    1.37 +  is(window[0].name, "x", "First frame is x");
    1.38 +  is(window[1].name, "y", "Second frame is y");
    1.39 +  is(window[2], undefined, "We should still not have our expando");
    1.40 +  is(window[3], "Hey there", "We should still have our prop on the proto chain");
    1.41 +
    1.42 +  var x = $("x");
    1.43 +  var y = $("y");
    1.44 +
    1.45 +  is(x.contentWindow, window[0], "First frame should have correct window");
    1.46 +  is(y.contentWindow, window[1], "Second frame should have correct window");
    1.47 +
    1.48 +  // set() hook test
    1.49 +  window[1] = "FAIL";
    1.50 +  is(window[1].name, "y", "Second frame is still y");
    1.51 +  y.parentNode.removeChild(y);
    1.52 +  ok(!("1" in window), "We no longer have two subframes");
    1.53 +  is(window[1], undefined, "We should not have a value here");
    1.54 +
    1.55 +  // defineProperty() hook test
    1.56 +  x.parentNode.appendChild(y);
    1.57 +  Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
    1.58 +				       writable: true })
    1.59 +  y.parentNode.removeChild(y);
    1.60 +  ok(!("1" in window), "We no longer have two subframes, again");
    1.61 +  is(window[1], undefined, "We should not have a value here either");
    1.62 +
    1.63 +  // More set() hook test
    1.64 +  window[1] = "FAIL3";
    1.65 +  ok(!("1" in window), "We shouldn't allow indexed expandos");
    1.66 +  is(window[1], undefined, "We should not have a value for an indexed expando");
    1.67 +  var desc = Object.getOwnPropertyDescriptor(window, "1");
    1.68 +  is(desc, undefined, "We really really shouldn't have indexed expandos");
    1.69 +
    1.70 +  x.parentNode.appendChild(y);
    1.71 +  is(window[1], y.contentWindow, "Second frame should now be visible");
    1.72 +  desc = Object.getOwnPropertyDescriptor(window, "1");
    1.73 +  ok(desc.configurable, "Subframe should be configurable");
    1.74 +  ok(desc.enumerable, "Subframe should be configurable");
    1.75 +  ok(!desc.writable, "Subframe should not be writable");
    1.76 +  is(desc.value, y.contentWindow, "Subframe should have correct value");
    1.77 +
    1.78 +  y.parentNode.removeChild(y);
    1.79 +  is(window[1], undefined, "And now we should be back to no [1] property");
    1.80 +
    1.81 +  // And more defineProperty()
    1.82 +  Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
    1.83 +				       writable: true })
    1.84 +  ok(!("1" in window), "Defining indexed properties really just shouldn't work");
    1.85 +  is(window[1], undefined, "Defining past end of list should not work");
    1.86 +
    1.87 +  // Enumeration tests
    1.88 +  x.parentNode.appendChild(y);
    1.89 +
    1.90 +  var names = Object.getOwnPropertyNames(window);
    1.91 +  is(names[0], "0", "Must start with 0");
    1.92 +  is(names[1], "1", "Must continue with 1");
    1.93 +  is(names.indexOf("2"), -1, "And 2, an attempted expando, should not be in there");
    1.94 +  is(names.indexOf("3"), -1, "But no 3; that's on the proto");
    1.95 +
    1.96 +  names = [];
    1.97 +  for (var name in window) {
    1.98 +    names.push(name);
    1.99 +  }
   1.100 +  is(names[0], "0", "Enumeration must start with 0");
   1.101 +  is(names[1], "1", "Enumeration must continue with 1");
   1.102 +  is(names.indexOf("2"), -1, "Enumeration: but no expando 2");
   1.103 +  isnot(names.indexOf("3"), -1, "Enumeration: and then 3, defined on the proto");
   1.104 +  is(names.indexOf("4"), -1, "But no 4 around");
   1.105 +
   1.106 +  // Delete tests
   1.107 +  is(delete window[1], false, "Deleting supported index should return false");
   1.108 +  is(window[1], y.contentWindow, "Shouldn't be able to delete a supported index");
   1.109 +  y.parentNode.removeChild(y);
   1.110 +  is(window[1], undefined,
   1.111 +     "And now we should have no property here");
   1.112 +  is(delete window[1], true, "Deleting unsupported index should return true");
   1.113 +  is(window[1], undefined,
   1.114 +     "And we shouldn't have things magically appear due to delete");
   1.115 +  </script>
   1.116 +</body>
   1.117 +</html>

mercurial