Bug 1290617 - allow non-temp mock webextensions r=kmag

MozReview-Commit-ID: JeEeMkrQ4te

--HG--
extra : rebase_source : 98d95907134c68a347067de1cce601656f27b4a3
This commit is contained in:
Robert Helmer 2016-07-29 16:14:19 -07:00
parent 7d0daf004c
commit e7f6d9d4ec
4 changed files with 31 additions and 9 deletions

View File

@ -30,7 +30,7 @@ add_task(function* test_tab_options_privileges() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: true,
useAddonManager: "temporary",
manifest: {
"permissions": ["tabs"],

View File

@ -4,7 +4,7 @@
function* loadExtension(options) {
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: true,
useAddonManager: "temporary",
manifest: Object.assign({
"permissions": ["tabs"],

View File

@ -1203,11 +1203,13 @@ this.Extension.generateXPI = function(id, data) {
* @param {string} id
* @param {nsIFile} file
* @param {nsIURI} rootURI
* @param {string} installType
*/
function MockExtension(id, file, rootURI) {
function MockExtension(id, file, rootURI, installType) {
this.id = id;
this.file = file;
this.rootURI = rootURI;
this.installType = installType;
let promiseEvent = eventName => new Promise(resolve => {
let onstartup = (msg, extension) => {
@ -1244,10 +1246,29 @@ MockExtension.prototype = {
},
startup() {
return AddonManager.installTemporaryAddon(this.file).then(addon => {
this.addon = addon;
return this._readyPromise;
});
if (this.installType == "temporary") {
return AddonManager.installTemporaryAddon(this.file).then(addon => {
this.addon = addon;
return this._readyPromise;
});
} else if (this.installType == "permanent") {
return new Promise((resolve, reject) => {
AddonManager.getInstallForFile(this.file, install => {
let listener = {
onInstallFailed: reject,
onInstallEnded: (install, newAddon) => {
this.addon = newAddon;
resolve(this._readyPromise);
},
};
install.addListener(listener);
install.install();
});
});
} else {
throw Error("installType must be one of: temporary, permanent");
}
},
shutdown() {
@ -1278,8 +1299,9 @@ this.Extension.generate = function(id, data) {
let fileURI = Services.io.newFileURI(file);
let jarURI = Services.io.newURI("jar:" + fileURI.spec + "!/", null, null);
// This may be "temporary" or "permanent".
if (data.useAddonManager) {
return new MockExtension(id, file, jarURI);
return new MockExtension(id, file, jarURI, data.useAddonManager);
}
return new Extension({

View File

@ -35,7 +35,7 @@ function backgroundScript() {
}
let extensionData = {
useAddonManager: true,
useAddonManager: "temporary",
background: "(" + backgroundScript.toString() + ")()",
manifest: {},
files: {},