bug 856232 - let addons add DebuggerServer actors anytime; r=past,dcamp
authorMyk Melez <myk@mozilla.org>
Fri, 03 May 2013 18:21:48 -0700
changeset 141764 e65f2839b0a29a15ba56ae7e75fccf3930c9506d
parent 141763 8e05ccbcb09b9069e5f0d562f1293f292d3f9962
child 141765 c097ee28852a052902fcd2ca6721757ad370ef75
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast, dcamp
bugs856232, 100644
milestone23.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 856232 - let addons add DebuggerServer actors anytime; r=past,dcamp --- toolkit/devtools/debugger/server/dbg-server.js | 15 ++-- .../debugger/tests/unit/post_init_global_actors.js | 17 +++++ .../debugger/tests/unit/post_init_tab_actors.js | 17 +++++ .../debugger/tests/unit/pre_init_global_actors.js | 17 +++++ .../debugger/tests/unit/pre_init_tab_actors.js | 17 +++++ .../debugger/tests/unit/test_add_actors.js | 82 ++++++++++++++++++++++ toolkit/devtools/debugger/tests/unit/xpcshell.ini | 1 + 7 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 toolkit/devtools/debugger/tests/unit/post_init_global_actors.js create mode 100644 toolkit/devtools/debugger/tests/unit/post_init_tab_actors.js create mode 100644 toolkit/devtools/debugger/tests/unit/pre_init_global_actors.js create mode 100644 toolkit/devtools/debugger/tests/unit/pre_init_tab_actors.js create mode 100644 toolkit/devtools/debugger/tests/unit/test_add_actors.js
toolkit/devtools/debugger/server/dbg-server.js
toolkit/devtools/debugger/tests/unit/post_init_global_actors.js
toolkit/devtools/debugger/tests/unit/post_init_tab_actors.js
toolkit/devtools/debugger/tests/unit/pre_init_global_actors.js
toolkit/devtools/debugger/tests/unit/pre_init_tab_actors.js
toolkit/devtools/debugger/tests/unit/test_add_actors.js
toolkit/devtools/debugger/tests/unit/xpcshell.ini
--- a/toolkit/devtools/debugger/server/dbg-server.js
+++ b/toolkit/devtools/debugger/server/dbg-server.js
@@ -48,24 +48,25 @@ const ServerSocket = CC("@mozilla.org/ne
                         "nsIServerSocket",
                         "initSpecialConnection");
 
 /***
  * Public API
  */
 var DebuggerServer = {
   _listener: null,
+  _initialized: false,
   _transportInitialized: false,
   xpcInspector: null,
   // Number of currently open TCP connections.
   _socketConnections: 0,
   // Map of global actor names to actor constructors provided by extensions.
-  globalActorFactories: null,
+  globalActorFactories: {},
   // Map of tab actor names to actor constructors provided by extensions.
-  tabActorFactories: null,
+  tabActorFactories: {},
 
   LONG_STRING_LENGTH: 10000,
   LONG_STRING_INITIAL_LENGTH: 1000,
 
   /**
    * A handler function that prompts the user to accept or decline the incoming
    * connection.
    */
@@ -110,18 +111,17 @@ var DebuggerServer = {
     if (this.initialized) {
       return;
     }
 
     this.xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
     this.initTransport(aAllowConnectionCallback);
     this.addActors("chrome://global/content/devtools/dbg-script-actors.js");
 
-    this.globalActorFactories = {};
-    this.tabActorFactories = {};
+    this._initialized = true;
   },
 
   /**
    * Initialize the debugger server's transport variables.  This can be
    * in place of init() for cases where the jsdebugger isn't needed.
    *
    * @param function aAllowConnectionCallback
    *        The embedder-provider callback, that decides whether an incoming
@@ -135,32 +135,33 @@ var DebuggerServer = {
     this._connections = {};
     this._nextConnID = 0;
     this._transportInitialized = true;
     this._allowConnection = aAllowConnectionCallback ?
                             aAllowConnectionCallback :
                             this._defaultAllowConnection;
   },
 
-  get initialized() { return !!this.globalActorFactories; },
+  get initialized() this._initialized,
 
   /**
    * Performs cleanup tasks before shutting down the debugger server, if no
    * connections are currently open. Such tasks include clearing any actor
    * constructors added at runtime. This method should be called whenever a
    * debugger server is no longer useful, to avoid memory leaks. After this
    * method returns, the debugger server must be initialized again before use.
    */
   destroy: function DS_destroy() {
     if (Object.keys(this._connections).length == 0) {
       this.closeListener();
-      delete this.globalActorFactories;
-      delete this.tabActorFactories;
+      this.globalActorFactories = {};
+      this.tabActorFactories = {};
       delete this._allowConnection;
       this._transportInitialized = false;
+      this._initialized = false;
       dumpn("Debugger server is shut down.");
     }
   },
 
   /**
    * Load a subscript into the debugging global.
    *
    * @param aURL string A url that will be loaded as a subscript into the
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/tests/unit/post_init_global_actors.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function PostInitGlobalActor(aConnection) {}
+
+PostInitGlobalActor.prototype = {
+  actorPrefix: "postInitGlobal",
+  onPing: function onPing(aRequest) {
+    return { message: "pong" };
+  },
+};
+
+PostInitGlobalActor.prototype.requestTypes = {
+  "ping": PostInitGlobalActor.prototype.onPing,
+};
+
+DebuggerServer.addGlobalActor(PostInitGlobalActor, "postInitGlobalActor");
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/tests/unit/post_init_tab_actors.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function PostInitTabActor(aConnection) {}
+
+PostInitTabActor.prototype = {
+  actorPostfix: "postInitTab",
+  onPing: function onPing(aRequest) {
+    return { message: "pong" };
+  },
+};
+
+PostInitTabActor.prototype.requestTypes = {
+  "ping": PostInitTabActor.prototype.onPing,
+};
+
+DebuggerServer.addGlobalActor(PostInitTabActor, "postInitTabActor");
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/tests/unit/pre_init_global_actors.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function PreInitGlobalActor(aConnection) {}
+
+PreInitGlobalActor.prototype = {
+  actorPrefix: "preInitGlobal",
+  onPing: function onPing(aRequest) {
+    return { message: "pong" };
+  },
+};
+
+PreInitGlobalActor.prototype.requestTypes = {
+  "ping": PreInitGlobalActor.prototype.onPing,
+};
+
+DebuggerServer.addGlobalActor(PreInitGlobalActor, "preInitGlobalActor");
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/tests/unit/pre_init_tab_actors.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function PreInitTabActor(aConnection) {}
+
+PreInitTabActor.prototype = {
+  actorPrefix: "preInitTab",
+  onPing: function onPing(aRequest) {
+    return { message: "pong" };
+  },
+};
+
+PreInitTabActor.prototype.requestTypes = {
+  "ping": PreInitTabActor.prototype.onPing,
+};
+
+DebuggerServer.addGlobalActor(PreInitTabActor, "preInitTabActor");
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/tests/unit/test_add_actors.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var gClient;
+var gActors;
+
+/**
+ * The purpose of these tests is to verify that it's possible to add actors
+ * both before and after the DebuggerServer has been initialized, so addons
+ * that add actors don't have to poll the object for its initialization state
+ * in order to add actors after initialization but rather can add actors anytime
+ * regardless of the object's state.
+ */
+function run_test()
+{
+  DebuggerServer.addActors("resource://test/pre_init_global_actors.js");
+  DebuggerServer.addActors("resource://test/pre_init_tab_actors.js");
+
+  DebuggerServer.init(function () { return true; });
+  DebuggerServer.addBrowserActors();
+
+  DebuggerServer.addActors("resource://test/post_init_global_actors.js");
+  DebuggerServer.addActors("resource://test/post_init_tab_actors.js");
+
+  add_test(init);
+  add_test(test_pre_init_global_actor);
+  add_test(test_pre_init_tab_actor);
+  add_test(test_post_init_global_actor);
+  add_test(test_post_init_tab_actor);
+  run_next_test();
+}
+
+function init()
+{
+  gClient = new DebuggerClient(DebuggerServer.connectPipe());
+  gClient.connect(function onConnect() {
+    gClient.listTabs(function onListTabs(aResponse) {
+      gActors = aResponse;
+      run_next_test();
+    });
+  });
+}
+
+function test_pre_init_global_actor()
+{
+  gClient.request({ to: gActors.preInitGlobalActor, type: "ping" },
+    function onResponse(aResponse) {
+      do_check_eq(aResponse.message, "pong");
+      run_next_test();
+    }
+  );
+}
+
+function test_pre_init_tab_actor()
+{
+  gClient.request({ to: gActors.preInitTabActor, type: "ping" },
+    function onResponse(aResponse) {
+      do_check_eq(aResponse.message, "pong");
+      run_next_test();
+    }
+  );
+}
+
+function test_post_init_global_actor()
+{
+  gClient.request({ to: gActors.postInitGlobalActor, type: "ping" },
+    function onResponse(aResponse) {
+      do_check_eq(aResponse.message, "pong");
+      run_next_test();
+    }
+  );
+}
+
+function test_post_init_tab_actor()
+{
+  gClient.request({ to: gActors.postInitTabActor, type: "ping" },
+    function onResponse(aResponse) {
+      do_check_eq(aResponse.message, "pong");
+      run_next_test();
+    }
+  );
+}
--- a/toolkit/devtools/debugger/tests/unit/xpcshell.ini
+++ b/toolkit/devtools/debugger/tests/unit/xpcshell.ini
@@ -115,8 +115,9 @@ reason = bug 820380
 [test_source-01.js]
 skip-if = toolkit == "gonk"
 reason = bug 820380
 [test_breakpointstore.js]
 [test_profiler_actor.js]
 skip-if = toolkit == "gonk"
 reason = bug 820380
 [test_unsafeDereference.js]
+[test_add_actors.js]