Bug 1256399 use temporary addon installation for update tests r=mossop
authorAndrew Swan <aswan@mozilla.com>
Tue, 15 Mar 2016 05:24:49 -0700
changeset 289371 fef5ea8968cbf4cc85cf59e5e03c98854fd54ba3
parent 289370 f1482a4600fc249ff802b31277fe3084089fe33a
child 289372 77caf1897d7a919cd5cf12ec4862e675b61a6e16
push id30102
push userryanvm@gmail.com
push dateSat, 19 Mar 2016 15:23:17 +0000
treeherdermozilla-central@720fb3d55e28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1256399
milestone48.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 1256399 use temporary addon installation for update tests r=mossop MozReview-Commit-ID: AdjNzZrA79N
toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul
toolkit/mozapps/update/tests/chrome/utils.js
--- a/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul
+++ b/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul
@@ -62,31 +62,32 @@ function runTest() {
   file = dir.clone();
   file.append(FILE_UPDATE_STATUS);
   ok(!file.exists(), file.path + " should not exist");
 
   file = dir.clone();
   file.append(FILE_UPDATE_ARCHIVE);
   ok(!file.exists(), file.path + " should not exist");
 
-  let addonPrepDir = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR,
-                                         Ci.nsILocalFile);
-  addonPrepDir.append(ADDON_PREP_DIR);
-  // Not being able to remove the directory used to create the test add-ons
-  // will not adversely affect subsequent tests so wrap it in a try block and
-  // don't test whether its removal was successful.
-  try {
-    removeDirRecursive(addonPrepDir);
-  }
-  catch (e) {
-    logTestInfo("Unable to remove directory. Path: " + addonPrepDir.path +
-                ", Exception: " + e);
-  }
-
-  resetAddons(cleanupRestoreUpdaterBackup);
+  resetAddons(() => {
+    let addonPrepDir = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR,
+                                           Ci.nsILocalFile);
+    addonPrepDir.append(ADDON_PREP_DIR);
+    // Not being able to remove the directory used to create the test add-ons
+    // will not adversely affect subsequent tests so wrap it in a try block and
+    // don't test whether its removal was successful.
+    try {
+      removeDirRecursive(addonPrepDir);
+    }
+    catch (e) {
+      logTestInfo("Unable to remove directory. Path: " + addonPrepDir.path +
+                  ", Exception: " + e);
+    }
+    cleanupRestoreUpdaterBackup();
+  });
 }
 
 /**
  * After all tests finish this will repeatedly attempt to restore the real
  * updater if it exists and then call finishTest after the restore is
  * successful.
  */
 function cleanupRestoreUpdaterBackup() {
--- a/toolkit/mozapps/update/tests/chrome/utils.js
+++ b/toolkit/mozapps/update/tests/chrome/utils.js
@@ -1311,55 +1311,24 @@ function setupAddons(aCallback) {
         aAddon.userDisabled = true;
       }
     });
     // If there are no pre-existing add-ons the preference value will be an
     // empty string.
     Services.prefs.setCharPref(PREF_DISABLEDADDONS, disabledAddons.join(" "));
 
     // Install the test add-ons.
-    let xpiFiles = getTestAddonXPIFiles();
-    let xpiCount = xpiFiles.length;
-    let installs = [];
-    xpiFiles.forEach(function(aFile) {
-      AddonManager.getInstallForFile(aFile, function(aInstall) {
-        if (!aInstall) {
-          throw "No AddonInstall created for " + aFile.path;
-        }
-
-        installs.push(aInstall);
-
-        if (--xpiCount == 0) {
-          let installCount = installs.length;
-          let installCompleted = function(aInstall) {
-            aInstall.removeListener(listener);
-
-            if (getAddonTestType(aInstall.addon.name) == "userdisabled") {
-              aInstall.addon.userDisabled = true;
-            }
-            if (--installCount == 0) {
-              setNoUpdateAddonsDisabledState();
-            }
-          };
-
-          let listener = {
-            onDownloadFailed: installCompleted,
-            onDownloadCancelled: installCompleted,
-            onInstallFailed: installCompleted,
-            onInstallCancelled: installCompleted,
-            onInstallEnded: installCompleted
-          };
-
-          installs.forEach(function(aInstall) {
-            aInstall.addListener(listener);
-            aInstall.install();
-          });
+    let promises = getTestAddonXPIFiles().map(function(aFile) {
+      return AddonManager.installTemporaryAddon(aFile).then(addon => {
+        if (getAddonTestType(addon.name) == "userdisabled") {
+          addon.userDisabled = true;
         }
       });
     });
+    return Promise.all(promises).then(setNoUpdateAddonsDisabledState);
   });
 }
 
 /**
  * Uninstalls the test add-ons, enables add-ons that were disabled when the
  * test started, and calls the callback specified in the aCallback parameter.
  *
  * @param  aCallback