Bug 870445 - Add -marionette command-line arg to Firefox, r=mdas
authorDavid Burns <dburns@mozilla.com>
Mon, 13 May 2013 13:43:15 +0100
changeset 145921 d9508c92f3cc0be5c8470741a532c7397a128677
parent 145920 3854819a064bfaa32615305d287f505984d2ab13
child 145922 9e310bf47f507943e35978c693a9d0eb92d9deb0
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs870445
milestone24.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 870445 - Add -marionette command-line arg to Firefox, r=mdas
browser/installer/package-manifest.in
testing/marionette/components/Makefile.in
testing/marionette/components/MarionetteComponents.manifest
testing/marionette/components/marionettecomponent.js
testing/marionette/moz.build
toolkit/toolkit.mozbuild
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -523,22 +523,20 @@
 @BINPATH@/components/AppProtocolHandler.js
 @BINPATH@/components/AppProtocolHandler.manifest
 
 #ifdef MOZ_WEBRTC
 @BINPATH@/components/PeerConnection.js
 @BINPATH@/components/PeerConnection.manifest
 #endif
 
-#ifdef ENABLE_MARIONETTE
 @BINPATH@/chrome/marionette@JAREXT@
 @BINPATH@/chrome/marionette.manifest
 @BINPATH@/components/MarionetteComponents.manifest
 @BINPATH@/components/marionettecomponent.js
