Created
July 29, 2016 19:25
-
-
Save rhelmer/3ae3bdf5ce125d8c6c51a8cf2c0eddf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm | |
| --- a/toolkit/components/extensions/Extension.jsm | |
| +++ b/toolkit/components/extensions/Extension.jsm | |
| @@ -1198,21 +1198,23 @@ this.Extension.generateXPI = function(id | |
| /** | |
| * A skeleton Extension-like object, used for testing, which installs an | |
| * add-on via the add-on manager when startup() is called, and | |
| * uninstalles it on shutdown(). | |
| * | |
| * @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) => { | |
| if (extension.id == this.id) { | |
| Management.off(eventName, onstartup); | |
| this._extension = extension; | |
| resolve(extension); | |
| @@ -1239,20 +1241,48 @@ MockExtension.prototype = { | |
| off(...args) { | |
| this._extensionPromise.then(extension => { | |
| extension.off(...args); | |
| }); | |
| }, | |
| 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") { | |
| + let installCompleted = (install) => { | |
| + install.removeListener(listener); | |
| + return new Promise(resolve => { | |
| + AddonManager.getAddonByID(this.id, resolve).then(addon => { | |
| + this.addon = addon; | |
| + return this._readyPromise; | |
| + }); | |
| + }); | |
| + }; | |
| + | |
| + let listener = { | |
| + onDownloadFailed: installCompleted, | |
| + onDownloadCancelled: installCompleted, | |
| + onInstallFailed: installCompleted, | |
| + onInstallCancelled: installCompleted, | |
| + onInstallEnded: installCompleted, | |
| + onInstallPostponed: installCompleted, | |
| + }; | |
| + | |
| + AddonManager.getInstallForFile(this.file, install => { | |
| + install.addListener(listener); | |
| + install.install(); | |
| + }); | |
| + } else { | |
| + throw Error("installType must be one of: temporary, permanent"); | |
| + } | |
| }, | |
| shutdown() { | |
| this.addon.uninstall(true); | |
| return this.cleanupGeneratedFile(); | |
| }, | |
| cleanupGeneratedFile() { | |
| @@ -1273,18 +1303,19 @@ this.Extension.generate = function(id, d | |
| let file = this.generateXPI(id, data); | |
| flushJarCache(file); | |
| Services.ppmm.broadcastAsyncMessage("Extension:FlushJarCache", {path: file.path}); | |
| 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({ | |
| id, | |
| resourceURI: jarURI, | |
| cleanupFile: file, | |
| }); | |
| }; | |
| diff --git a/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_debug_global.html b/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_debug_global.html | |
| --- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_debug_global.html | |
| +++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_debug_global.html | |
| @@ -30,17 +30,17 @@ const { | |
| */ | |
| function backgroundScript() { | |
| window.testThing = "test!"; | |
| browser.test.notifyPass("background script ran"); | |
| } | |
| let extensionData = { | |
| - useAddonManager: true, | |
| + useAddonManager: "temporary", | |
| background: "(" + backgroundScript.toString() + ")()", | |
| manifest: {}, | |
| files: {}, | |
| }; | |
| add_task(function* () { | |
| let extension = ExtensionTestUtils.loadExtension(extensionData); | |
| yield extension.startup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment