Bug 1497644 - Ensure that RootClient is used for all requests made to the root actor. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 11 Oct 2018 16:25:23 +0000
changeset 489094 eaf50a59155d0bef730fc4b48038589297860fc2
parent 489093 9b6dac8e39db00a7a5739c05f0b868e2fd88efb5
child 489095 3a7632140ea5c04fed23b206f3dacf8e83719e86
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersyulia
bugs1497644
milestone64.0a1
Bug 1497644 - Ensure that RootClient is used for all requests made to the root actor. r=yulia MozReview-Commit-ID: HJm7yQCMbkg Depends on D8141 Differential Revision: https://phabricator.services.mozilla.com/D8142
devtools/server/tests/unit/test_forwardingprefix.js
devtools/server/tests/unit/test_protocolSpec.js
devtools/server/tests/unit/test_requestTypes.js
devtools/shared/client/root-client.js
devtools/shared/security/tests/chrome/test_websocket-transport.html
devtools/shared/security/tests/unit/test_encryption.js
devtools/shared/security/tests/unit/test_oob_cert_auth.js
--- a/devtools/server/tests/unit/test_forwardingprefix.js
+++ b/devtools/server/tests/unit/test_forwardingprefix.js
@@ -78,32 +78,37 @@ function tryActors(reachables, completed
     /*
      * Let each callback capture its own iteration's value; outerActor is
      * local to the whole loop, not to a single iteration.
      */
     const actor = outerActor;
 
     count++;
 
+    let promise;
     // phone home
-    gClient.request(
-      { to: actor, type: "echo", value: "tango"},
-      (response) => {
-        if (reachables.has(actor)) {
-          Assert.deepEqual({ from: actor, to: actor,
-                             type: "echo", value: "tango" }, response);
-        } else {
-          Assert.deepEqual({ from: actor, error: "noSuchActor",
-                             message: "No such actor for ID: " + actor }, response);
-        }
+    if (actor == "root") {
+      promise = gClient.mainRoot.echo({ value: "tango" });
+    } else {
+      promise = gClient.request({ to: actor, type: "echo", value: "tango"});
+    }
+    const callback = (response) => {
+      if (reachables.has(actor)) {
+        Assert.deepEqual({ from: actor, to: actor,
+                           type: "echo", value: "tango" }, response);
+      } else {
+        Assert.deepEqual({ from: actor, error: "noSuchActor",
+                           message: "No such actor for ID: " + actor }, response);
+      }
 
-        if (--count == 0) {
-          executeSoon(completed, "tryActors callback " + completed.name);
-        }
-      });
+      if (--count == 0) {
+        executeSoon(completed, "tryActors callback " + completed.name);
+      }
+    };
+    promise.then(callback, callback);
   }
 }
 
 /*
  * With no forwarding established, sending messages to root should work,
  * but sending messages to prefixed actor names, or anyone else, should get
  * an error.
  */
--- a/devtools/server/tests/unit/test_protocolSpec.js
+++ b/devtools/server/tests/unit/test_protocolSpec.js
@@ -2,18 +2,15 @@
 
 const run_test = Test(async function() {
   initTestDebuggerServer();
   const connection = DebuggerServer.connectPipe();
   const client = Async(new DebuggerClient(connection));
 
   await client.connect();
 
-  const response = await client.request({
-    to: "root",
-    type: "protocolDescription"
-  });
+  const response = await client.mainRoot.protocolDescription();
 
   assert(response.from == "root");
   assert(typeof (response.types) === "object");
 
   await client.close();
 });
