Bug 1429150 - Create an enterprise policy to prevent the application from checking for app updates r=Felipe

MozReview-Commit-ID: 4K4U4AJw7V1

--HG--
extra : rebase_source : 310c3534d57442942ba6852bcfe842d096da2948
extra : source : de8d7142b665913237d88208363cbeb2697e8ead
This commit is contained in:
Kirk Steuber 2018-02-07 09:49:37 -08:00
Родитель 4905862de3
Коммит a89871ae9d
10 изменённых файлов: 85 добавлений и 2 удалений

Просмотреть файл

@ -20,6 +20,12 @@ const POLICIES_FILENAME = "policies.json";
// and set PREF_ALTERNATE_PATH in firefox.js as:
// /your/repo/browser/components/enterprisepolicies/helpers/sample.json
const PREF_ALTERNATE_PATH = "browser.policies.alternatePath";
// For testing, we may want to set PREF_ALTERNATE_PATH to point to a file
// relative to the test root directory. In order to enable this, the string
// below may be placed at the beginning of that preference value and it will
// be replaced with the path to the test root directory.
const MAGIC_TEST_ROOT_PREFIX = "<test-root>";
const PREF_TEST_ROOT = "mochitest.testRoot";
// This pref is meant to be temporary: it will only be used while we're
// testing this feature without rolling it out officially. When the
@ -319,6 +325,18 @@ class JSONPoliciesProvider {
// the admin-provided policies by changing the user-controlled prefs.
// This pref is only meant for tests, so it's fine to use this extra
// synchronous configFile.exists() above.
if (alternatePath.startsWith(MAGIC_TEST_ROOT_PREFIX)) {
// Intentionally not using a default value on this pref lookup. If no
// test root is set, we are not currently testing and this function
// should throw rather than returning something.
let testRoot = Services.prefs.getStringPref(PREF_TEST_ROOT);
let relativePath = alternatePath.substring(MAGIC_TEST_ROOT_PREFIX.length);
if (AppConstants.platform == "win") {
relativePath = relativePath.replace(/\//g, "\\");
}
alternatePath = testRoot + relativePath;
}
configFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsIFile);
configFile.initWithPath(alternatePath);

Просмотреть файл

@ -37,6 +37,14 @@ this.Policies = {
}
},
"DisableAppUpdate": {
onBeforeAddons(manager, param) {
if (param == true) {
manager.disallowFeature("appUpdate");
}
}
},
"display_menu_bar": {
onBeforeUIStartup(manager, param) {
if (param == true) {

Просмотреть файл

@ -10,6 +10,15 @@
"enum": [true]
},
"DisableAppUpdate": {
"description": "Prevent the browser from updating.",
"first_available": "60.0",
"enterprise_only": true,
"type": "boolean",
"enum": [true]
},
"display_menu_bar": {
"description": "Causes the menu bar to be displayed by default.",
"first_available": "60.0",

Просмотреть файл

@ -11,6 +11,7 @@ support-files =
[browser_policies_setAndLockPref_API.js]
[browser_policies_simple_policies.js]
[browser_policies_validate_and_parse_API.js]
[browser_policy_app_update.js]
[browser_policy_block_set_desktop_background.js]
[browser_policy_default_browser_check.js]
[browser_policy_disable_fxscreenshots.js]

Просмотреть файл

@ -0,0 +1,19 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var updateService = Cc["@mozilla.org/updates/update-service;1"].
getService(Ci.nsIApplicationUpdateService);
// This test is intended to ensure that nsIUpdateService::canCheckForUpdates
// is true before the "DisableAppUpdate" policy is applied. Testing that
// nsIUpdateService::canCheckForUpdates is false after the "DisableAppUpdate"
// policy is applied needs to occur in a different test since the policy does
// not properly take effect unless it is applied during application startup.
add_task(async function test_updates_pre_policy() {
is(Services.policies.isAllowed("appUpdate"), true,
"Since no policies have been set, appUpdate should be allowed by default");
is(updateService.canCheckForUpdates, true,
"Should be able to check for updates before any policies are in effect.");
});

Просмотреть файл

@ -0,0 +1,8 @@
[DEFAULT]
prefs =
browser.policies.enabled=true
browser.policies.alternatePath='<test-root>/browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json'
support-files =
config_disable_app_update.json
[browser_policy_disable_app_update.js]

Просмотреть файл

@ -0,0 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var updateService = Cc["@mozilla.org/updates/update-service;1"].
getService(Ci.nsIApplicationUpdateService);
add_task(async function test_updates_post_policy() {
is(Services.policies.isAllowed("appUpdate"), false,
"appUpdate should be disabled by policy.");
is(updateService.canCheckForUpdates, false,
"Should not be able to check for updates with DisableAppUpdate enabled.");
});

Просмотреть файл

@ -0,0 +1,5 @@
{
"policies": {
"DisableAppUpdate": true
}
}

Просмотреть файл

@ -8,5 +8,6 @@ with Files("**"):
BUG_COMPONENT = ("Firefox", "General")
BROWSER_CHROME_MANIFESTS += [
'browser/browser.ini'
'browser/browser.ini',
'browser/disable_app_update/browser.ini'
]

Просмотреть файл

@ -119,7 +119,7 @@ if (AppConstants.MOZ_GECKO_PROFILER) {
if (AppConstants.MOZ_TOOLKIT_SEARCH) {
initTable.search = ["@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"];
}
if (AppConstants.MOZ_BUILD_APP == "browser") {
if ("@mozilla.org/browser/enterprisepolicies;1" in Cc) {
initTable.policies = ["@mozilla.org/browser/enterprisepolicies;1", "nsIEnterprisePolicies"];
}