/** Test for Bug 868996 **/
SimpleTest.waitForExplicitFinish();
var sb1, sb2; var Cu = SpecialPowers.Cu;
function testOpenerSet() {
// Use setTimeout to make the relevant onerror run in this window var win = window.open("file1_setting_opener.html");
// A sandbox for the window
sb1 = new Cu.Sandbox(win, {wantXrays: true })
sb1.win = win
// And a sandbox using the expanded principal.
sb2 = new Cu.Sandbox([win], {wantXrays: true })
sb2.win = win
}
function evalsb(str, sb) {
// Have to unwrap() to get objects we care about
return SpecialPowers.unwrap(Cu.evalInSandbox(str, sb));
}
function basicOpenerTest(win) {
is(win.opener, window, "Opening a window should give it the right opener");
is(evalsb("win.opener", sb1), window, "Reading opener in sandbox 1 should work");
is(evalsb("win.opener", sb2), window, "Reading opener in sandbox 2 should work");
is(win.opener, $("x").contentWindow, "Should be able to set an opener to a different window");
is(evalsb("win.opener", sb1), $("y").contentWindow, "Should be able to set the opener to a different window in a sandbox one");
is(evalsb("win.opener", sb2), $("z").contentWindow, "Should be able to set the opener to a different window in a sandbox two");
win.location = "file2_setting_opener.html";
}
function continueOpenerTest(win) {
is(win.opener, window, "Navigating a window should have reset the opener we stashed on it temporarily");
is(evalsb("win.opener", sb1), window, "Navigating a window should have reset the opener in sb1");
is(evalsb("win.opener", sb2), window, "Navigating a window should have reset the opener in sb2");
win.opener = 5;
evalsb("win.opener = 5", sb1);
evalsb("win.opener = 5", sb2);
is(win.opener, 5, "Should be able to set an opener to a primitive");
is(evalsb("win.opener", sb1), 5, "Should be able to set the opener to a primitive in a sandbox one");
is(evalsb("win.opener", sb2), 5, "Should be able to set the opener to a primitive in a sandbox two");
win.location = "file3_setting_opener.html";
}
function continueOpenerTest2(win) {
is(win.opener, window, "Navigating a window again should have reset the opener we stashed on it temporarily");
is(evalsb("win.opener", sb1), window, "Navigating a window again should have reset the opener in sb1");
is(evalsb("win.opener", sb2), window, "Navigating a window again should have reset the opener in sb2");
win.opener = null;
is(win.opener, null, "Should be able to set the opener to null");
is(evalsb("win.opener", sb1), null, "Setting the opener to null should be visible in sb1");
is(evalsb("win.opener", sb2), null, "Setting the opener to null should be visible in sb2");
win.location = "file4_setting_opener.html";
// Now poll for that load, since we have no way for the window to
// communicate with us now
setTimeout(checkForLoad, 0, win);
}
function checkForLoad(win) {
if (!win.document.documentElement ||
win.document.documentElement.innerText != "Loaded") {
setTimeout(checkForLoad, 0, win);
return;
}
is(win.opener, null, "Null opener should persist across navigations");
is(evalsb("win.opener", sb1), null, "Null opener should persist across navigations in sb1");
is(evalsb("win.opener", sb2), null, "Null opener should persist across navigations in sb2");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.