tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

window-named-properties.html (3414B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Changes to named properties of the window object</title>
      4 <link rel="author" title="Ms2ger" href="ms2ger@gmail.com">
      5 <link rel="author" title="Boris Zbarsky" href="bzbarsky@mit.edu">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#window">
      7 <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-window-nameditem">
      8 <link rel="help" href="https://webidl.spec.whatwg.org/#named-properties-object">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <div id=log></div>
     12 <iframe name="bar"></iframe>
     13 <iframe name="baz"></iframe>
     14 <iframe name="baz"></iframe>
     15 <iframe name="constructor"></iframe>
     16 <iframe id="quux"></iframe>
     17 <script>
     18 function assert_data_propdesc(pd, Writable, Enumerable, Configurable) {
     19  assert_equals(typeof pd, "object");
     20  assert_equals(pd.writable, Writable);
     21  assert_equals(pd.enumerable, Enumerable);
     22  assert_equals(pd.configurable, Configurable);
     23 }
     24 test(function() {
     25  assert_true("bar" in window, "bar not in window");
     26  assert_equals(window["bar"],
     27                document.getElementsByTagName("iframe")[0].contentWindow);
     28 }, "Static name");
     29 
     30 test(function() {
     31  assert_true("quux" in window, "quux not in window");
     32  assert_equals(window["quux"],
     33                document.getElementsByTagName("iframe")[4]);
     34 }, "Static id");
     35 
     36 test(function() {
     37  assert_true("bar" in Window.prototype, "bar in Window.prototype");
     38  assert_false(Window.prototype.hasOwnProperty("bar"), "Window.prototype.hasOwnProperty(\"bar\")");
     39 
     40  var gsp = Object.getPrototypeOf(Object.getPrototypeOf(window));
     41  assert_true("bar" in gsp, "bar in gsp");
     42  assert_true(gsp.hasOwnProperty("bar"), "gsp.hasOwnProperty(\"bar\")");
     43  assert_data_propdesc(Object.getOwnPropertyDescriptor(gsp, "bar"),
     44                       true, false, true);
     45 }, "Static name on the prototype");
     46 test(function() {
     47  assert_equals(window.constructor, Window);
     48  assert_false(window.hasOwnProperty("constructor"), "window.constructor should not be an own property.");
     49 
     50  var proto = Object.getPrototypeOf(window);
     51  assert_equals(proto.constructor, Window);
     52  assert_true("constructor" in proto, "constructor in proto");
     53  assert_data_propdesc(Object.getOwnPropertyDescriptor(proto, "constructor"),
     54                       true, false, true);
     55 
     56  var gsp = Object.getPrototypeOf(proto);
     57  assert_true("constructor" in gsp, "constructor in gsp");
     58  assert_false(gsp.hasOwnProperty("constructor"), "gsp.hasOwnProperty(\"constructor\")");
     59  assert_equals(Object.getOwnPropertyDescriptor(gsp, "constructor"), undefined);
     60 }, "constructor");
     61 test(function() {
     62  var gsp = Object.getPrototypeOf(Object.getPrototypeOf(window));
     63  assert_equals(gsp.baz, document.getElementsByTagName("iframe")[1].contentWindow);
     64 }, "duplicate property names")
     65 var t = async_test("Dynamic name")
     66 var t2 = async_test("Ghost name")
     67 t.step(function() {
     68  var iframe = document.getElementsByTagName("iframe")[0];
     69  iframe.setAttribute("srcdoc", "<script>window.name='foo'<\/script>");
     70  iframe.onload = function() {
     71    t.step(function() {
     72      assert_true("foo" in window, "foo not in window");
     73      assert_equals(window["foo"], iframe.contentWindow);
     74    });
     75    t.done();
     76    t2.step(function() {
     77      assert_false("bar" in window, "bar still in window");
     78      assert_equals(window["bar"], undefined);
     79    });
     80    t2.done();
     81  };
     82 });
     83 </script>