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
|
"use strict";
const { JSONFile } = ChromeUtils.importESModule(
"resource://gre/modules/JSONFile.sys.mjs"
);
const aomStartup = Cc["@mozilla.org/addons/addon-manager-startup;1"].getService(
Ci.amIAddonManagerStartup
);
const gProfDir = do_get_profile();
Services.prefs.setIntPref(
"extensions.enabledScopes",
AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_APPLICATION
);
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42.0", "42.0");
const DUMMY_ID = "@dummy";
const DUMMY_ADDONS = {
addons: {
"@dummy": {
lastModifiedTime: 1337,
rootURI: "resource:///modules/themes/dummy/",
version: "1",
},
},
};
const TEST_ADDON_ID = "@test-theme";
const TEST_THEME = {
lastModifiedTime: 1337,
rootURI: "resource:///modules/themes/test/",
version: "1",
};
const TEST_ADDONS = {
addons: {
"@test-theme": TEST_THEME,
},
};
// Utility to write out various addonStartup.json files.
async function writeAOMStartupData(data) {
let jsonFile = new JSONFile({
path: PathUtils.join(gProfDir.path, "addonStartup.json.lz4"),
compression: "lz4",
});
jsonFile.data = data;
await jsonFile._save();
return aomStartup.readStartupData();
}
// This tests that any buitin removed from the build will
// get removed from the state data.
add_task(async function test_startup_missing_builtin() {
let startupData = await writeAOMStartupData({
"app-builtin": DUMMY_ADDONS,
});
Assert.ok(
!!startupData["app-builtin"].addons[DUMMY_ID],
"non-existant addon is in startup data"
);
await AddonTestUtils.promiseStartupManager();
await AddonTestUtils.promiseShutdownManager();
// This data is flushed on shutdown, so we check it after shutdown.
startupData = aomStartup.readStartupData();
Assert.equal(
startupData["app-builtin"].addons[DUMMY_ID],
undefined,
"non-existant addon is removed from startup data"
);
});
// This test verifies that a builtin installed prior to the
// second scan is not overwritten by old state data during
// the scan.
add_task(async function test_startup_default_theme_moved() {
let startupData = await writeAOMStartupData({
"app-profile": DUMMY_ADDONS,
"app-builtin": TEST_ADDONS,
});
Assert.ok(
!!startupData["app-profile"].addons[DUMMY_ID],
"non-existant addon is in startup data"
);
Assert.ok(
!!startupData["app-builtin"].addons[TEST_ADDON_ID],
"test addon is in startup data"
);
let themeDef = {
manifest: {
browser_specific_settings: { gecko: { id: TEST_ADDON_ID } },
version: "1.1",
theme: {},
},
};
await setupBuiltinExtension(themeDef, "second-loc");
await AddonTestUtils.promiseStartupManager("44");
await AddonManager.maybeInstallBuiltinAddon(
TEST_ADDON_ID,
"1.1",
"resource://second-loc/"
);
await AddonManagerPrivate.getNewSideloads();
let addon = await AddonManager.getAddonByID(TEST_ADDON_ID);
Assert.ok(!addon.foreignInstall, "addon was not marked as a foreign install");
Assert.equal(addon.version, "1.1", "addon version is correct");
await AddonTestUtils.promiseShutdownManager();
// This data is flushed on shutdown, so we check it after shutdown.
startupData = aomStartup.readStartupData();
Assert.equal(
startupData["app-builtin"].addons[TEST_ADDON_ID].version,
"1.1",
"startup data is correct in cache"
);
Assert.equal(
startupData["app-builtin"].addons[DUMMY_ID],
undefined,
"non-existant addon is removed from startup data"
);
});
// This test verifies that a builtin addon being updated
// is not marked as a foreignInstall.
add_task(async function test_startup_builtin_not_foreign() {
let startupData = await writeAOMStartupData({
"app-profile": DUMMY_ADDONS,
"app-builtin": {
addons: {
"@test-theme": {
...TEST_THEME,
rootURI: "resource://second-loc/",
},
},
},
});
Assert.ok(
!!startupData["app-profile"].addons[DUMMY_ID],
"non-existant addon is in startup data"
);
Assert.ok(
!!startupData["app-builtin"].addons[TEST_ADDON_ID],
"test addon is in startup data"
);
let themeDef = {
manifest: {
browser_specific_settings: { gecko: { id: TEST_ADDON_ID } },
version: "1.1",
theme: {},
},
};
await setupBuiltinExtension(themeDef, "second-loc");
await AddonTestUtils.promiseStartupManager("43");
await AddonManager.maybeInstallBuiltinAddon(
TEST_ADDON_ID,
"1.1",
"resource://second-loc/"
);
await AddonManagerPrivate.getNewSideloads();
let addon = await AddonManager.getAddonByID(TEST_ADDON_ID);
Assert.ok(!addon.foreignInstall, "addon was not marked as a foreign install");
Assert.equal(addon.version, "1.1", "addon version is correct");
await AddonTestUtils.promiseShutdownManager();
// This data is flushed on shutdown, so we check it after shutdown.
startupData = aomStartup.readStartupData();
Assert.equal(
startupData["app-builtin"].addons[TEST_ADDON_ID].version,
"1.1",
"startup data is correct in cache"
);
Assert.equal(
startupData["app-builtin"].addons[DUMMY_ID],
undefined,
"non-existant addon is removed from startup data"
);
});
|