--- a/devtools/server/tests/unit/test_requestTypes.js
+++ b/devtools/server/tests/unit/test_requestTypes.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { RootActor } = require("devtools/server/actors/root");
 
 function test_requestTypes_request(client, anActor) {
-  client.request({ to: "root", type: "requestTypes" }, function(response) {
+  client.mainRoot.requestTypes().then(function(response) {
     const expectedRequestTypes = Object.keys(RootActor
                                            .prototype
                                            .requestTypes);
 
     Assert.ok(Array.isArray(response.requestTypes));
     Assert.equal(JSON.stringify(response.requestTypes),
                  JSON.stringify(expectedRequestTypes));
 
--- a/devtools/shared/client/root-client.js
+++ b/devtools/shared/client/root-client.js
@@ -305,16 +305,36 @@ RootClient.prototype = {
   /**
    * Description of protocol's actors and methods.
    *
    * @param function onResponse
    *        Called with the response packet.
    */
   protocolDescription: DebuggerClient.requester({ type: "protocolDescription" }),
 
+  /**
+   * Special request, actually supported by all actors to retrieve the list of all
+   * the request names supported by this actor.
+   */
+  requestTypes: DebuggerClient.requester({ type: "requestTypes" }),
+
+  /**
+   * Test request that returns the object passed as first argument.
+   *
+   * `echo` is special as all the property of the given object have to be passed
+   * on the packet object. That's not something that can be achieve by requester helper.
+   */
+  echo(object) {
+    const packet = Object.assign(object, {
+      to: this.actor,
+      type: "echo",
+    });
+    return this.request(packet);
+  },
+
   /*
    * Methods constructed by DebuggerClient.requester require these forwards
    * on their 'this'.
    */
   get _transport() {
     return this._client._transport;
   },
   get request() {
--- a/devtools/shared/security/tests/chrome/test_websocket-transport.html
+++ b/devtools/shared/security/tests/chrome/test_websocket-transport.html
@@ -51,21 +51,17 @@ window.onload = function() {
     };
     client.addListener("closed", onUnexpectedClose);
 
     await client.connect();
     await client.listTabs();
 
     // Send a message the server that will echo back
     const message = "message";
-    const reply = await client.request({
-      to: "root",
-      type: "echo",
-      message
-    });
+    const reply = await client.mainRoot.echo({ message });
     is(reply.message, message, "Echo message matches");
 
     client.removeListener("closed", onUnexpectedClose);
     transport.close();
     listener.close();
     is(DebuggerServer.listeningSockets, 0, "0 listening sockets");
 
     DebuggerServer.destroy();
--- a/devtools/shared/security/tests/unit/test_encryption.js
+++ b/devtools/shared/security/tests/unit/test_encryption.js
@@ -49,21 +49,17 @@ add_task(async function() {
   const onUnexpectedClose = () => {
     do_throw("Closed unexpectedly");
   };
   client.addListener("closed", onUnexpectedClose);
   await connectClient(client);
 
   // Send a message the server will echo back
   const message = "secrets";
-  const reply = await client.request({
-    to: "root",
-    type: "echo",
-    message
-  });
+  const reply = await client.mainRoot.echo({ message });
   equal(reply.message, message, "Encrypted echo matches");
 
   client.removeListener("closed", onUnexpectedClose);
   transport.close();
   listener.close();
   equal(DebuggerServer.listeningSockets, 0, "0 listening sockets");
 });
 
--- a/devtools/shared/security/tests/unit/test_oob_cert_auth.js
+++ b/devtools/shared/security/tests/unit/test_oob_cert_auth.js
@@ -71,21 +71,17 @@ add_task(async function() {
   const onUnexpectedClose = () => {
     do_throw("Closed unexpectedly");
   };
   client.addListener("closed", onUnexpectedClose);
   await connectClient(client);
 
   // Send a message the server will echo back
   const message = "secrets";
-  const reply = await client.request({
-    to: "root",
-    type: "echo",
-    message
-  });
+  const reply = await client.mainRoot.echo({ message });
   equal(reply.message, message, "Encrypted echo matches");
 
   client.removeListener("closed", onUnexpectedClose);
   transport.close();
   listener.close();
   equal(DebuggerServer.listeningSockets, 0, "0 listening sockets");
 });