|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
<html>
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
https://bugzilla.mozilla.org/show_bug.cgi?id=868996
|
|
Packit |
f0b94e |
-->
|
|
Packit |
f0b94e |
<head>
|
|
Packit |
f0b94e |
<meta charset="utf-8">
|
|
Packit |
f0b94e |
<title>Test for Bug 868996</title>
|
|
Packit |
f0b94e |
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
Packit |
f0b94e |
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
Packit |
f0b94e |
<script type="application/javascript">
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/** Test for Bug 868996 **/
|
|
Packit |
f0b94e |
SimpleTest.waitForExplicitFinish();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
var sb1, sb2;
|
|
Packit |
f0b94e |
var Cu = SpecialPowers.Cu;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function testOpenerSet() {
|
|
Packit |
f0b94e |
// Use setTimeout to make the relevant onerror run in this window
|
|
Packit |
f0b94e |
var win = window.open("file1_setting_opener.html");
|
|
Packit |
f0b94e |
// A sandbox for the window
|
|
Packit |
f0b94e |
sb1 = new Cu.Sandbox(win, {wantXrays: true })
|
|
Packit |
f0b94e |
sb1.win = win
|
|
Packit |
f0b94e |
// And a sandbox using the expanded principal.
|
|
Packit |
f0b94e |
sb2 = new Cu.Sandbox([win], {wantXrays: true })
|
|
Packit |
f0b94e |
sb2.win = win
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function evalsb(str, sb) {
|
|
Packit |
f0b94e |
// Have to unwrap() to get objects we care about
|
|
Packit |
f0b94e |
return SpecialPowers.unwrap(Cu.evalInSandbox(str, sb));
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function basicOpenerTest(win) {
|
|
Packit |
f0b94e |
is(win.opener, window, "Opening a window should give it the right opener");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), window,
|
|
Packit |
f0b94e |
"Reading opener in sandbox 1 should work");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), window,
|
|
Packit |
f0b94e |
"Reading opener in sandbox 2 should work");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.opener = $("x").contentWindow;
|
|
Packit |
f0b94e |
evalsb("win.opener = win.opener.document.getElementById('y').contentWindow", sb1);
|
|
Packit |
f0b94e |
evalsb("win.opener = win.opener.document.getElementById('z').contentWindow", sb2);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
is(win.opener, $("x").contentWindow, "Should be able to set an opener to a different window");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), $("y").contentWindow,
|
|
Packit |
f0b94e |
"Should be able to set the opener to a different window in a sandbox one");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), $("z").contentWindow,
|
|
Packit |
f0b94e |
"Should be able to set the opener to a different window in a sandbox two");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.location = "file2_setting_opener.html";
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function continueOpenerTest(win) {
|
|
Packit |
f0b94e |
is(win.opener, window, "Navigating a window should have reset the opener we stashed on it temporarily");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), window,
|
|
Packit |
f0b94e |
"Navigating a window should have reset the opener in sb1");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), window,
|
|
Packit |
f0b94e |
"Navigating a window should have reset the opener in sb2");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.opener = 5;
|
|
Packit |
f0b94e |
evalsb("win.opener = 5", sb1);
|
|
Packit |
f0b94e |
evalsb("win.opener = 5", sb2);
|
|
Packit |
f0b94e |
is(win.opener, 5, "Should be able to set an opener to a primitive");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), 5,
|
|
Packit |
f0b94e |
"Should be able to set the opener to a primitive in a sandbox one");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), 5,
|
|
Packit |
f0b94e |
"Should be able to set the opener to a primitive in a sandbox two");
|
|
Packit |
f0b94e |
win.location = "file3_setting_opener.html";
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function continueOpenerTest2(win) {
|
|
Packit |
f0b94e |
is(win.opener, window,
|
|
Packit |
f0b94e |
"Navigating a window again should have reset the opener we stashed on it temporarily");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), window,
|
|
Packit |
f0b94e |
"Navigating a window again should have reset the opener in sb1");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), window,
|
|
Packit |
f0b94e |
"Navigating a window again should have reset the opener in sb2");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.opener = null;
|
|
Packit |
f0b94e |
is(win.opener, null, "Should be able to set the opener to null");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), null,
|
|
Packit |
f0b94e |
"Setting the opener to null should be visible in sb1");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), null,
|
|
Packit |
f0b94e |
"Setting the opener to null should be visible in sb2");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.location = "file4_setting_opener.html";
|
|
Packit |
f0b94e |
// Now poll for that load, since we have no way for the window to
|
|
Packit |
f0b94e |
// communicate with us now
|
|
Packit |
f0b94e |
setTimeout(checkForLoad, 0, win);
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
function checkForLoad(win) {
|
|
Packit |
f0b94e |
if (!win.document.documentElement ||
|
|
Packit |
f0b94e |
win.document.documentElement.innerText != "Loaded") {
|
|
Packit |
f0b94e |
setTimeout(checkForLoad, 0, win);
|
|
Packit |
f0b94e |
return;
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
is(win.opener, null, "Null opener should persist across navigations");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb1), null,
|
|
Packit |
f0b94e |
"Null opener should persist across navigations in sb1");
|
|
Packit |
f0b94e |
is(evalsb("win.opener", sb2), null,
|
|
Packit |
f0b94e |
"Null opener should persist across navigations in sb2");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
win.close();
|
|
Packit |
f0b94e |
SimpleTest.finish();
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
addLoadEvent(testOpenerSet);
|
|
Packit |
f0b94e |
</script>
|
|
Packit |
f0b94e |
</head>
|
|
Packit |
f0b94e |
<body>
|
|
Packit |
f0b94e |
Mozilla Bug 868996
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
<iframe id="x"></iframe>
|
|
Packit |
f0b94e |
<iframe id="y"></iframe>
|
|
Packit |
f0b94e |
<iframe id="z"></iframe>
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
</body>
|
|
Packit |
f0b94e |
</html>
|