copy from toolkit/mozapps/extensions/test/xpcshell/test_system_update_custom.js
copy to toolkit/mozapps/extensions/test/xpcshell/test_system_update_enterprisepolicy.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_system_update_custom.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_system_update_enterprisepolicy.js
@@ -1,11 +1,28 @@
-// Tests that system add-on upgrades work.
+/* 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
+// DisableSysAddonUpdate enterprise policy.
ChromeUtils.import("resource://testing-common/httpd.js");
+ChromeUtils.import("resource://testing-common/EnterprisePolicyTesting.jsm");
+
+// Setting PREF_DISABLE_SECURITY tells the policy engine that we are in testing
+// mode and enables restarting the policy engine without restarting the browser.
+Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, true);
+Services.prefs.setBoolPref("browser.policies.enabled", true);
+registerCleanupFunction(() => {
+ Services.prefs.clearUserPref(PREF_DISABLE_SECURITY);
+ Services.prefs.clearUserPref("browser.policies.enabled");
+});
+
+Services.policies; // Load policy engine
BootstrapMonitor.init();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2");
var testserver = new HttpServer();
testserver.registerDirectory("/data/", do_get_file("data/system_addons"));
testserver.start();
@@ -14,257 +31,48 @@ var root = testserver.identity.primarySc
testserver.identity.primaryPort + "/data/";
Services.prefs.setCharPref(PREF_SYSTEM_ADDON_UPDATE_URL, root + "update.xml");
let distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "empty"], true);
registerDirectory("XREAppFeat", distroDir);
initSystemAddonDirs();
/**
- * Defines the set of initial conditions to run each test against. Each should
- * define the following properties:
+ * 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 = {
- // Runs tests with no updated or default system add-ons initially installed
- blank: {
- 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}
- ],
- },
- // Runs tests with default system add-ons installed
- withAppSet: {
- setup() {
- clearSystemAddonUpdatesDir();
- distroDir.leafName = "prefilled";
- },
- initialState: [
- { isUpgrade: false, version: null},
- { isUpgrade: false, version: "2.0"},
- { isUpgrade: false, version: "2.0"},
- { isUpgrade: false, version: null},
- { isUpgrade: false, version: null}
- ]
+ setup() {
+ clearSystemAddonUpdatesDir();
+ distroDir.leafName = "empty";
},
-
- // Runs tests with updated system add-ons installed
- withProfileSet: {
- setup() {
- buildPrefilledUpdatesDir();
- distroDir.leafName = "empty";
- },
- initialState: [
- { isUpgrade: false, version: null},
- { isUpgrade: true, version: "2.0"},
- { isUpgrade: true, version: "2.0"},
- { isUpgrade: false, version: null},
- { isUpgrade: false, version: null}
- ]
- },
-
- // Runs tests with both default and updated system add-ons installed
- withBothSets: {
- setup() {
- buildPrefilledUpdatesDir();
- distroDir.leafName = "hidden";
- },
- initialState: [
- { isUpgrade: false, version: "1.0"},
- { isUpgrade: true, version: "2.0"},
- { isUpgrade: true, version: "2.0"},
- { isUpgrade: false, version: null},
- { isUpgrade: false, version: null}
- ]
- },
+ initialState: [
+ { isUpgrade: false, version: null},
+ { isUpgrade: false, version: null},
+ { isUpgrade: false, version: null},
+ { isUpgrade: false, version: null},
+ { isUpgrade: false, version: null}
+ ],
};
-// Test that the update check is performed as part of the regular add-on update
-// check
-add_task(async function test_addon_update() {
- await setupSystemAddonConditions(TEST_CONDITIONS.blank, distroDir);
+add_task(async function test_update_disabled_by_policy() {
+ await setupSystemAddonConditions(TEST_CONDITIONS, distroDir);
+
+ await EnterprisePolicyTesting.setupPolicyEngineWithJson({
+ "policies": {
+ "DisableSysAddonUpdate": true
+ }
+ });
await updateAllSystemAddons(await buildSystemAddonUpdates([
{ id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
{ id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" }
], root), testserver);
- await verifySystemAddonState(TEST_CONDITIONS.blank.initialState, [
- {isUpgrade: false, version: null},
- {isUpgrade: true, version: "2.0"},
- {isUpgrade: true, version: "2.0"},
- {isUpgrade: false, version: null},
- {isUpgrade: false, version: null}
- ], false, distroDir);
-
- await promiseShutdownManager();
-});
-
-// Disabling app updates should block system add-on updates
-add_task(async function test_app_update_disabled() {
- await setupSystemAddonConditions(TEST_CONDITIONS.blank, distroDir);
-
- Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, false);
- await updateAllSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" }
- ], root), testserver);
- Services.prefs.clearUserPref(PREF_APP_UPDATE_ENABLED);
-
- await verifySystemAddonState(TEST_CONDITIONS.blank.initialState, undefined, false, distroDir);
-
- await promiseShutdownManager();
-});
-
-// Safe mode should block system add-on updates
-add_task(async function test_safe_mode() {
- gAppInfo.inSafeMode = true;
-
- await setupSystemAddonConditions(TEST_CONDITIONS.blank, distroDir);
-
- Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, false);
- await updateAllSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" }
- ], root), testserver);
- Services.prefs.clearUserPref(PREF_APP_UPDATE_ENABLED);
-
- await verifySystemAddonState(TEST_CONDITIONS.blank.initialState, undefined, false, distroDir);
-
- await promiseShutdownManager();
-
- gAppInfo.inSafeMode = false;
-});
-
-// Tests that a set that matches the default set does nothing
-add_task(async function test_match_default() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withAppSet, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" }
- ], root), testserver);
-
- // Shouldn't have installed an updated set
- await verifySystemAddonState(TEST_CONDITIONS.withAppSet.initialState, undefined, false, distroDir);
-
- await promiseShutdownManager();
-});
-
-// Tests that a set that matches the hidden default set works
-add_task(async function test_match_default_revert() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withBothSets, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system1@tests.mozilla.org", version: "1.0", path: "system1_1.xpi" },
- { id: "system2@tests.mozilla.org", version: "1.0", path: "system2_1.xpi" }
- ], root), testserver);
-
- // This should revert to the default set instead of installing new versions
- // into an updated set.
- await verifySystemAddonState(TEST_CONDITIONS.withBothSets.initialState, [
- {isUpgrade: false, version: "1.0"},
- {isUpgrade: false, version: "1.0"},
- {isUpgrade: false, version: null},
- {isUpgrade: false, version: null},
- {isUpgrade: false, version: null}
- ], false, distroDir);
+ await verifySystemAddonState(TEST_CONDITIONS.initialState, undefined, false, distroDir);
await promiseShutdownManager();
});
-
-// Tests that a set that matches the current set works
-add_task(async function test_match_current() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withBothSets, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" }
- ], root), testserver);
-
- // This should remain with the current set instead of creating a new copy
- let set = JSON.parse(Services.prefs.getCharPref(PREF_SYSTEM_ADDON_SET));
- Assert.equal(set.directory, "prefilled");
-
- await verifySystemAddonState(TEST_CONDITIONS.withBothSets.initialState, undefined, false, distroDir);
-
- await promiseShutdownManager();
-});
-
-// Tests that a set with a minor change doesn't re-download existing files
-add_task(async function test_no_download() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withBothSets, distroDir);
-
- // The missing file here is unneeded since there is a local version already
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "missing.xpi" },
- { id: "system4@tests.mozilla.org", version: "1.0", path: "system4_1.xpi" }
- ], root), testserver);
-
- await verifySystemAddonState(TEST_CONDITIONS.withBothSets.initialState, [
- {isUpgrade: false, version: "1.0"},
- {isUpgrade: true, version: "2.0"},
- {isUpgrade: false, version: null},
- {isUpgrade: true, version: "1.0"},
- {isUpgrade: false, version: null}
- ], false, distroDir);
-
- await promiseShutdownManager();
-});
-
-// Tests that a second update before a restart works
-add_task(async function test_double_update() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withAppSet, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
- ], root), testserver);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system3@tests.mozilla.org", version: "2.0", path: "system3_2.xpi" },
- { id: "system4@tests.mozilla.org", version: "1.0", path: "system4_1.xpi" }
- ], root), testserver);
-
- await verifySystemAddonState(TEST_CONDITIONS.withAppSet.initialState, [
- {isUpgrade: false, version: null},
- {isUpgrade: false, version: "2.0"},
- {isUpgrade: true, version: "2.0"},
- {isUpgrade: true, version: "1.0"},
- {isUpgrade: false, version: null}
- ], true, distroDir);
-
- await promiseShutdownManager();
-});
-
-// A second update after a restart will delete the original unused set
-add_task(async function test_update_purges() {
- await setupSystemAddonConditions(TEST_CONDITIONS.withBothSets, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates([
- { id: "system2@tests.mozilla.org", version: "2.0", path: "system2_2.xpi" },
- { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
- ], root), testserver);
-
- await verifySystemAddonState(TEST_CONDITIONS.withBothSets.initialState, [
- {isUpgrade: false, version: "1.0"},
- {isUpgrade: true, version: "2.0"},
- {isUpgrade: true, version: "1.0"},
- {isUpgrade: false, version: null},
- {isUpgrade: false, version: null}
- ], false, distroDir);
-
- await installSystemAddons(await buildSystemAddonUpdates(null), testserver);
-
- let dirs = await getSystemAddonDirectories();
- Assert.equal(dirs.length, 1);
-
- await promiseShutdownManager();
-});