Bug 792647 - Wait for system-message-listener-ready on B2G before returning during newSession, r=philikon, DONTBUILD, a=NPOTB
authorJonathan Griffin <jgriffin@mozilla.com>
Tue, 16 Oct 2012 16:33:55 -0700
changeset 116615 2ca4c7e6f6ce01f1cff5a267ec96ccd8cb0d2a6e
parent 116614 5da108186d3305a70bb4a478da4ce96cee7541b9
child 116616 fa9d3e13e47399cd49a49c4e21ee596e32bbd29c
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon, DONTBUILD, NPOTB
bugs792647
milestone18.0a2
Bug 792647 - Wait for system-message-listener-ready on B2G before returning during newSession, r=philikon, DONTBUILD, a=NPOTB
testing/marionette/marionette-actors.js
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -36,16 +36,25 @@ Cu.import("resource://gre/modules/NetUti
 Services.prefs.setBoolPref("marionette.contentListener", false);
 let appName = Services.appinfo.name;
 
 // import logger
 Cu.import("resource:///modules/services-common/log4moz.js");
 let logger = Log4Moz.repository.getLogger("Marionette");
 logger.info('marionette-actors.js loaded');
 
+// This is used to prevent newSession from returning before the telephony
+// API's are ready; see bug 792647.  This assumes that marionette-actors.js
+// will be loaded before the 'system-message-listener-ready' message
+// is fired.  If this stops being true, this approach will have to change.
+let systemMessageListenerReady = false;
+Services.obs.addObserver(function() {
+  systemMessageListenerReady = true;
+}, "system-message-listener-ready", false);
+
 /**
  * Creates the root actor once a connection is established
  */
 
 function createRootActor(aConnection)
 {
   return new MarionetteRootActor(aConnection);
 }
@@ -433,17 +442,20 @@ MarionetteDriverActor.prototype = {
    * the client to test in.
    *
    */
   newSession: function MDA_newSession() {
 
     function waitForWindow() {
       let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
       let win = this.getCurrentWindow();
-      if (!win || (appName == "Firefox" && !win.gBrowser) || (appName == "Fennec" && !win.BrowserApp)) { 
+      if (!win ||
+          (appName == "Firefox" && !win.gBrowser) ||
+          (appName == "Fennec" && !win.BrowserApp) ||
+          (appName == "B2G" && !systemMessageListenerReady)) { 
         checkTimer.initWithCallback(waitForWindow.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
       }
       else {
         this.startBrowser(win, true);
       }
     }
 
     this.switchToGlobalMessageManager();