Commit 42b53c41 authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1560808 - Don't activate policy engine if there are no policies. r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D46973

--HG--
extra : moz-landing-system : lando
parent 245b8785
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
add_task(async function test_notice_in_aboutprefences() { add_task(async function test_notice_in_aboutprefences() {
await setupPolicyEngineWithJson({ await setupPolicyEngineWithJson({
policies: {}, policies: {
DummyPolicy: true,
},
}); });
await BrowserTestUtils.withNewTab("about:preferences", async browser => { await BrowserTestUtils.withNewTab("about:preferences", async browser => {
......
...@@ -438,7 +438,10 @@ class JSONPoliciesProvider { ...@@ -438,7 +438,10 @@ class JSONPoliciesProvider {
} }
get hasPolicies() { get hasPolicies() {
return this._policies !== null || this._failed; return (
this._failed ||
(this._policies !== null && Object.keys(this._policies).length)
);
} }
get policies() { get policies() {
...@@ -543,7 +546,7 @@ class WindowsGPOPoliciesProvider { ...@@ -543,7 +546,7 @@ class WindowsGPOPoliciesProvider {
} }
get hasPolicies() { get hasPolicies() {
return this._policies !== null; return this._policies !== null && Object.keys(this._policies).length;
} }
get policies() { get policies() {
...@@ -576,7 +579,7 @@ class macOSPoliciesProvider { ...@@ -576,7 +579,7 @@ class macOSPoliciesProvider {
} }
get hasPolicies() { get hasPolicies() {
return this._policies !== null; return this._policies !== null && Object.keys(this._policies).length;
} }
get policies() { get policies() {
......
...@@ -11,3 +11,5 @@ BROWSER_CHROME_MANIFESTS += [ ...@@ -11,3 +11,5 @@ BROWSER_CHROME_MANIFESTS += [
TESTING_JS_MODULES += [ TESTING_JS_MODULES += [
'EnterprisePolicyTesting.jsm', 'EnterprisePolicyTesting.jsm',
] ]
XPCSHELL_TESTS_MANIFESTS += ['xpcshell/xpcshell.ini']
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const { updateAppInfo, getAppInfo } = ChromeUtils.import(
"resource://testing-common/AppInfo.jsm"
);
const { FileTestUtils } = ChromeUtils.import(
"resource://testing-common/FileTestUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
updateAppInfo({
name: "XPCShell",
ID: "xpcshell@tests.mozilla.org",
version: "48",
platformVersion: "48",
});
// This initializes the policy engine for xpcshell tests
let policies = Cc["@mozilla.org/enterprisepolicies;1"].getService(
Ci.nsIObserver
);
policies.observe(null, "policies-startup", null);
// Any changes to this function should also be made to the corresponding version
// in toolkit/components/enterprisepolicies/tests/browser/head.js
async function setupPolicyEngineWithJson(json, customSchema) {
let filePath;
if (typeof json == "object") {
filePath = FileTestUtils.getTempFile("policies.json").path;
// This file gets automatically deleted by FileTestUtils
// at the end of the test run.
await OS.File.writeAtomic(filePath, JSON.stringify(json), {
encoding: "utf-8",
});
} else {
filePath = do_get_file(json ? json : "non-existing-file.json").path;
}
Services.prefs.setStringPref("browser.policies.alternatePath", filePath);
let promise = new Promise(resolve => {
Services.obs.addObserver(function observer() {
Services.obs.removeObserver(
observer,
"EnterprisePolicies:AllPoliciesApplied"
);
resolve();
}, "EnterprisePolicies:AllPoliciesApplied");
});
// Clear any previously used custom schema
Cu.unload("resource:///modules/policies/schema.jsm");
if (customSchema) {
let schemaModule = ChromeUtils.import(
"resource:///modules/policies/schema.jsm",
null
);
schemaModule.schema = customSchema;
}
Services.obs.notifyObservers(null, "EnterprisePolicies:Restart");
return promise;
}
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_app_update_URL() {
await setupPolicyEngineWithJson({
policies: {},
});
equal(
Services.policies.status,
Ci.nsIEnterprisePolicies.INACTIVE,
"Engine is not active"
);
});
[DEFAULT]
head = head.js
skip-if = toolkit == 'android'
[test_empty.js]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment