1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
const TESTPAGE = `${SECURE_TESTROOT}webapi_addon_listener.html`;
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [["extensions.webapi.testing", true]],
});
});
async function getListenerEvents(browser) {
let result = await SpecialPowers.spawn(browser, [], async function () {
return content.document.getElementById("result").textContent;
});
return result.split("\n").map(JSON.parse);
}
const ID = "test@tests.mozilla.org";
let provider = new MockProvider();
provider.createAddons([
{
id: ID,
name: "Test add-on",
operationsRequiringRestart: AddonManager.OP_NEED_RESTART_NONE,
},
]);
// Test disable and enable from content
add_task(async function () {
await BrowserTestUtils.withNewTab(TESTPAGE, async function (browser) {
let addon = await promiseAddonByID(ID);
isnot(addon, null, "Test addon exists");
is(addon.userDisabled, false, "addon is enabled");
// Disable the addon from content.
await SpecialPowers.spawn(browser, [], async function () {
return content.navigator.mozAddonManager
.getAddonByID("test@tests.mozilla.org")
.then(addon => addon.setEnabled(false));
});
let events = await getListenerEvents(browser);
let expected = [
{ id: ID, event: "onDisabling" },
{ id: ID, event: "onDisabled" },
];
Assert.deepEqual(events, expected, "Got expected disable events");
// Enable the addon from content.
await SpecialPowers.spawn(browser, [], async function () {
return content.navigator.mozAddonManager
.getAddonByID("test@tests.mozilla.org")
.then(addon => addon.setEnabled(true));
});
events = await getListenerEvents(browser);
expected = expected.concat([
{ id: ID, event: "onEnabling" },
{ id: ID, event: "onEnabled" },
]);
Assert.deepEqual(events, expected, "Got expected enable events");
});
});
|