Bug 1067424 - Test for webapps actor getAppActor method. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 18 Sep 2014 05:44:00 -0400
changeset 206480 62bec3669030a90ca8c72e3fbdeb5ffb74deed1f
parent 206479 9e88f96e430fdfd9db73daec11cbd957dd21a00f
child 206481 e42e0e8f37912d4c10f3bac1a6dac6ad630ad3cc
push id27528
push userryanvm@gmail.com
push dateMon, 22 Sep 2014 19:27:54 +0000
treeherdermozilla-central@d8688cafc752 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1067424
milestone35.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 1067424 - Test for webapps actor getAppActor method. r=jryans
toolkit/devtools/apps/tests/debugger-protocol-helper.js
toolkit/devtools/apps/tests/test_webapps_actor.html
toolkit/devtools/server/actors/webapps.js
toolkit/devtools/server/child.js
--- a/toolkit/devtools/apps/tests/debugger-protocol-helper.js
+++ b/toolkit/devtools/apps/tests/debugger-protocol-helper.js
@@ -2,16 +2,19 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
 const { DebuggerClient } = Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
+const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
+const {require} = devtools;
+
 
 const { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm");
 const { Services } = Cu.import("resource://gre/modules/Services.jsm");
 
 let gClient, gActor;
 
 function connect(onDone) {
 
@@ -109,14 +112,51 @@ addMessageListener("install", function (
     webappActorRequest(request, function (aResponse) {
       sendAsyncMessage("installed", aResponse);
     });
   } catch(e) {
     dump("installTestApp exception: " + e + "\n");
   }
 });
 
+addMessageListener("getAppActor", function (aMessage) {
+  let { manifestURL } = aMessage;
+  let request = {type: "getAppActor", manifestURL: manifestURL};
+  webappActorRequest(request, function (aResponse) {
+    sendAsyncMessage("appActor", aResponse);
+  });
+});
+
+let Frames = [];
+addMessageListener("addFrame", function (aMessage) {
+  let win = Services.wm.getMostRecentWindow("navigator:browser");
+  let doc = win.document;
+  let frame = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe");
+  frame.setAttribute("mozbrowser", "true");
+  if (aMessage.mozapp) {
+    frame.setAttribute("mozapp", aMessage.mozapp);
+  }
+  if (aMessage.remote) {
+    frame.setAttribute("remote", aMessage.remote);
+  }
+  if (aMessage.src) {
+    frame.setAttribute("src", aMessage.src);
+  }
+  doc.documentElement.appendChild(frame);
+  Frames.push(frame);
+  sendAsyncMessage("frameAdded");
+});
+
 addMessageListener("cleanup", function () {
   webappActorRequest({type: "unwatchApps"}, function () {
     gClient.close();
   });
 });
 
+let AppFramesMock = {
+  list: function () {
+    return Frames;
+  },
+  addObserver: function () {},
+  removeObserver: function () {}
+};
+
+require("devtools/server/actors/webapps").setAppFramesMock(AppFramesMock);
--- a/toolkit/devtools/apps/tests/test_webapps_actor.html
+++ b/toolkit/devtools/apps/tests/test_webapps_actor.html
@@ -220,16 +220,31 @@ var steps = [
       manifestURL: CERTIFIED_APP_MANIFEST
     }, true);
   },
   function() {
     info("== SETUP == Disable certified app access");
     SpecialPowers.popPrefEnv(next);
   },
   function() {
+    info("== TEST == Get packaged app actor");
+    addFrame(
+      { mozapp: PACKAGED_APP_MANIFEST, remote: true },
+      function () {
+        getAppActor(PACKAGED_APP_MANIFEST, function (response) {
+          let tabActor = response.actor;
+          ok(!!tabActor, "TabActor is correctly instanciated in child.js");
+          ok("actor" in tabActor, "Tab actor is available in child");
+          ok("consoleActor" in tabActor, "Console actor is available in child");
+          next();
+        });
+      });
+
+  },
+  function() {
     info("== TEST == Uninstall packaged app");
     uninstall(PACKAGED_APP_MANIFEST);
   },
   function() {
     info("== TEST == Uninstall certified app");
     uninstall(CERTIFIED_APP_MANIFEST);
   },
   function() {
@@ -304,12 +319,28 @@ function uninstall(manifestURL) {
   });
 
   mm.sendAsyncMessage("appActorRequest", {
     type: "uninstall",
     manifestURL: manifestURL
   });
 }
 
+function getAppActor(manifestURL, callback) {
+  mm.addMessageListener("appActor", function onAppActor(aResponse) {
+    mm.removeMessageListener("appActor", onAppActor);
+    callback(aResponse);
+  });
+  mm.sendAsyncMessage("getAppActor", { manifestURL: manifestURL });
+}
+
+function addFrame(options, callback) {
+  mm.addMessageListener("frameAdded", function onFrameAdded() {
+    mm.removeMessageListener("frameAdded", onFrameAdded);
+    callback();
+  });
+  mm.sendAsyncMessage("addFrame", options);
+}
+
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/devtools/server/actors/webapps.js
+++ b/toolkit/devtools/server/actors/webapps.js
@@ -20,16 +20,20 @@ let Services = require("Services");
 
 let AppFramesMock = null;
 
 exports.setAppFramesMock = function (mock) {
   AppFramesMock = mock;
 }
 
 DevToolsUtils.defineLazyGetter(this, "AppFrames", () => {
+  // Offer a way for unit test to provide a mock
+  if (AppFramesMock) {
+    return AppFramesMock;
+  }
   try {
     return Cu.import("resource://gre/modules/AppFrames.jsm", {}).AppFrames;
   } catch(e) {}
   return null;
 });
 
 function debug(aMsg) {
   /*
--- a/toolkit/devtools/server/child.js
+++ b/toolkit/devtools/server/child.js
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+try {
+
 let chromeGlobal = this;
 
 // Encapsulate in its own scope to allows loading this frame script
 // more than once.
 (function () {
   let Cu = Components.utils;
   let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
   const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js");
@@ -59,8 +61,12 @@ let chromeGlobal = this;
     let conn = connections.get(childID);
     if (conn) {
       conn.close();
       connections.delete(childID);
     }
   });
   addMessageListener("debug:disconnect", onDisconnect);
 })();
+
+} catch(e) {
+  dump("Exception in app child process: " + e + "\n");
+}