Bug 1252871 - Move promiseFindAddonUpdates to AddonTestUtils r?aswan
MozReview-Commit-ID: 9lmpuQSQWw1
--- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
@@ -1083,16 +1083,71 @@ var AddonTestUtils = {
* @return {Promise<Addon>}
* Resolves to the add-on with the given ID.
*/
promiseAddonByID(id) {
return new Promise(resolve => AddonManager.getAddonByID(id, resolve));
},
/**
+ * Returns a promise that will be resolved when an add-on update check is
+ * complete. The value resolved will be an AddonInstall if a new version was
+ * found.
+ */
+ promiseFindAddonUpdates(addon, reason = AddonManager.UPDATE_WHEN_PERIODIC_UPDATE) {
+ let equal = this.testScope.equal;
+ return new Promise((resolve, reject) => {
+ let result = {};
+ addon.findUpdates({
+ onNoCompatibilityUpdateAvailable: function(addon2) {
+ if ("compatibilityUpdate" in result) {
+ throw new Error("Saw multiple compatibility update events");
+ }
+ equal(addon, addon2, "onNoCompatibilityUpdateAvailable");
+ result.compatibilityUpdate = false;
+ },
+
+ onCompatibilityUpdateAvailable: function(addon2) {
+ if ("compatibilityUpdate" in result) {
+ throw new Error("Saw multiple compatibility update events");
+ }
+ equal(addon, addon2, "onCompatibilityUpdateAvailable");
+ result.compatibilityUpdate = true;
+ },
+
+ onNoUpdateAvailable: function(addon2) {
+ if ("updateAvailable" in result) {
+ throw new Error("Saw multiple update available events");
+ }
+ equal(addon, addon2, "onNoUpdateAvailable");
+ result.updateAvailable = false;
+ },
+
+ onUpdateAvailable: function(addon2, install) {
+ if ("updateAvailable" in result) {
+ throw new Error("Saw multiple update available events");
+ }
+ equal(addon, addon2, "onUpdateAvailable");
+ result.updateAvailable = install;
+ },
+
+ onUpdateFinished: function(addon2, error) {
+ equal(addon, addon2, "onUpdateFinished");
+ if (error == AddonManager.UPDATE_STATUS_NO_ERROR) {
+ resolve(result);
+ } else {
+ result.error = error;
+ reject(result);
+ }
+ }
+ }, reason);
+ });
+ },
+
+ /**
* A promise-based variant of AddonManager.getAddonsWithOperationsByTypes
*
* @param {Array<string>} types
* The first argument to AddonManager.getAddonsWithOperationsByTypes
* @return {Promise<Array<Addon>>}
* Resolves to an array of add-ons with the given operations
* pending.
*/
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -66,16 +66,17 @@ const {
manuallyInstall,
manuallyUninstall,
promiseAddonByID,
promiseAddonEvent,
promiseAddonsByIDs,
promiseAddonsWithOperationsByTypes,
promiseCompleteAllInstalls,
promiseConsoleOutput,
+ promiseFindAddonUpdates,
promiseInstallAllFiles,
promiseInstallFile,
promiseRestartManager,
promiseSetExtensionModifiedTime,
promiseShutdownManager,
promiseStartupManager,
promiseWriteProxyFileToDir,
registerDirectory,
@@ -1266,69 +1267,15 @@ function saveJSON(aData, aFile) {
function callback_soon(aFunction) {
return function(...args) {
do_execute_soon(function() {
aFunction.apply(null, args);
}, aFunction.name ? "delayed callback " + aFunction.name : "delayed callback");
}
}
-/**
- * Returns a promise that will be resolved when an add-on update check is
- * complete. The value resolved will be an AddonInstall if a new version was
- * found.
- */
-function promiseFindAddonUpdates(addon, reason = AddonManager.UPDATE_WHEN_PERIODIC_UPDATE) {
- return new Promise((resolve, reject) => {
- let result = {};
- addon.findUpdates({
- onNoCompatibilityUpdateAvailable: function(addon2) {
- if ("compatibilityUpdate" in result) {
- do_throw("Saw multiple compatibility update events");
- }
- equal(addon, addon2, "onNoCompatibilityUpdateAvailable");
- result.compatibilityUpdate = false;
- },
-
- onCompatibilityUpdateAvailable: function(addon2) {
- if ("compatibilityUpdate" in result) {
- do_throw("Saw multiple compatibility update events");
- }
- equal(addon, addon2, "onCompatibilityUpdateAvailable");
- result.compatibilityUpdate = true;
- },
-
- onNoUpdateAvailable: function(addon2) {
- if ("updateAvailable" in result) {
- do_throw("Saw multiple update available events");
- }
- equal(addon, addon2, "onNoUpdateAvailable");
- result.updateAvailable = false;
- },
-
- onUpdateAvailable: function(addon2, install) {
- if ("updateAvailable" in result) {
- do_throw("Saw multiple update available events");
- }
- equal(addon, addon2, "onUpdateAvailable");
- result.updateAvailable = install;
- },
-
- onUpdateFinished: function(addon2, error) {
- equal(addon, addon2, "onUpdateFinished");
- if (error == AddonManager.UPDATE_STATUS_NO_ERROR) {
- resolve(result);
- } else {
- result.error = error;
- reject(result);
- }
- }
- }, reason);
- });
-}
-
function writeProxyFileToDir(aDir, aAddon, aId) {
awaitPromise(promiseWriteProxyFileToDir(aDir, aAddon, aId));
let file = aDir.clone();
file.append(aId);
return file
}