Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=868996 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 868996</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | <script type="application/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | /** Test for Bug 868996 **/ |
michael@0 | 14 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 15 | |
michael@0 | 16 | var sb1, sb2; |
michael@0 | 17 | var Cu = SpecialPowers.Cu; |
michael@0 | 18 | |
michael@0 | 19 | function testOpenerSet() { |
michael@0 | 20 | // Use setTimeout to make the relevant onerror run in this window |
michael@0 | 21 | var win = window.open("data:text/html,<script>opener.setTimeout(opener.basicOpenerTest, 0, this)</" + "script>"); |
michael@0 | 22 | // A sandbox for the window |
michael@0 | 23 | sb1 = new Cu.Sandbox(win, {wantXrays: true }) |
michael@0 | 24 | sb1.win = win |
michael@0 | 25 | // And a sandbox using the expanded principal. |
michael@0 | 26 | sb2 = new Cu.Sandbox([win], {wantXrays: true }) |
michael@0 | 27 | sb2.win = win |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function evalsb(str, sb) { |
michael@0 | 31 | // Have to unwrap() to get objects we care about |
michael@0 | 32 | return SpecialPowers.unwrap(Cu.evalInSandbox(str, sb)); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function basicOpenerTest(win) { |
michael@0 | 36 | is(win.opener, window, "Opening a window should give it the right opener"); |
michael@0 | 37 | is(evalsb("win.opener", sb1), window, |
michael@0 | 38 | "Reading opener in sandbox 1 should work"); |
michael@0 | 39 | is(evalsb("win.opener", sb2), window, |
michael@0 | 40 | "Reading opener in sandbox 2 should work"); |
michael@0 | 41 | |
michael@0 | 42 | win.opener = $("x").contentWindow; |
michael@0 | 43 | evalsb("win.opener = win.opener.document.getElementById('y').contentWindow", sb1); |
michael@0 | 44 | evalsb("win.opener = win.opener.document.getElementById('z').contentWindow", sb2); |
michael@0 | 45 | |
michael@0 | 46 | is(win.opener, $("x").contentWindow, "Should be able to set an opener to a different window"); |
michael@0 | 47 | is(evalsb("win.opener", sb1), $("y").contentWindow, |
michael@0 | 48 | "Should be able to set the opener to a different window in a sandbox one"); |
michael@0 | 49 | is(evalsb("win.opener", sb2), $("z").contentWindow, |
michael@0 | 50 | "Should be able to set the opener to a different window in a sandbox two"); |
michael@0 | 51 | |
michael@0 | 52 | win.location = "data:text/html,<script>opener.setTimeout(opener.continueOpenerTest, 0, this);</" + "script>"; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function continueOpenerTest(win) { |
michael@0 | 56 | is(win.opener, window, "Navigating a window should have reset the opener we stashed on it temporarily"); |
michael@0 | 57 | is(evalsb("win.opener", sb1), window, |
michael@0 | 58 | "Navigating a window should have reset the opener in sb1"); |
michael@0 | 59 | is(evalsb("win.opener", sb2), window, |
michael@0 | 60 | "Navigating a window should have reset the opener in sb2"); |
michael@0 | 61 | |
michael@0 | 62 | win.opener = 5; |
michael@0 | 63 | evalsb("win.opener = 5", sb1); |
michael@0 | 64 | evalsb("win.opener = 5", sb2); |
michael@0 | 65 | is(win.opener, 5, "Should be able to set an opener to a primitive"); |
michael@0 | 66 | is(evalsb("win.opener", sb1), 5, |
michael@0 | 67 | "Should be able to set the opener to a primitive in a sandbox one"); |
michael@0 | 68 | is(evalsb("win.opener", sb2), 5, |
michael@0 | 69 | "Should be able to set the opener to a primitive in a sandbox two"); |
michael@0 | 70 | win.location = "data:text/html,<script>opener.setTimeout(opener.continueOpenerTest2, 0, this);</" + "script>"; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function continueOpenerTest2(win) { |
michael@0 | 74 | is(win.opener, window, |
michael@0 | 75 | "Navigating a window again should have reset the opener we stashed on it temporarily"); |
michael@0 | 76 | is(evalsb("win.opener", sb1), window, |
michael@0 | 77 | "Navigating a window again should have reset the opener in sb1"); |
michael@0 | 78 | is(evalsb("win.opener", sb2), window, |
michael@0 | 79 | "Navigating a window again should have reset the opener in sb2"); |
michael@0 | 80 | |
michael@0 | 81 | win.opener = null; |
michael@0 | 82 | is(win.opener, null, "Should be able to set the opener to null"); |
michael@0 | 83 | is(evalsb("win.opener", sb1), null, |
michael@0 | 84 | "Setting the opener to null should be visible in sb1"); |
michael@0 | 85 | is(evalsb("win.opener", sb2), null, |
michael@0 | 86 | "Setting the opener to null should be visible in sb2"); |
michael@0 | 87 | |
michael@0 | 88 | win.location = "data:text/html,Loaded"; |
michael@0 | 89 | // Now poll for that load, since we have no way for the window to |
michael@0 | 90 | // communicate with us now |
michael@0 | 91 | setTimeout(checkForLoad, 0, win); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function checkForLoad(win) { |
michael@0 | 95 | if (!win.document.documentElement || |
michael@0 | 96 | win.document.documentElement.textContent != "Loaded") { |
michael@0 | 97 | setTimeout(checkForLoad, 0, win); |
michael@0 | 98 | return; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | is(win.opener, null, "Null opener should persist across navigations"); |
michael@0 | 102 | is(evalsb("win.opener", sb1), null, |
michael@0 | 103 | "Null opener should persist across navigations in sb1"); |
michael@0 | 104 | is(evalsb("win.opener", sb2), null, |
michael@0 | 105 | "Null opener should persist across navigations in sb2"); |
michael@0 | 106 | |
michael@0 | 107 | win.close(); |
michael@0 | 108 | SimpleTest.finish(); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | addLoadEvent(testOpenerSet); |
michael@0 | 112 | </script> |
michael@0 | 113 | </head> |
michael@0 | 114 | <body> |
michael@0 | 115 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=868996">Mozilla Bug 868996</a> |
michael@0 | 116 | <p id="display"></p> |
michael@0 | 117 | <div id="content" style="display: none"> |
michael@0 | 118 | <iframe id="x"></iframe> |
michael@0 | 119 | <iframe id="y"></iframe> |
michael@0 | 120 | <iframe id="z"></iframe> |
michael@0 | 121 | </div> |
michael@0 | 122 | <pre id="test"> |
michael@0 | 123 | </pre> |
michael@0 | 124 | </body> |
michael@0 | 125 | </html> |