blob: 2311f7610501af19439b8e9b3b5c5620835a54b6 (
plain)
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
|
"use strict";
function delay(time) {
return new Promise(resolve => {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(resolve, time);
});
}
const { Extension } = ChromeUtils.importESModule(
"resource://gre/modules/Extension.sys.mjs"
);
add_task(async function test_startup_request_handler() {
const ID = "request-startup@xpcshell.mozilla.org";
let extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: { gecko: { id: ID } },
},
files: {
"meh.txt": "Meh.",
},
});
let ready = false;
let resolvePromise;
let promise = new Promise(resolve => {
resolvePromise = resolve;
});
promise.then(() => {
ready = true;
});
let origInitLocale = Extension.prototype.initLocale;
Extension.prototype.initLocale = async function initLocale() {
await promise;
return origInitLocale.call(this);
};
let startupPromise = extension.startup();
await delay(0);
let policy = WebExtensionPolicy.getByID(ID);
let url = policy.getURL("meh.txt");
let resp = ExtensionTestUtils.fetch(url, url);
resp.then(() => {
ok(ready, "Shouldn't get response before extension is ready");
});
await delay(2000);
resolvePromise();
await startupPromise;
let body = await resp;
equal(body, "Meh.", "Got the correct response");
await extension.unload();
Extension.prototype.initLocale = origInitLocale;
});
|