Source code

Revision control

Copy as Markdown

Other Tools

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
JsonSchema: "resource://gre/modules/JsonSchema.sys.mjs",
});
function assertValidates(validator, obj, msg) {
const result = validator.validate(obj);
Assert.ok(
result.valid && result.errors.length === 0,
`${msg} - errors = ${JSON.stringify(result.errors, undefined, 2)}`
);
}
async function fetchSchema(uri) {
try {
dump(`URI: ${uri}\n`);
return fetch(uri, { credentials: "omit" }).then(rsp => rsp.json());
} catch (e) {
throw new Error(`Could not fetch ${uri}`);
}
}
async function schemaValidatorFor(uri, { common = false } = {}) {
const schema = await fetchSchema(uri);
const validator = new lazy.JsonSchema.Validator(schema);
if (common) {
const commonSchema = await fetchSchema(
);
validator.addSchema(commonSchema);
}
return validator;
}
async function makeValidators() {
const experimentValidator = await schemaValidatorFor(
"chrome://browser/content/asrouter/schemas/MessagingExperiment.schema.json"
);
const messageValidators = {
cfr_doorhanger: await schemaValidatorFor(
{ common: true }
),
cfr_urlbar_chiclet: await schemaValidatorFor(
{ common: true }
),
infobar: await schemaValidatorFor(
{ common: true }
),
pb_newtab: await schemaValidatorFor(
{ common: true }
),
spotlight: await schemaValidatorFor(
{ common: true }
),
toast_notification: await schemaValidatorFor(
{ common: true }
),
toolbar_badge: await schemaValidatorFor(
{ common: true }
),
update_action: await schemaValidatorFor(
{ common: true }
),
feature_callout: await schemaValidatorFor(
// For now, Feature Callout and Spotlight share a common schema
{ common: true }
),
};
messageValidators.milestone_message = messageValidators.cfr_doorhanger;
return { experimentValidator, messageValidators };
}