Bug 1456051 - Make addon an ES module. r=maja_zf

This does not really functionally change anything, but it prevents
us from polluting the global space in testing/marionette/driver.js.

MozReview-Commit-ID: Guwt3g0lS8q

--HG--
extra : rebase_source : ad2c38e51d54b7c4ead6b8d6a49d05a0dfef7c6c
This commit is contained in:
Andreas Tolfsen 2018-04-23 08:12:30 +01:00
Родитель 921d8f6a6e
Коммит 916ef8de56
3 изменённых файлов: 91 добавлений и 87 удалений

Просмотреть файл

@ -9,10 +9,7 @@ ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
const {UnknownError} = ChromeUtils.import("chrome://marionette/content/error.js", {});
this.EXPORTED_SYMBOLS = ["addon"];
/** @namespace */
this.addon = {};
this.EXPORTED_SYMBOLS = ["Addon"];
// from https://developer.mozilla.org/en-US/Add-ons/Add-on_Manager/AddonManager#AddonInstall_errors
const ERRORS = {
@ -60,6 +57,8 @@ async function installAddon(file) {
});
}
/** Installs addons by path and uninstalls by ID. */
class Addon {
/**
* Install a Firefox addon.
*
@ -80,7 +79,7 @@ async function installAddon(file) {
* @throws {UnknownError}
* If there is a problem installing the addon.
*/
addon.install = async function(path, temporary = false) {
static async install(path, temporary = false) {
let addon;
let file;
@ -106,7 +105,7 @@ addon.install = async function(path, temporary = false) {
}
return addon.id;
};
}
/**
* Uninstall a Firefox addon.
@ -122,7 +121,7 @@ addon.install = async function(path, temporary = false) {
* @throws {UnknownError}
* If there is a problem uninstalling the addon.
*/
addon.uninstall = async function(id) {
static async uninstall(id) {
let candidate = await AddonManager.getAddonByID(id);
return new Promise(resolve => {
@ -143,6 +142,8 @@ addon.uninstall = async function(id) {
};
AddonManager.addAddonListener(listener);
addon.uninstall();
candidate.uninstall();
});
};
}
}
this.Addon = Addon;

Просмотреть файл

@ -1,4 +1,7 @@
addon module
============
.. js:autoclass:: addon
Addon
-----
.. js:autoclass:: Addon
:members:

Просмотреть файл

@ -11,7 +11,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("chrome://marionette/content/accessibility.js");
ChromeUtils.import("chrome://marionette/content/addon.js");
const {Addon} = ChromeUtils.import("chrome://marionette/content/addon.js", {});
ChromeUtils.import("chrome://marionette/content/assert.js");
ChromeUtils.import("chrome://marionette/content/atom.js");
const {
@ -3296,7 +3296,7 @@ GeckoDriver.prototype.installAddon = function(cmd) {
throw new InvalidArgumentError();
}
return addon.install(path, temp);
return Addon.install(path, temp);
};
GeckoDriver.prototype.uninstallAddon = function(cmd) {
@ -3307,7 +3307,7 @@ GeckoDriver.prototype.uninstallAddon = function(cmd) {
throw new InvalidArgumentError();
}
return addon.uninstall(id);
return Addon.uninstall(id);
};
/** Receives all messages from content messageManager. */