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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const profileDir = gProfD.clone();
profileDir.append("extensions");
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
const ADDONS = [
{
id: "addon1@experiments.addons.mozilla.org",
dependencies: ["experiments.addon2"],
},
{
id: "addon2@experiments.addons.mozilla.org",
dependencies: ["experiments.addon3"],
},
{
id: "addon3@experiments.addons.mozilla.org",
},
{
id: "addon4@experiments.addons.mozilla.org",
},
{
id: "addon5@experiments.addons.mozilla.org",
dependencies: ["experiments.addon2"],
},
];
let addonFiles = [];
let events = [];
function promiseAddonStartup(id) {
return new Promise(resolve => {
const onBootstrapMethod = (event, { method, params }) => {
if (method == "startup" && params.id == id) {
AddonTestUtils.off("bootstrap-method", onBootstrapMethod);
resolve();
}
};
AddonTestUtils.on("bootstrap-method", onBootstrapMethod);
});
}
add_task(async function setup() {
await promiseStartupManager();
const onBootstrapMethod = (event, { method, params }) => {
if (method == "startup" || method == "shutdown") {
events.push([method, params.id]);
}
};
AddonTestUtils.on("bootstrap-method", onBootstrapMethod);
registerCleanupFunction(() => {
AddonTestUtils.off("bootstrap-method", onBootstrapMethod);
});
for (let addon of ADDONS) {
let manifest = {
browser_specific_settings: { gecko: { id: addon.id } },
permissions: addon.dependencies,
};
addonFiles.push(await createTempWebExtensionFile({ manifest }));
}
});
add_task(async function () {
deepEqual(events, [], "Should have no events");
await promiseInstallFile(addonFiles[3]);
deepEqual(events, [["startup", ADDONS[3].id]]);
events.length = 0;
await promiseInstallFile(addonFiles[0]);
deepEqual(events, [], "Should have no events");
await promiseInstallFile(addonFiles[1]);
deepEqual(events, [], "Should have no events");
await Promise.all([
promiseInstallFile(addonFiles[2]),
promiseAddonStartup(ADDONS[0].id),
]);
deepEqual(events, [
["startup", ADDONS[2].id],
["startup", ADDONS[1].id],
["startup", ADDONS[0].id],
]);
events.length = 0;
await Promise.all([
promiseInstallFile(addonFiles[2]),
promiseAddonStartup(ADDONS[0].id),
]);
deepEqual(events, [
["shutdown", ADDONS[0].id],
["shutdown", ADDONS[1].id],
["shutdown", ADDONS[2].id],
["startup", ADDONS[2].id],
["startup", ADDONS[1].id],
["startup", ADDONS[0].id],
]);
events.length = 0;
await promiseInstallFile(addonFiles[4]);
deepEqual(events, [["startup", ADDONS[4].id]]);
events.length = 0;
await promiseRestartManager();
deepEqual(events, [
["shutdown", ADDONS[4].id],
["shutdown", ADDONS[3].id],
["shutdown", ADDONS[0].id],
["shutdown", ADDONS[1].id],
["shutdown", ADDONS[2].id],
["startup", ADDONS[2].id],
["startup", ADDONS[1].id],
["startup", ADDONS[0].id],
["startup", ADDONS[3].id],
["startup", ADDONS[4].id],
]);
await promiseShutdownManager();
});
|