Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { TabStateFlusher } = ChromeUtils.importESModule(
"resource:///modules/sessionstore/TabStateFlusher.sys.mjs"
);
// Restore a page containing a cross-origin about:blank iframe
add_task(async function test_restore_with_cross_origin_blank_iframe() {
const tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
);
const blankLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, {
wantLoad: "about:blank",
includeSubFrames: true,
});
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
const ifr = content.document.querySelector("iframe");
await SpecialPowers.spawn(ifr, [], () => {
// Must use wrappedJSObject so we use the right content principal
content.wrappedJSObject.location = "about:blank";
});
});
await blankLoaded;
await TabStateFlusher.flush(tab.linkedBrowser);
const sessionStoreClosedObjectsChanged = TestUtils.topicObserved(
"sessionstore-closed-objects-changed"
);
gBrowser.removeTab(tab);
await sessionStoreClosedObjectsChanged;
const restoredTab = SessionStore.undoCloseTab(window, 0);
await BrowserTestUtils.waitForEvent(restoredTab, "SSTabRestored");
// The crash doesn't cause the test to fail, so check if the iframe was restored
await SpecialPowers.spawn(restoredTab.linkedBrowser, [], async () => {
const ifr = content.document.querySelector("iframe");
Assert.ok(ifr, "did not crash");
Assert.ok(!ifr.contentDocument && !ifr.document, "iframe is restricted");
});
BrowserTestUtils.removeTab(restoredTab);
});