Bug 1527753 - Part 2: Add test for restricting JS Window Actors to specific remoteTypes; r=nika
authorJohn Dai <jdai@mozilla.com>
Wed, 27 Mar 2019 14:54:15 +0000
changeset 466381 28c8708ee20e51213d529de7f6a5a2fe96ed62d2
parent 466380 99c4c6989e06ed8597cc570df993129821e095b2
child 466382 79f99b532456a7d5b31537cd9d7db92cfc3654d7
push id35768
push useropoprus@mozilla.com
push dateThu, 28 Mar 2019 09:55:54 +0000
treeherdermozilla-central@c045dd97faf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1527753
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527753 - Part 2: Add test for restricting JS Window Actors to specific remoteTypes; r=nika Differential Revision: https://phabricator.services.mozilla.com/D25052
dom/ipc/tests/browser_JSWindowActor.js
--- a/dom/ipc/tests/browser_JSWindowActor.js
+++ b/dom/ipc/tests/browser_JSWindowActor.js
@@ -19,16 +19,17 @@ let windowActorOptions = {
       "test-js-window-actor-child-observer",
     ],
   },
 };
 
 function teardown() {
   windowActorOptions.allFrames = false;
   delete windowActorOptions.matches;
+  delete windowActorOptions.remoteTypes;
   ChromeUtils.unregisterWindowActor("Test");
 }
 
 add_task(function test_registerWindowActor() {
   ok(ChromeUtils, "Should be able to get the ChromeUtils interface");
   ChromeUtils.registerWindowActor("Test", windowActorOptions);
   SimpleTest.doesThrow(() =>
     ChromeUtils.registerWindowActor("Test", windowActorOptions),
@@ -291,16 +292,56 @@ add_task(async function test_getActor_wi
           let child = frame.contentWindow.window.getWindowGlobalChild();
           Assert.throws(() => child.getActor("Test"),
             /NS_ERROR_NOT_AVAILABLE/, "Should throw if it doesn't match.");
         });
       teardown();
     });
 });
 
+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) {
       windowActorOptions.allFrames = false;
       ChromeUtils.registerWindowActor("Test", windowActorOptions);
 
       await ContentTask.spawn(
         browser, {}, async function() {