Bug 1816987 - ESMified browser/components/enterprisepolicies/schemas r=kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D174495
This commit is contained in:
Bilal 2023-04-27 19:23:00 +00:00
parent 58b5467f89
commit 76a6a97929
13 changed files with 33 additions and 32 deletions

View File

@ -37,8 +37,8 @@ browser/components/sessionstore/test/unit/data/sessionstore_valid.js
browser/components/sessionstore/test/unit/data/sessionstore_invalid.js
# This file is split into two in order to keep it as a valid json file
# for documentation purposes (policies.json) but to be accessed by the
# code as a .jsm (schema.jsm)
browser/components/enterprisepolicies/schemas/schema.jsm
# code as a .sys.mjs (schema.sys.mjs)
browser/components/enterprisepolicies/schemas/schema.sys.mjs
# generated or library files in pocket
browser/components/pocket/content/panels/js/tmpl.js
browser/components/pocket/content/panels/js/vendor.bundle.js

View File

@ -101,8 +101,8 @@ browser/components/sessionstore/test/unit/data/sessionstore_valid.js
browser/components/sessionstore/test/unit/data/sessionstore_invalid.js
# This file is split into two in order to keep it as a valid json file
# for documentation purposes (policies.json) but to be accessed by the
# code as a .jsm (schema.jsm)
browser/components/enterprisepolicies/schemas/schema.jsm
# code as a .sys.mjs (schema.sys.mjs)
browser/components/enterprisepolicies/schemas/schema.sys.mjs
# generated or library files in pocket
browser/components/pocket/content/panels/js/tmpl.js
browser/components/pocket/content/panels/js/vendor.bundle.js

View File

@ -8,8 +8,8 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
XPCOMUtils.defineLazyModuleGetters(this, {
schema: "resource:///modules/policies/schema.jsm",
ChromeUtils.defineESModuleGetters(this, {
schema: "resource:///modules/policies/schema.sys.mjs",
});
function col(text, className) {

View File

@ -8,5 +8,5 @@ with Files("**"):
BUG_COMPONENT = ("Firefox", "Enterprise Policies")
EXTRA_PP_JS_MODULES.policies += [
"schema.jsm",
"schema.sys.mjs",
]

View File

@ -2,9 +2,15 @@
* 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 EXPORTED_SYMBOLS = ["schema"];
const schema =
const initialSchema =
#include policies-schema.json
export let schema = initialSchema;
export function modifySchemaForTests(customSchema) {
if (customSchema) {
schema = customSchema;
} else {
schema = initialSchema;
}
}

View File

@ -19,8 +19,8 @@ function checkArrayIsSorted(array, msg) {
}
add_task(async function test_policies_sorted() {
let { schema } = ChromeUtils.import(
"resource:///modules/policies/schema.jsm"
let { schema } = ChromeUtils.importESModule(
"resource:///modules/policies/schema.sys.mjs"
);
let { Policies } = ChromeUtils.importESModule(
"resource:///modules/policies/Policies.sys.mjs"
@ -37,8 +37,8 @@ add_task(async function test_policies_sorted() {
});
add_task(async function check_naming_conventions() {
let { schema } = ChromeUtils.import(
"resource:///modules/policies/schema.jsm"
let { schema } = ChromeUtils.importESModule(
"resource:///modules/policies/schema.sys.mjs"
);
equal(
Object.keys(schema.properties).some(key => key.includes("__")),

View File

@ -103,7 +103,7 @@ this.experiments_urlbar = class extends ExtensionAPI {
value: Preferences.get(pref),
// Nothing actually uses this, but on debug builds there are extra
// checks enabled in Schema.jsm that fail if it's not present. The
// checks enabled in Schema.sys.mjs that fail if it's not present. The
// value doesn't matter.
levelOfControl: "controllable_by_this_extension",
};

View File

@ -678,7 +678,7 @@ skip-if = os == "android"
run-sequentially = node server exceptions dont replay well
[test_proxy_pac.js]
[test_trr_enterprise_policy.js]
firefox-appdir = browser # needed for resource:///modules/policies/schema.jsm to be registered
firefox-appdir = browser # needed for resource:///modules/policies/schema.sys.mjs to be registered
skip-if =
os == "android"
socketprocess_networking

View File

@ -170,8 +170,8 @@ EnterprisePoliciesManager.prototype = {
},
_activatePolicies(unparsedPolicies) {
let { schema } = ChromeUtils.import(
"resource:///modules/policies/schema.jsm"
let { schema } = ChromeUtils.importESModule(
"resource:///modules/policies/schema.sys.mjs"
);
for (let policyName of Object.keys(unparsedPolicies)) {

View File

@ -41,8 +41,8 @@ export var macOSPoliciesParser = {
},
removeUnknownPolicies(policies) {
let { schema } = ChromeUtils.import(
"resource:///modules/policies/schema.jsm"
let { schema } = ChromeUtils.importESModule(
"resource:///modules/policies/schema.sys.mjs"
);
for (let policyName of Object.keys(policies)) {

View File

@ -9,6 +9,7 @@ import { Assert } from "resource://testing-common/Assert.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
FileTestUtils: "resource://testing-common/FileTestUtils.sys.mjs",
modifySchemaForTests: "resource:///modules/policies/schema.sys.mjs",
});
export var EnterprisePolicyTesting = {
@ -41,15 +42,8 @@ export var EnterprisePolicyTesting = {
}, "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"
);
schemaModule.schema = customSchema;
}
// Clear any previously used custom schema or assign a new one
lazy.modifySchemaForTests(customSchema || null);
Services.obs.notifyObservers(null, "EnterprisePolicies:Restart");
return promise;

View File

@ -1,4 +1,5 @@
[DEFAULT]
firefox-appdir = browser
head = head.js
skip-if = toolkit == 'android'

View File

@ -120,7 +120,7 @@ excluded_from_imports_prefix = list(
# Files has macro.
"browser/app/profile/firefox.js",
"browser/branding/official/pref/firefox-branding.js",
"browser/components/enterprisepolicies/schemas/schema.jsm",
"browser/components/enterprisepolicies/schemas/schema.sys.mjs",
"browser/locales/en-US/firefox-l10n.js",
"mobile/android/app/geckoview-prefs.js",
"mobile/android/app/mobile.js",