Bug 1142734 - Use Timer.jsm and add some logs to jetpack-addon-harness.js. r=mossop, a=test-only
authorErik Vold <evold@mozilla.com>
Sat, 06 Jun 2015 19:21:15 -0700
changeset 266198 b2455e4eca11
parent 266197 b009c272abac
child 266199 a7f385942c76
push id4785
push userryanvm@gmail.com
push date2015-06-08 13:34 +0000
treeherdermozilla-beta@a2c9c4c49319 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, test-only
bugs1142734
milestone39.0
Bug 1142734 - Use Timer.jsm and add some logs to jetpack-addon-harness.js. r=mossop, a=test-only
testing/mochitest/jetpack-addon-harness.js
--- a/testing/mochitest/jetpack-addon-harness.js
+++ b/testing/mochitest/jetpack-addon-harness.js
@@ -4,16 +4,17 @@ var gConfig;
 if (Cc === undefined) {
   var Cc = Components.classes;
   var Ci = Components.interfaces;
   var Cu = Components.utils;
 }
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
+Cu.import("resource://gre/modules/Timer.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
   "resource://gre/modules/AddonManager.jsm");
 
 // Start the tests after the window has been displayed
 window.addEventListener("load", function testOnLoad() {
@@ -69,20 +70,28 @@ function installAddon(url) {
             setPrefs("extensions.modules." + install.addon.id + ".path", paths);
           }
         },
 
         onInstallEnded: function(install, addon) {
           resolve(addon);
         },
 
+        onDownloadCancelled: function(install) {
+          reject("Download cancelled: " + install.error);
+        },
+
         onDownloadFailed: function(install) {
           reject("Download failed: " + install.error);
         },
 
+        onInstallCancelled: function(install) {
+          reject("Install cancelled: " + install.error);
+        },
+
         onInstallFailed: function(install) {
           reject("Install failed: " + install.error);
         }
       });
 
       install.install();
     }, "application/x-xpinstall");
   });
@@ -91,20 +100,21 @@ function installAddon(url) {
 // Uninstalls an add-on returning a promise for when it is gone
 function uninstallAddon(oldAddon) {
   return new Promise(function(resolve, reject) {
     AddonManager.addAddonListener({
       onUninstalled: function(addon) {
         if (addon.id != oldAddon.id)
           return;
 
+        dump("TEST-INFO | jetpack-addon-harness.js | Uninstalled test add-on " + addon.id + "\n");
+
         // Some add-ons do async work on uninstall, we must wait for that to
         // complete
-        let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-        timer.init(resolve, 500, timer.TYPE_ONE_SHOT);
+        setTimeout(resolve, 500);
       }
     });
 
     oldAddon.uninstall();
   });
 }
 
 // Waits for a test add-on to signal it has completed its tests
@@ -114,23 +124,23 @@ function waitForResults() {
       Services.obs.removeObserver(arguments.callee, "sdk:test:results");
 
       resolve(JSON.parse(data));
     }, "sdk:test:results", false);
   });
 }
 
 // Runs tests for the add-on available at URL.
-let testAddon = Task.async(function*({ url, expected }) {
+let testAddon = Task.async(function*({ url }) {
   dump("TEST-INFO | jetpack-addon-harness.js | Installing test add-on " + realPath(url) + "\n");
   let addon = yield installAddon(url);
 
   let results = yield waitForResults();
 
-  dump("TEST-INFO | jetpack-addon-harness.js | Uninstalling test add-on " + realPath(url) + "\n");
+  dump("TEST-INFO | jetpack-addon-harness.js | Uninstalling test add-on " + addon.id + "\n");
   yield uninstallAddon(addon);
 
   dump("TEST-INFO | jetpack-addon-harness.js | Testing add-on " + realPath(url) + " is complete\n");
   return results;
 });
 
 // Sets a set of prefs for test add-ons
 function setPrefs(root, options) {
@@ -192,27 +202,30 @@ function testInit() {
         else {
           dump("Jetpack Addon Test Summary\n");
           dump("\tPassed: " + passed + "\n" +
                "\tFailed: " + failed + "\n" +
                "\tTodo: 0\n");
         }
 
         if (config.closeWhenDone) {
+          dump("TEST-INFO | jetpack-addon-harness.js | Shutting down.\n");
+
           const appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
                              getService(Ci.nsIAppStartup);
           appStartup.quit(appStartup.eAttemptQuit);
         }
       }
 
       function testNextAddon() {
         if (fileNames.length == 0)
           return finish();
 
         let filename = fileNames.shift();
+        dump("TEST-INFO | jetpack-addon-harness.js | Starting test add-on " + realPath(filename.url) + "\n");
         testAddon(filename).then(results => {
           passed += results.passed;
           failed += results.failed;
         }).then(testNextAddon, error => {
           // If something went wrong during the test then a previous test add-on
           // may still be installed, this leaves us in an unexpected state so
           // probably best to just abandon testing at this point
           failed++;