summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_window_cross_origin_props.html
blob: d16a103fb68157f1532ab7ac8bbe53b4de12e972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=946067
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 946067</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  /** Test for Bug 946067 **/
  SimpleTest.waitForExplicitFinish();

  function doGet(prop, thisObj) {
    return Object.getOwnPropertyDescriptor(window, prop).get.call(thisObj);
  }

  function doSet(prop, thisObj, value) {
    return Object.getOwnPropertyDescriptor(window, prop).set.call(thisObj, value);
  }

  window.onload = function() {
    frames[0].focus();
    is(document.activeElement.id, "x", "Should have focused first subframe");
    frames[0].blur();
    window.focus.call(frames[1]);
    is(document.activeElement.id, "y", "Should have focused second subframe");
    window.blur.call(frames[1]);

    frames[0].close();
    is(frames[0].closed, false, "Subframe is not closed");
    window.close.call(frames[0]);
    is(doGet("closed", frames[0]), false, "Subframe is still not closed");

    is(frames[0].frames, frames[0], "window.frames === window");
    is(doGet("frames", frames[0]), frames[0],
       "Really, window.frames === window");

    try {
      frames[0].frames = 1;
      ok(false, "Should throw when setting .frames");
    } catch (e) {
      ok(true, "Should throw when setting .frames");
    }
    try {
      doSet("frames", frames[0], 1);
      ok(false, "Should still throw when setting .frames");
    } catch (e) {
      ok(true, "Should still throw when setting .frames");
    }

    // Just check whether we can get the location without throwing:
    is(frames[0].location, doGet("location", frames[0]),
       "Should be same Location object");

    is(frames[0].length, 0, "404 page has no subframes");
    is(doGet("length", frames[0]), 0, "404 page has no subframes");

    is(frames[0].opener, null, "subframe has no opener");
    is(doGet("opener", frames[0]), null, "subframe still has no opener");

    is(frames[0].parent, window, "subframe has us as parent");
    is(doGet("parent", frames[0]), window, "subframe still has us as parent");

    // Check that postMessage doesn't throw
    frames[0].postMessage(null, "*");

    is(frames[0].self, frames[0], "self should work");
    is(doGet("self", frames[0]), frames[0], "self should still work");

    is(frames[0].top, window.top, "Our subframe's top should be our top");
    is(doGet("top", frames[0]), window.top,
       "Our subframe's top should still be our top");

    is(frames[0].window, frames[0], "window getter should work");
    is(doGet("window", frames[0]), frames[0], "window getter should still work");
    isnot(Object.getOwnPropertyDescriptor(window, "window").get, undefined,
          "Should have a getter here");

    // Finally, check that we can set the location
    frames[0].location = "about:blank";
    doSet("location", frames[1], "about:blank");

    SimpleTest.finish();
  }
  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946067">Mozilla Bug 946067</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
  <iframe id="x" src="http://www.example.com/nosuchpageIhope"></iframe>
  <iframe id="y" src="http://www.example.com/nosuchpageIhope"></iframe>
</pre>
</body>
</html>