Bug 1252871 - Move promiseFindAddonUpdates to AddonTestUtils r=aswan

MozReview-Commit-ID: 9lmpuQSQWw1

--HG--
extra : rebase_source : e1ffd24d34875c1a9d0820a1beccd9223a4119a5
This commit is contained in:
Matthew Wein 2016-09-26 10:49:05 -07:00
parent 4b795c5eb5
commit 09fbf696c1
2 changed files with 56 additions and 54 deletions

View File

@ -1087,6 +1087,61 @@ var AddonTestUtils = {
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
*

View File

@ -71,6 +71,7 @@ const {
promiseAddonsWithOperationsByTypes,
promiseCompleteAllInstalls,
promiseConsoleOutput,
promiseFindAddonUpdates,
promiseInstallAllFiles,
promiseInstallFile,
promiseRestartManager,
@ -1271,60 +1272,6 @@ function callback_soon(aFunction) {
}
}
/**
* 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));