summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/head_sideload.js
blob: 8ff3f2f0728f85800f70482ea92d686b8125433b (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
65
66
67
68
69
70
71
72
73
74
75
76
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

/* import-globals-from head_addons.js */

// Enable all scopes.
Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_ALL);
// Setting this to all enables the same behavior as before disabling sideloading.
// We reset this later after doing some legacy sideloading.
Services.prefs.setIntPref("extensions.sideloadScopes", AddonManager.SCOPE_ALL);
// AddonTestUtils sets this to zero, we need the default value.
Services.prefs.clearUserPref("extensions.autoDisableScopes");

createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");

function getID(n) {
  return `${n}@tests.mozilla.org`;
}
function initialVersion(n) {
  return `${n}.0`;
}

// Setup some common extension locations, one in each scope.

// SCOPE_SYSTEM
const globalDir = gProfD.clone();
globalDir.append("app-system-share");
globalDir.append(gAppInfo.ID);
registerDirectory("XRESysSExtPD", globalDir.parent);

// SCOPE_USER
const userDir = gProfD.clone();
userDir.append("app-system-user");
userDir.append(gAppInfo.ID);
registerDirectory("XREUSysExt", userDir.parent);

// SCOPE_APPLICATION
const addonAppDir = gProfD.clone();
addonAppDir.append("app-global");
addonAppDir.append("extensions");
registerDirectory("XREAddonAppDir", addonAppDir.parent);

// SCOPE_PROFILE
const profileDir = gProfD.clone();
profileDir.append("extensions");

const scopeDirectories = {
  global: globalDir,
  user: userDir,
  app: addonAppDir,
  profile: profileDir,
};

const scopeToDir = new Map([
  [AddonManager.SCOPE_SYSTEM, globalDir],
  [AddonManager.SCOPE_USER, userDir],
  [AddonManager.SCOPE_APPLICATION, addonAppDir],
  [AddonManager.SCOPE_PROFILE, profileDir],
]);

async function createWebExtension(id, version, dir) {
  let xpi = AddonTestUtils.createTempWebExtensionFile({
    manifest: {
      version,
      browser_specific_settings: { gecko: { id } },
    },
  });
  await AddonTestUtils.manuallyInstall(xpi, dir);
}

function check_startup_changes(aType, aIds) {
  let changes = AddonManager.getStartupChanges(aType);
  changes = changes.filter(aEl => /@tests.mozilla.org$/.test(aEl));

  Assert.deepEqual([...aIds].sort(), changes.sort());
}