From f78ea8ee85ac86e9a4a87483f6a814fb697ea8dd Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Tue, 20 Oct 2020 20:48:54 +0000 Subject: [PATCH] Bug 1671676 - [devtools] Update browser_setupInParentChild.js to only test setupInParent r=ochameau Depends on D93821 Differential Revision: https://phabricator.services.mozilla.com/D93822 --- devtools/server/tests/browser/browser.ini | 4 +- .../browser/browser_setupInParentChild.js | 76 ------------------- .../tests/browser/browser_setup_in_parent.js | 52 +++++++++++++ .../server/tests/browser/setup-in-child.js | 23 ------ .../tests/browser/test-setup-in-parent.js | 33 ++++++++ 5 files changed, 87 insertions(+), 101 deletions(-) delete mode 100644 devtools/server/tests/browser/browser_setupInParentChild.js create mode 100644 devtools/server/tests/browser/browser_setup_in_parent.js delete mode 100644 devtools/server/tests/browser/setup-in-child.js create mode 100644 devtools/server/tests/browser/test-setup-in-parent.js diff --git a/devtools/server/tests/browser/browser.ini b/devtools/server/tests/browser/browser.ini index 2bb10e0c548b..cf8a4ee67b09 100644 --- a/devtools/server/tests/browser/browser.ini +++ b/devtools/server/tests/browser/browser.ini @@ -42,10 +42,10 @@ support-files = storage-secured-iframe.html stylesheets-nested-iframes.html test-errors-actor.js + test-setup-in-parent.js test-spawn-actor-in-parent.js test-window.xhtml inspector-helpers.js - setup-in-child.js setup-in-parent.js storage-helpers.js !/devtools/client/shared/test/shared-head.js @@ -153,7 +153,7 @@ skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still di skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S [browser_perf-samples-01.js] [browser_perf-samples-02.js] -[browser_setupInParentChild.js] +[browser_setup_in_parent.js] [browser_spawn_actor_in_parent.js] [browser_storage_browser_toolbox_indexeddb.js] [browser_storage_cookies-duplicate-names.js] diff --git a/devtools/server/tests/browser/browser_setupInParentChild.js b/devtools/server/tests/browser/browser_setupInParentChild.js deleted file mode 100644 index 0fe7b54e2cb5..000000000000 --- a/devtools/server/tests/browser/browser_setupInParentChild.js +++ /dev/null @@ -1,76 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Bug 1181100 - Test DevToolsServerConnection.setupInParent and DevToolsServer.setupInChild - */ - -"use strict"; - -const { - connectToFrame, -} = require("devtools/server/connectors/frame-connector"); - -add_task(async () => { - // Create a minimal browser with a message manager - const browser = document.createXULElement("browser"); - browser.setAttribute("type", "content"); - document.body.appendChild(browser); - - // Instantiate a minimal server - DevToolsServer.init(); - if (!DevToolsServer.createRootActor) { - DevToolsServer.registerAllActors(); - } - - // Fake a connection to an iframe - const transport = DevToolsServer.connectPipe(); - const conn = transport._serverConnection; - const client = new DevToolsClient(transport); - - // Wait for a response from setupInChild - const onChild = msg => { - Services.ppmm.removeMessageListener("test:setupChild", onChild); - const args = msg.json; - - is(args[0], 1, "Got first numeric argument"); - is(args[1], "two", "Got second string argument"); - is(args[2].three, true, "Got last JSON argument"); - - // Ask the child to call setupInParent - DevToolsServer.setupInChild({ - module: - "chrome://mochitests/content/browser/devtools/server/tests/browser/setup-in-child.js", - setupChild: "callParent", - }); - }; - Services.ppmm.addMessageListener("test:setupChild", onChild); - - // Wait also for a reponse from setupInParent called from setup-in-child.js - const onDone = new Promise(resolve => { - const onParent = (_, topic, args) => { - Services.obs.removeObserver(onParent, "test:setupParent"); - args = JSON.parse(args); - - is(args[0], true, "Got `mm` argument, a message manager"); - ok(args[1].match(/server\d+.conn\d+.child\d+/), "Got `prefix` argument"); - - resolve(); - }; - Services.obs.addObserver(onParent, "test:setupParent"); - }); - - // Instanciate e10s machinery and call setupInChild - await connectToFrame(conn, browser); - DevToolsServer.setupInChild({ - module: - "chrome://mochitests/content/browser/devtools/server/tests/browser/setup-in-child.js", - setupChild: "setupChild", - args: [1, "two", { three: true }], - }); - await onDone; - - await client.close(); - DevToolsServer.destroy(); - browser.remove(); -}); diff --git a/devtools/server/tests/browser/browser_setup_in_parent.js b/devtools/server/tests/browser/browser_setup_in_parent.js new file mode 100644 index 000000000000..fa09cf6b6eee --- /dev/null +++ b/devtools/server/tests/browser/browser_setup_in_parent.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const ACTOR_URL = + "chrome://mochitests/content/browser/devtools/server/tests/browser/test-setup-in-parent.js"; + +const { TestSetupInParentFront } = require(ACTOR_URL); + +add_task(async function() { + const browser = await addTab("data:text/html;charset=utf-8,foo"); + + info("Register target-scoped actor in the content process"); + await registerActorInContentProcess(ACTOR_URL, { + prefix: "testSetupInParent", + constructor: "TestSetupInParentActor", + type: { target: true }, + }); + + const tab = gBrowser.getTabForBrowser(browser); + const target = await TargetFactory.forTab(tab); + await target.attach(); + const { client } = target; + const form = target.targetForm; + + // As this Front isn't instantiated by protocol.js, we have to manually + // set its actor ID and manage it: + const front = new TestSetupInParentFront(client); + front.actorID = form.testSetupInParentActor; + front.manage(front); + + // Wait also for a reponse from setupInParent called from setup-in-child.js + const onDone = new Promise(resolve => { + const onParent = (_, topic, args) => { + Services.obs.removeObserver(onParent, "test:setupParent"); + args = JSON.parse(args); + + is(args[0], true, "Got `mm` argument, a message manager"); + ok(args[1].match(/server\d+.conn\d+.child\d+/), "Got `prefix` argument"); + + resolve(); + }; + Services.obs.addObserver(onParent, "test:setupParent"); + }); + + await front.callSetupInParent(); + await onDone; + + await target.destroy(); + gBrowser.removeCurrentTab(); +}); diff --git a/devtools/server/tests/browser/setup-in-child.js b/devtools/server/tests/browser/setup-in-child.js deleted file mode 100644 index c06133b56d03..000000000000 --- a/devtools/server/tests/browser/setup-in-child.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; - -const { Cc } = require("chrome"); -const cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(); -const { DevToolsServer } = require("devtools/server/devtools-server"); - -exports.setupChild = function(a, b, c) { - cpmm.sendAsyncMessage("test:setupChild", [a, b, c]); -}; - -exports.callParent = function() { - // Hack! Fetch DevToolsServerConnection objects directly within DevToolsServer guts. - for (const id in DevToolsServer._connections) { - const conn = DevToolsServer._connections[id]; - // eslint-disable-next-line no-restricted-properties - conn.setupInParent({ - module: - "chrome://mochitests/content/browser/devtools/server/tests/browser/setup-in-parent.js", - setupParent: "setupParent", - args: [{ one: true }, 2, "three"], - }); - } -}; diff --git a/devtools/server/tests/browser/test-setup-in-parent.js b/devtools/server/tests/browser/test-setup-in-parent.js new file mode 100644 index 000000000000..2d2d9858b265 --- /dev/null +++ b/devtools/server/tests/browser/test-setup-in-parent.js @@ -0,0 +1,33 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const { FrontClassWithSpec } = protocol; + +const spec = protocol.generateActorSpec({ + typeName: "testSetupInParent", + + methods: { + callSetupInParent: { + request: {}, + response: {}, + }, + }, +}); + +exports.TestSetupInParentActor = protocol.ActorClassWithSpec(spec, { + callSetupInParent: async function() { + // eslint-disable-next-line no-restricted-properties + this.conn.setupInParent({ + module: + "chrome://mochitests/content/browser/devtools/server/tests/browser/setup-in-parent.js", + setupParent: "setupParent", + args: [{ one: true }, 2, "three"], + }); + }, +}); + +class TestSetupInParentFront extends FrontClassWithSpec(spec) {} +exports.TestSetupInParentFront = TestSetupInParentFront;