-#endif
 
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
 ; Modules
 @BINPATH@/browser/modules/*
 @BINPATH@/modules/*
--- a/testing/marionette/components/Makefile.in
+++ b/testing/marionette/components/Makefile.in
@@ -4,14 +4,18 @@
 
 DEPTH = @DEPTH@
 topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
+ifdef ENABLE_MARIONETTE
+DEFINES += -DENABLE_MARIONETTE=1
+endif
+
 EXTRA_PP_COMPONENTS = \
-        MarionetteComponents.manifest \
-        marionettecomponent.js \
-        $(NULL)
+    MarionetteComponents.manifest \
+    marionettecomponent.js \
+    $(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/testing/marionette/components/MarionetteComponents.manifest
+++ b/testing/marionette/components/MarionetteComponents.manifest
@@ -1,4 +1,5 @@
 # Marionette
 component {786a1369-dca5-4adc-8486-33d23c88010a} marionettecomponent.js
 contract @mozilla.org/marionette;1 {786a1369-dca5-4adc-8486-33d23c88010a}
+category command-line-handler b-marionette @mozilla.org/marionette;1
 category profile-after-change MarionetteComponent @mozilla.org/marionette;1
--- a/testing/marionette/components/marionettecomponent.js
+++ b/testing/marionette/components/marionettecomponent.js
@@ -17,102 +17,128 @@ const ServerSocket = CC("@mozilla.org/ne
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/services-common/log4moz.js");
 
 function MarionetteComponent() {
   this._loaded = false;
+  this.observerService = Services.obs;
+
   // set up the logger
   this.logger = Log4Moz.repository.getLogger("Marionette");
-  this.logger.level = Log4Moz.Level["INFO"];
+  this.logger.level = Log4Moz.Level["Info"];
   let logf = FileUtils.getFile('ProfD', ['marionette.log']);
-  
+
+  let dumper = false;
   let formatter = new Log4Moz.BasicFormatter();
   this.logger.addAppender(new Log4Moz.RotatingFileAppender(logf, formatter));
-  this.logger.addAppender(new Log4Moz.DumpAppender(formatter));
+#ifdef DEBUG
+  dumper = true;
+#endif
+#ifdef MOZ_B2G
+  dumper = true;
+#endif
+  if (dumper) {
+    this.logger.addAppender(new Log4Moz.DumpAppender(formatter));
+  }
   this.logger.info("MarionetteComponent loaded");
 }
 
 MarionetteComponent.prototype = {
   classDescription: "Marionette component",
   classID: MARIONETTE_CID,
   contractID: MARIONETTE_CONTRACTID,
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
-  _xpcom_categories: [{category: "profile-after-change", service: true}],
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler, Ci.nsIObserver]),
+  _xpcom_categories: [{category: "command-line-handler", entry: "b-marionette"},
+                      {category: "profile-after-change", service: true}],
   original_forcelocal: null,
   appName: Services.appinfo.name,
+  enabled: false,
+  finalUiStartup: false,
 
   onSocketAccepted: function mc_onSocketAccepted(aSocket, aTransport) {
     this.logger.info("onSocketAccepted for Marionette dummy socket");
   },
 
   onStopListening: function mc_onStopListening(aSocket, status) {
     this.logger.info("onStopListening for Marionette dummy socket, code " + status);
     aSocket.close();
   },
 
+  // Check cmdLine argument for --marionette
+  handle: function mc_handle(cmdLine) {
+    // If the CLI is there then lets do work otherwise nothing to see
+    if (cmdLine.handleFlag("marionette", false)) {
+      this.enabled = true;
+      this.logger.info("marionette enabled via command-line");
+      this.init();
+    }
+  },
+
   observe: function mc_observe(aSubject, aTopic, aData) {
-    let observerService = Services.obs;
     switch (aTopic) {
       case "profile-after-change":
-        let enabled = false;
+        // Using final-ui-startup as the xpcom category doesn't seem to work,
+        // so we wait for that by adding an observer here.
+        this.observerService.addObserver(this, "final-ui-startup", false);
+#ifdef ENABLE_MARIONETTE
+        let enabledPref = false;
         try {
-          enabled = Services.prefs.getBoolPref(MARIONETTE_ENABLED_PREF);
+          enabledPref = Services.prefs.getBoolPref(MARIONETTE_ENABLED_PREF);
         } catch(e) {}
-        if (enabled) {
-          this.logger.info("marionette enabled");
-
-          //add observers
-          observerService.addObserver(this, "final-ui-startup", false);
-          observerService.addObserver(this, "xpcom-shutdown", false);
+        if (enabledPref) {
+          this.enabled = true;
+          this.logger.info("marionette enabled via build flag and pref");
         }
         else {
-          this.logger.info("marionette not enabled");
+          this.logger.info("marionette not enabled via pref");
         }
+#endif
         break;
       case "final-ui-startup":
-        this.logger.info("marionette initializing at " + aTopic);
-        observerService.removeObserver(this, aTopic);
-
-        try {
-          this.original_forcelocal = Services.prefs.getBoolPref(DEBUGGER_FORCELOCAL_PREF);
-        }
-        catch(e) {}
-
-        let marionette_forcelocal = this.appName == 'B2G' ? false : true;
-        try {
-          marionette_forcelocal = Services.prefs.getBoolPref(MARIONETTE_FORCELOCAL_PREF);
-        }
-        catch(e) {}
-        Services.prefs.setBoolPref(DEBUGGER_FORCELOCAL_PREF, marionette_forcelocal);
-
-        if (!marionette_forcelocal) {
-          // See bug 800138.  Because the first socket that opens with
-          // force-local=false fails, we open a dummy socket that will fail.
-	  // keepWhenOffline=true so that it still work when offline (local).
-          // This allows the following attempt by Marionette to open a socket
-          // to succeed.
-          let insaneSacrificialGoat = new ServerSocket(666, Ci.nsIServerSocket.KeepWhenOffline, 4);
-          insaneSacrificialGoat.asyncListen(this);
-        }
-
+        this.finalUiStartup = true;
+        this.observerService.removeObserver(this, aTopic);
+        this.observerService.addObserver(this, "xpcom-shutdown", false);
         this.init();
         break;
       case "xpcom-shutdown":
-        observerService.removeObserver(this, "xpcom-shutdown");
+        this.observerService.removeObserver(this, "xpcom-shutdown");
         this.uninit();
         break;
     }
   },
 
   init: function mc_init() {
-    if (!this._loaded) {
+    if (!this._loaded && this.enabled && this.finalUiStartup) {
       this._loaded = true;
+
+      try {
+        this.original_forcelocal = Services.prefs.getBoolPref(DEBUGGER_FORCELOCAL_PREF);
+      }
+      catch(e) {}
+
+      let marionette_forcelocal = this.appName == 'B2G' ? false : true;
+      try {
+        marionette_forcelocal = Services.prefs.getBoolPref(MARIONETTE_FORCELOCAL_PREF);
+      }
+      catch(e) {}
+      Services.prefs.setBoolPref(DEBUGGER_FORCELOCAL_PREF, marionette_forcelocal);
+
+      if (!marionette_forcelocal) {
+        // See bug 800138.  Because the first socket that opens with
+        // force-local=false fails, we open a dummy socket that will fail.
+        // keepWhenOffline=true so that it still work when offline (local).
+        // This allows the following attempt by Marionette to open a socket
+        // to succeed.
+        let insaneSacrificialGoat = new ServerSocket(666, Ci.nsIServerSocket.KeepWhenOffline, 4);
+        insaneSacrificialGoat.asyncListen(this);
+      }
+
       let port;
       try {
         port = Services.prefs.getIntPref('marionette.defaultPrefs.port');
       }
       catch(e) {
         port = 2828;
       }
       try {
--- a/testing/marionette/moz.build
+++ b/testing/marionette/moz.build
@@ -1,8 +1,7 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
-if CONFIG['ENABLE_MARIONETTE']:
-    DIRS += ['components', 'atoms']
+DIRS += ['components', 'atoms']
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -223,17 +223,17 @@ if CONFIG['MOZ_ENABLE_GNOME_COMPONENT']:
 if not CONFIG['MOZ_ENABLE_LIBCONIC'] and CONFIG['MOZ_ENABLE_DBUS']:
     add_tier_dir('platform', 'toolkit/system/dbus')
 
 add_tier_dir('platform', 'addon-sdk')
 
 if CONFIG['MOZ_MAPINFO']:
     add_tier_dir('platform', 'tools/codesighs')
 
-if CONFIG['ENABLE_MARIONETTE']:
+if CONFIG['ENABLE_MARIONETTE'] or CONFIG['MOZ_WIDGET_TOOLKIT'] not in ('gonk', 'android'):
     add_tier_dir('platform', 'testing/marionette')
 
 if CONFIG['ENABLE_TESTS']:
     add_tier_dir('platform', [
         'testing/mochitest',
         'testing/xpcshell',
         'testing/tools/screenshot',
         'testing/peptest',