bug 962858 - bypass native installation during automated tests; r=mfinkle,fabrice
authorMyk Melez <myk@mozilla.org>
Fri, 24 Jan 2014 20:51:30 -0800
changeset 181232 78f00eacf00a35d2b13517ca8d12e5cc5bcac5ff
parent 181231 36dfbfb486f50b51e24c52765f9bf0c2188c5ad4
child 181233 14de085ae57f5e4a82e8151a8d8b9730a8a3b25e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, fabrice
bugs962858
milestone29.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 962858 - bypass native installation during automated tests; r=mfinkle,fabrice
dom/apps/src/Webapps.jsm
mobile/android/chrome/content/browser.js
mobile/android/modules/WebappManager.jsm
testing/profiles/prefs_general.js
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -1126,17 +1126,17 @@ this.DOMApplicationRegistry = {
 
     let msg = aMessage.data || {};
     let mm = aMessage.target;
     msg.mm = mm;
 
     switch (aMessage.name) {
       case "Webapps:Install": {
 #ifdef MOZ_ANDROID_SYNTHAPKS
-        Services.obs.notifyObservers(null, "webapps-download-apk", JSON.stringify(msg));
+        Services.obs.notifyObservers(mm, "webapps-runtime-install", JSON.stringify(msg));
 #else
         this.doInstall(msg, mm);
 #endif
         break;
       }
       case "Webapps:GetSelf":
         this.getSelf(msg, mm);
         break;
@@ -1155,17 +1155,17 @@ this.DOMApplicationRegistry = {
       case "Webapps:GetNotInstalled":
         this.getNotInstalled(msg, mm);
         break;
       case "Webapps:GetAll":
         this.doGetAll(msg, mm);
         break;
       case "Webapps:InstallPackage": {
 #ifdef MOZ_ANDROID_SYNTHAPKS
-        Services.obs.notifyObservers(null, "webapps-download-apk", JSON.stringify(msg));
+        Services.obs.notifyObservers(mm, "webapps-runtime-install-package", JSON.stringify(msg));
 #else
         this.doInstallPackage(msg, mm);
 #endif
         break;
       }
       case "Webapps:RegisterForMessages":
         this.addMessageListener(msg.messages, msg.app, mm);
         break;
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -329,17 +329,18 @@ var BrowserApp = {
     Services.obs.addObserver(this, "Viewport:Change", false);
     Services.obs.addObserver(this, "Viewport:Flush", false);
     Services.obs.addObserver(this, "Viewport:FixedMarginsChanged", false);
     Services.obs.addObserver(this, "Passwords:Init", false);
     Services.obs.addObserver(this, "FormHistory:Init", false);
     Services.obs.addObserver(this, "gather-telemetry", false);
     Services.obs.addObserver(this, "keyword-search", false);
 #ifdef MOZ_ANDROID_SYNTHAPKS
-    Services.obs.addObserver(this, "webapps-download-apk", false);
+    Services.obs.addObserver(this, "webapps-runtime-install", false);
+    Services.obs.addObserver(this, "webapps-runtime-install-package", false);
     Services.obs.addObserver(this, "webapps-ask-install", false);
     Services.obs.addObserver(this, "webapps-launch", false);
     Services.obs.addObserver(this, "webapps-uninstall", false);
     Services.obs.addObserver(this, "Webapps:AutoInstall", false);
     Services.obs.addObserver(this, "Webapps:Load", false);
     Services.obs.addObserver(this, "Webapps:AutoUninstall", false);
 #endif
     Services.obs.addObserver(this, "sessionstore-state-purge-complete", false);
@@ -1574,18 +1575,22 @@ var BrowserApp = {
         this.selectedTab.updateViewportSize(gScreenWidth);
         break;
 
       case "nsPref:changed":
         this.notifyPrefObservers(aData);
         break;
 
 #ifdef MOZ_ANDROID_SYNTHAPKS
-      case "webapps-download-apk":
-        WebappManager.downloadApk(JSON.parse(aData));
+      case "webapps-runtime-install":
+        WebappManager.install(JSON.parse(aData), aSubject);
+        break;
+
+      case "webapps-runtime-install-package":
+        WebappManager.installPackage(JSON.parse(aData), aSubject);
         break;
 
       case "webapps-ask-install":
         WebappManager.askInstall(JSON.parse(aData));
         break;
 
       case "webapps-launch": {
         WebappManager.launch(JSON.parse(aData));
--- a/mobile/android/modules/WebappManager.jsm
+++ b/mobile/android/modules/WebappManager.jsm
@@ -23,19 +23,47 @@ function dump(a) {
 
 function sendMessageToJava(aMessage) {
   return Services.androidBridge.handleGeckoMessage(JSON.stringify(aMessage));
 }
 
 this.WebappManager = {
   __proto__: DOMRequestIpcHelper.prototype,
 
-  downloadApk: function(aMsg) {
+  get _testing() {
+    try {
+      return Services.prefs.getBoolPref("browser.webapps.testing");
+    } catch(ex) {
+      return false;
+    }
+  },
+
+  install: function(aMessage, aMessageManager) {
+    if (this._testing) {
+      // Go directly to DOM.  Do not download/install APK, do not collect $200.
+      DOMApplicationRegistry.doInstall(aMessage, aMessageManager);
+      return;
+    }
+
+    this._downloadApk(aMessage);
+  },
+
+  installPackage: function(aMessage, aMessageManager) {
+    if (this._testing) {
+      // Go directly to DOM.  Do not download/install APK, do not collect $200.
+      DOMApplicationRegistry.doInstallPackage(aMessage, aMessageManager);
+      return;
+    }
+
+    this._downloadApk(aMessage);
+  },
+
+  _downloadApk: function(aMsg) {
     let manifestUrl = aMsg.app.manifestURL;
-    dump("downloadApk for " + manifestUrl);
+    dump("_downloadApk for " + manifestUrl);
 
     // Get the endpoint URL and convert it to an nsIURI/nsIURL object.
     const GENERATOR_URL_PREF = "browser.webapps.apkFactoryUrl";
     const GENERATOR_URL_BASE = Services.prefs.getCharPref(GENERATOR_URL_PREF);
     let generatorUrl = NetUtil.newURI(GENERATOR_URL_BASE).QueryInterface(Ci.nsIURL);
 
     // Populate the query part of the URL with the manifest URL parameter.
     let params = {
@@ -112,16 +140,21 @@ this.WebappManager = {
       manifestURL: manifestURL,
       origin: origin
     });
   },
 
   uninstall: function(aData) {
     dump("uninstall: " + aData.manifestURL);
 
+    if (this._testing) {
+      // We don't have to do anything, as the registry does all the work.
+      return;
+    }
+
     // TODO: uninstall the APK.
   },
 
   autoInstall: function(aData) {
     let mm = {
       sendAsyncMessage: function (aMessageName, aData) {
         // TODO hook this back to Java to report errors.
         dump("sendAsyncMessage " + aMessageName + ": " + JSON.stringify(aData));
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -151,8 +151,11 @@ user_pref("browser.pagethumbnails.captur
 
 // Indicate that the download panel has been shown once so that whichever
 // download test runs first doesn't show the popup inconsistently.
 user_pref("browser.download.panel.shown", true);
 
 // prefs for firefox metro.
 // Disable first-tun tab
 user_pref("browser.firstrun.count", 0);
+
+// Enable webapps testing mode, which bypasses native installation.
+user_pref("browser.webapps.testing", true);