summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_system_update_enterprisepolicy.js
blob: 2211a358621ed61761fcd11fc6e61f666868f342 (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
77
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// This test verifies that system addon updates are correctly blocked by the
// DisableSystemAddonUpdate enterprise policy.

const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
  "resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);

Services.policies; // Load policy engine

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

let distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "empty"], true);
registerDirectory("XREAppFeat", distroDir);
add_task(() => initSystemAddonDirs());

/**
 * Defines the set of initial conditions to run the test against.
 *
 * setup:        A task to setup the profile into the initial state.
 * initialState: The initial expected system add-on state after setup has run.
 *
 * These conditions run tests with no updated or default system add-ons
 * initially installed
 */
const TEST_CONDITIONS = {
  setup() {
    clearSystemAddonUpdatesDir();
    distroDir.leafName = "empty";
  },
  initialState: [
    { isUpgrade: false, version: null },
    { isUpgrade: false, version: null },
    { isUpgrade: false, version: null },
    { isUpgrade: false, version: null },
    { isUpgrade: false, version: null },
  ],
};

add_task(async function test_update_disabled_by_policy() {
  await setupSystemAddonConditions(TEST_CONDITIONS, distroDir);

  await EnterprisePolicyTesting.setupPolicyEngineWithJson({
    policies: {
      DisableSystemAddonUpdate: true,
    },
  });

  await updateAllSystemAddons(
    buildSystemAddonUpdates([
      {
        id: "system2@tests.mozilla.org",
        version: "2.0",
        path: "system2_2.xpi",
        xpi: await getSystemAddonXPI(2, "2.0"),
      },
      {
        id: "system3@tests.mozilla.org",
        version: "2.0",
        path: "system3_2.xpi",
        xpi: await getSystemAddonXPI(3, "2.0"),
      },
    ])
  );

  await verifySystemAddonState(
    TEST_CONDITIONS.initialState,
    undefined,
    false,
    distroDir
  );

  await promiseShutdownManager();
});