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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const { ExtensionParent } = ChromeUtils.importESModule(
"resource://gre/modules/ExtensionParent.sys.mjs"
);
add_task(async function testExtensionDebuggingUtilsCleanup() {
const extension = ExtensionTestUtils.loadExtension({
background() {
browser.test.sendMessage("background.ready");
},
});
const expectedEmptyDebugUtils = {
hiddenXULWindow: null,
cacheSize: 0,
};
let { hiddenXULWindow, debugBrowserPromises } = ExtensionParent.DebugUtils;
deepEqual(
{ hiddenXULWindow, cacheSize: debugBrowserPromises.size },
expectedEmptyDebugUtils,
"No ExtensionDebugUtils resources has been allocated yet"
);
await extension.startup();
await extension.awaitMessage("background.ready");
hiddenXULWindow = ExtensionParent.DebugUtils.hiddenXULWindow;
deepEqual(
{ hiddenXULWindow, cacheSize: debugBrowserPromises.size },
expectedEmptyDebugUtils,
"No debugging resources has been yet allocated once the extension is running"
);
const fakeAddonActor = {
addonId: extension.id,
};
const anotherAddonActor = {
addonId: extension.id,
};
const waitFirstBrowser =
ExtensionParent.DebugUtils.getExtensionProcessBrowser(fakeAddonActor);
const waitSecondBrowser =
ExtensionParent.DebugUtils.getExtensionProcessBrowser(anotherAddonActor);
const addonDebugBrowser = await waitFirstBrowser;
equal(
addonDebugBrowser.isRemoteBrowser,
extension.extension.remote,
"The addon debugging browser has the expected remote type"
);
equal(
await waitSecondBrowser,
addonDebugBrowser,
"Two addon debugging actors related to the same addon get the same browser element "
);
equal(
debugBrowserPromises.size,
1,
"The expected resources has been allocated"
);
const nonExistentAddonActor = {
addonId: "non-existent-addon@test",
};
const waitRejection = ExtensionParent.DebugUtils.getExtensionProcessBrowser(
nonExistentAddonActor
);
await Assert.rejects(
waitRejection,
/Extension not found/,
"Reject with the expected message for non existent addons"
);
equal(
debugBrowserPromises.size,
1,
"No additional debugging resources has been allocated"
);
await ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(
fakeAddonActor
);
equal(
debugBrowserPromises.size,
1,
"The addon debugging browser is cached until all the related actors have released it"
);
await ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(
anotherAddonActor
);
hiddenXULWindow = ExtensionParent.DebugUtils.hiddenXULWindow;
deepEqual(
{ hiddenXULWindow, cacheSize: debugBrowserPromises.size },
expectedEmptyDebugUtils,
"All the allocated debugging resources has been cleared"
);
await extension.unload();
});
add_task(async function testExtensionDebuggingUtilsAddonReloaded() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: {
gecko: {
id: "test-reloaded@test.mozilla.com",
},
},
},
background() {
browser.test.sendMessage("background.ready");
},
});
await extension.startup();
await extension.awaitMessage("background.ready");
let fakeAddonActor = {
addonId: extension.id,
};
const addonDebugBrowser =
await ExtensionParent.DebugUtils.getExtensionProcessBrowser(fakeAddonActor);
equal(
addonDebugBrowser.isRemoteBrowser,
extension.extension.remote,
"The addon debugging browser has the expected remote type"
);
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
1,
"Got the expected number of requested debug browsers"
);
const { chromeDocument } = ExtensionParent.DebugUtils.hiddenXULWindow;
ok(
addonDebugBrowser.parentElement === chromeDocument.documentElement,
"The addon debugging browser is part of the hiddenXULWindow chromeDocument"
);
await extension.unload();
// Install an extension with the same id to recreate for the DebugUtils
// conditions similar to an addon reloaded while the Addon Debugger is opened.
extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: {
gecko: {
id: "test-reloaded@test.mozilla.com",
},
},
},
background() {
browser.test.sendMessage("background.ready");
},
});
await extension.startup();
await extension.awaitMessage("background.ready");
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
1,
"Got the expected number of requested debug browsers"
);
const newAddonDebugBrowser =
await ExtensionParent.DebugUtils.getExtensionProcessBrowser(fakeAddonActor);
equal(
addonDebugBrowser,
newAddonDebugBrowser,
"The existent debugging browser has been reused"
);
equal(
newAddonDebugBrowser.isRemoteBrowser,
extension.extension.remote,
"The addon debugging browser has the expected remote type"
);
await ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(
fakeAddonActor
);
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
0,
"All the addon debugging browsers has been released"
);
await extension.unload();
});
add_task(async function testExtensionDebuggingUtilsWithMultipleAddons() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: {
gecko: {
id: "test-addon-1@test.mozilla.com",
},
},
},
background() {
browser.test.sendMessage("background.ready");
},
});
let anotherExtension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: {
gecko: {
id: "test-addon-2@test.mozilla.com",
},
},
},
background() {
browser.test.sendMessage("background.ready");
},
});
await extension.startup();
await extension.awaitMessage("background.ready");
await anotherExtension.startup();
await anotherExtension.awaitMessage("background.ready");
const fakeAddonActor = {
addonId: extension.id,
};
const anotherFakeAddonActor = {
addonId: anotherExtension.id,
};
const { DebugUtils } = ExtensionParent;
const debugBrowser = await DebugUtils.getExtensionProcessBrowser(
fakeAddonActor
);
const anotherDebugBrowser = await DebugUtils.getExtensionProcessBrowser(
anotherFakeAddonActor
);
const chromeDocument = DebugUtils.hiddenXULWindow.chromeDocument;
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
2,
"Got the expected number of debug browsers requested"
);
ok(
debugBrowser.parentElement === chromeDocument.documentElement,
"The first debug browser is part of the hiddenXUL chromeDocument"
);
ok(
anotherDebugBrowser.parentElement === chromeDocument.documentElement,
"The second debug browser is part of the hiddenXUL chromeDocument"
);
await ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(
fakeAddonActor
);
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
1,
"Got the expected number of debug browsers requested"
);
ok(
anotherDebugBrowser.parentElement === chromeDocument.documentElement,
"The second debug browser is still part of the hiddenXUL chromeDocument"
);
ok(
debugBrowser.parentElement == null,
"The first debug browser has been removed from the hiddenXUL chromeDocument"
);
await ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(
anotherFakeAddonActor
);
ok(
anotherDebugBrowser.parentElement == null,
"The second debug browser has been removed from the hiddenXUL chromeDocument"
);
equal(
ExtensionParent.DebugUtils.debugBrowserPromises.size,
0,
"All the addon debugging browsers has been released"
);
await extension.unload();
await anotherExtension.unload();
});
|