summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js')
-rw-r--r--toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js b/toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js
new file mode 100644
index 000000000..27d8029c5
--- /dev/null
+++ b/toolkit/mozapps/webextensions/test/browser/browser_webapi_enable.js
@@ -0,0 +1,62 @@
+const TESTPAGE = `${SECURE_TESTROOT}webapi_addon_listener.html`;
+
+Services.prefs.setBoolPref("extensions.webapi.testing", true);
+registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("extensions.webapi.testing");
+});
+
+function* getListenerEvents(browser) {
+ let result = yield ContentTask.spawn(browser, null, function*() {
+ return content.document.getElementById("result").textContent;
+ });
+
+ return result.split('\n').map(JSON.parse);
+}
+
+const ID = "test@tests.mozilla.org";
+
+let provider = new MockProvider(false);
+provider.createAddons([
+ {
+ id: ID,
+ name: "Test add-on",
+ operationsRequiringRestart: AddonManager.OP_NEED_RESTART_NONE,
+ },
+]);
+
+// Test disable and enable from content
+add_task(function* () {
+ yield BrowserTestUtils.withNewTab(TESTPAGE, function*(browser) {
+ let addon = yield promiseAddonByID(ID);
+ isnot(addon, null, "Test addon exists");
+ is(addon.userDisabled, false, "addon is enabled");
+
+ // Disable the addon from content.
+ yield ContentTask.spawn(browser, null, function* () {
+ return content.navigator.mozAddonManager
+ .getAddonByID("test@tests.mozilla.org")
+ .then(addon => { addon.setEnabled(false); });
+ });
+
+ let events = yield getListenerEvents(browser);
+ let expected = [
+ {id: ID, needsRestart: false, event: "onDisabling"},
+ {id: ID, needsRestart: false, event: "onDisabled"},
+ ];
+ Assert.deepEqual(events, expected, "Got expected disable events");
+
+ // Enable the addon from content.
+ yield ContentTask.spawn(browser, null, function* () {
+ return content.navigator.mozAddonManager
+ .getAddonByID("test@tests.mozilla.org")
+ .then(addon => { addon.setEnabled(true); });
+ });
+
+ events = yield getListenerEvents(browser);
+ expected = expected.concat([
+ {id: ID, needsRestart: false, event: "onEnabling"},
+ {id: ID, needsRestart: false, event: "onEnabled"},
+ ]);
+ Assert.deepEqual(events, expected, "Got expected enable events");
+ });
+});