1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/publicdomain/zero/1.0/
6 // This test uses add-on versions that follow the toolkit version but we
7 // started to encourage the use of a simpler format in Bug 1793925. We disable
8 // the pref below to avoid install errors.
9 Services.prefs.setBoolPref(
10 "extensions.webextensions.warnings-as-errors",
14 // IDs for scopes that should sideload when sideloading
17 getID(`legacy-global`),
20 getID(`legacy-profile`),
23 // This tests that, on a rebuild after addonStartup.json and extensions.json
24 // are lost, we only sideload from the profile.
25 add_task(async function test_sideloads_after_rebuild() {
28 // Create a sideloaded addon for each scope before the restriction is put
29 // in place (by updating the sideloadScopes preference).
30 for (let [name, dir] of Object.entries(scopeDirectories)) {
31 let id = getID(`legacy-${name}`);
33 await createWebExtension(id, initialVersion(name), dir);
36 await promiseStartupManager();
38 // SCOPE_APPLICATION will never sideload, so we expect 3
39 let sideloaded = await AddonManagerPrivate.getNewSideloads();
40 Assert.equal(sideloaded.length, 4, "four sideloaded addon");
41 let sideloadedIds = sideloaded.map(a => a.id);
42 for (let id of legacyIDs) {
43 Assert.ok(sideloadedIds.includes(id));
46 // After a restart that causes a database rebuild, we should have
47 // the same addons available
48 await promiseShutdownManager();
49 // Reset our scope pref so the scope limitation works.
50 Services.prefs.setIntPref(
51 "extensions.sideloadScopes",
52 AddonManager.SCOPE_PROFILE
55 // Try to sideload from a non-profile directory.
56 await createWebExtension(
57 getID(`sideload-global-1`),
58 initialVersion("sideload-global"),
62 await promiseStartupManager("2");
64 // We should still only have 4 addons.
65 let addons = await AddonManager.getAddonsByTypes(["extension"]);
66 Assert.equal(addons.length, 4, "addons remain installed");
68 await promiseShutdownManager();
70 // Install a sideload that will not load because it is not in
71 // appStartup.json and is not in a sideloadScope.
72 await createWebExtension(
73 getID(`sideload-global-2`),
74 initialVersion("sideload-global"),
77 await createWebExtension(
78 getID(`sideload-app-2`),
79 initialVersion("sideload-global"),
82 // Install a sideload that will load. We cannot currently prevent
84 await createWebExtension(
85 getID(`sideload-profile`),
86 initialVersion("sideload-profile"),
90 // Replace the extensions.json with something bogus so we lose our xpidatabase.
91 // On AOM startup, addons are restored with help from XPIState. Existing
92 // sideloads should all remain. One new sideloaded addon should be added from
94 await IOUtils.writeJSON(gExtensionsJSON.path, {
95 not: "what we expect to find",
97 info(`**** restart AOM and rebuild XPI database`);
98 await promiseStartupManager();
100 addons = await AddonManager.getAddonsByTypes(["extension"]);
101 Assert.equal(addons.length, 5, "addons installed");
103 await promiseShutdownManager();
105 // Install a sideload that will not load.
106 await createWebExtension(
107 getID(`sideload-global-3`),
108 initialVersion("sideload-global"),
111 // Install a sideload that will load. We cannot currently prevent
113 await createWebExtension(
114 getID(`sideload-profile-2`),
115 initialVersion("sideload-profile"),
119 // Replace the extensions.json with something bogus so we lose our xpidatabase.
120 await IOUtils.writeJSON(gExtensionsJSON.path, {
121 not: "what we expect to find",
123 // Delete our appStartup/XPIState data. Now we should only be able to
124 // restore extensions in the profile.
125 gAddonStartup.remove(true);
126 info(`**** restart AOM and rebuild XPI database`);
128 await promiseStartupManager();
130 addons = await AddonManager.getAddonsByTypes(["extension"]);
131 Assert.equal(addons.length, 3, "addons installed");
133 let [a1, a2, a3] = await promiseAddonsByIDs([
134 getID(`legacy-profile`),
135 getID(`sideload-profile`),
136 getID(`sideload-profile-2`),
139 Assert.notEqual(a1, null);
140 Assert.ok(isExtensionInBootstrappedList(profileDir, a1.id));
142 Assert.notEqual(a2, null);
143 Assert.ok(isExtensionInBootstrappedList(profileDir, a2.id));
145 Assert.notEqual(a3, null);
146 Assert.ok(isExtensionInBootstrappedList(profileDir, a3.id));
148 await promiseShutdownManager();