Bug 1527753 - Part 2: Add test for restricting JS Window Actors to specific remoteTypes; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D25052

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Dai 2019-03-27 14:54:15 +00:00
parent ea22ce4b23
commit df61a92296

View File

@ -24,6 +24,7 @@ let windowActorOptions = {
function teardown() {
windowActorOptions.allFrames = false;
delete windowActorOptions.matches;
delete windowActorOptions.remoteTypes;
ChromeUtils.unregisterWindowActor("Test");
}
@ -296,6 +297,46 @@ add_task(async function test_getActor_with_iframe_mismatch() {
});
});
add_task(async function test_getActor_with_remoteType_match() {
await BrowserTestUtils.withNewTab({gBrowser, url: TEST_URL},
async function(browser) {
windowActorOptions.remoteTypes = ["web"];
ChromeUtils.registerWindowActor("Test", windowActorOptions);
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent.getActor("Test"), "JSWindowActorParent should have value.");
await ContentTask.spawn(
browser, {}, async function() {
let child = content.window.getWindowGlobalChild();
ok(child, "WindowGlobalChild should have value.");
ok(child.getActor("Test"), "JSWindowActorChild should have value.");
});
teardown();
});
});
add_task(async function test_getActor_with_remoteType_mismatch() {
await BrowserTestUtils.withNewTab({gBrowser, url: TEST_URL},
async function(browser) {
windowActorOptions.remoteTypes = ["privileged"];
ChromeUtils.registerWindowActor("Test", windowActorOptions);
let parent = browser.browsingContext.currentWindowGlobal;
Assert.throws(() => parent.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/, "Should throw if its remoteTypes don't match.");
await ContentTask.spawn(
browser, {}, async function() {
let child = content.window.getWindowGlobalChild();
ok(child, "WindowGlobalChild should have value.");
Assert.throws(() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/, "Should throw if its remoteTypes don't match.");
});
teardown();
});
});
add_task(async function test_getActor_without_allFrames() {
await BrowserTestUtils.withNewTab({gBrowser, url: URL},
async function(browser) {