Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const SAME_SITE_PARENT_URL =
getRootDirectory(gTestPath).replace(
) + "framebusting_intervention_parent.html";
const SAME_SITE_FRAME_URL =
getRootDirectory(gTestPath).replace(
) + "framebusting_intervention_frame.html";
const SAME_SITE_DESTINATION_URL =
getRootDirectory(gTestPath).replace(
) + "framebusting_intervention_parent.html";
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["dom.disable_open_during_load", true],
["dom.security.framebusting_intervention.enabled", true],
["dom.disable_open_click_delay", 0],
],
});
});
add_task(async function () {
const tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"about:blank"
);
// Run actual checks.
await checkSameSiteDestination(tab);
await checkCrossSiteDestination(tab);
await checkCrossSiteFrame(tab);
BrowserTestUtils.removeTab(tab);
});
async function checkSameSiteDestination(tab) {
info("Triggering framebusting to a same-site destination...");
const loaded = BrowserTestUtils.browserLoaded(
tab.linkedBrowser,
/*includeSubFrames=*/ false,
SAME_SITE_DESTINATION_URL
);
await triggerFramebusting(
tab,
/*attrs=*/ {},
/*params=*/ { variant: "url", url: SAME_SITE_DESTINATION_URL },
SAME_SITE_PARENT_URL,
SAME_SITE_FRAME_URL
);
info("Waiting for redirect...");
await loaded;
is(tab.linkedBrowser.currentURI.spec, SAME_SITE_DESTINATION_URL);
}
async function checkCrossSiteDestination(tab) {
info("Triggering framebusting to a cross-site destination...");
await triggerFramebusting(
tab,
/*attrs=*/ {},
/*params=*/ { variant: "url", url: FRAMEBUSTING_PARENT_URL },
SAME_SITE_PARENT_URL,
SAME_SITE_FRAME_URL
);
info("Waiting for notification...");
await TestUtils.waitForCondition(() =>
gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked")
);
is(tab.linkedBrowser.currentURI.spec, SAME_SITE_PARENT_URL);
}
async function checkCrossSiteFrame(tab) {
info("Triggering framebusting from a cross-site frame...");
await triggerFramebusting(
tab,
/*attrs=*/ {},
/*params=*/ { variant: "url", url: SAME_SITE_DESTINATION_URL },
SAME_SITE_PARENT_URL
);
info("Waiting for notification...");
await TestUtils.waitForCondition(() =>
gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked")
);
is(tab.linkedBrowser.currentURI.spec, SAME_SITE_PARENT_URL);
}