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
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const STARTUP_APIS = ["backgroundPage"];
const STARTUP_MODULES = [
"resource://gre/modules/Extension.jsm",
"resource://gre/modules/ExtensionCommon.jsm",
"resource://gre/modules/ExtensionParent.jsm",
// FIXME: This is only loaded at startup for new extension installs.
// Otherwise the data comes from the startup cache. We should test for
// this.
"resource://gre/modules/ExtensionPermissions.jsm",
"resource://gre/modules/ExtensionProcessScript.jsm",
"resource://gre/modules/ExtensionUtils.jsm",
"resource://gre/modules/ExtensionTelemetry.jsm",
];
if (!Services.prefs.getBoolPref("extensions.webextensions.remote")) {
STARTUP_MODULES.push(
"resource://gre/modules/ExtensionChild.jsm",
"resource://gre/modules/ExtensionPageChild.jsm"
);
}
if (AppConstants.MOZ_APP_NAME == "thunderbird") {
STARTUP_MODULES.push(
"resource://gre/modules/ExtensionChild.jsm",
"resource://gre/modules/ExtensionContent.jsm",
"resource://gre/modules/ExtensionPageChild.jsm"
);
}
AddonTestUtils.init(this);
// Tests that only the minimal set of API scripts and modules are loaded at
// startup for a simple extension.
add_task(async function test_loaded_scripts() {
await ExtensionTestUtils.startAddonManager();
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "temporary",
background() {},
manifest: {},
});
await extension.startup();
const { apiManager } = ExtensionParent;
const loadedAPIs = Array.from(apiManager.modules.values())
.filter(m => m.loaded || m.asyncLoaded)
.map(m => m.namespaceName);
deepEqual(
loadedAPIs.sort(),
STARTUP_APIS,
"No extra APIs should be loaded at startup for a simple extension"
);
let loadedModules = Cu.loadedJSModules
.concat(Cu.loadedESModules)
.filter(url => url.startsWith("resource://gre/modules/Extension"));
deepEqual(
loadedModules.sort(),
STARTUP_MODULES.sort(),
"No extra extension modules should be loaded at startup for a simple extension"
);
await extension.unload();
});
|