diff --git a/toolkit/components/extensions/Schemas.jsm b/toolkit/components/extensions/Schemas.jsm index b6c3513766fe..c673956e9030 100644 --- a/toolkit/components/extensions/Schemas.jsm +++ b/toolkit/components/extensions/Schemas.jsm @@ -1904,8 +1904,33 @@ class IntegerType extends Type { } class BooleanType extends Type { + static get EXTRA_PROPERTIES() { + return ["enum", ...super.EXTRA_PROPERTIES]; + } + + static parseSchema(root, schema, path, extraProperties = []) { + this.checkSchemaProperties(schema, path, extraProperties); + let enumeration = schema.enum || null; + return new this(schema, enumeration); + } + + constructor(schema, enumeration) { + super(schema); + this.enumeration = enumeration; + } + normalize(value, context) { - return this.normalizeBase("boolean", value, context); + if (!this.checkBaseType(getValueBaseType(value))) { + return context.error(() => `Expected boolean instead of ${JSON.stringify(value)}`, + `be a boolean`); + } + value = this.preprocess(value, context); + if (this.enumeration && !this.enumeration.includes(value)) { + return context.error(() => `Invalid value ${JSON.stringify(value)}`, + `be ${this.enumeration}`); + } + this.checkDeprecated(context, value); + return {value}; } checkBaseType(baseType) { diff --git a/toolkit/components/extensions/schemas/manifest.json b/toolkit/components/extensions/schemas/manifest.json index 10238018e401..597a7c80007d 100644 --- a/toolkit/components/extensions/schemas/manifest.json +++ b/toolkit/components/extensions/schemas/manifest.json @@ -578,8 +578,17 @@ }, { "id": "PersistentBackgroundProperty", - "type": "boolean", - "deprecated": "Event pages are not currently supported. This will run as a persistent background page." + "choices": [ + { + "type": "boolean", + "enum": [true] + }, + { + "type": "boolean", + "enum": [false], + "deprecated": "Event pages are not currently supported. This will run as a persistent background page." + } + ] } ] } diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_eventpage_warning.js b/toolkit/components/extensions/test/xpcshell/test_ext_eventpage_warning.js index d09c040b941d..5d7f03b04946 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_eventpage_warning.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_eventpage_warning.js @@ -44,6 +44,20 @@ add_task(async function test_eventpages() { "nonExistentProp": true, }, }, + { + message: "testing persistent background page", + eventPage: { + "page": "event-page.html", + "persistent": true, + }, + }, + { + message: "testing scripts with persistent background running as a background page", + eventPage: { + "scripts": ["event_page_script.js"], + "persistent": true, + }, + }, ]; let {messages} = await promiseConsoleOutput(async () => { @@ -61,5 +75,5 @@ add_task(async function test_eventpages() { {message: /Event pages are not currently supported./}, {message: /Event pages are not currently supported./}, {message: /Reading manifest: Error processing background.nonExistentProp: An unexpected property was found/}, - ]}); + ]}, true); }); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js index be0acef4d05c..2ca362135058 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js @@ -1739,3 +1739,42 @@ add_task(async function testReturns() { "Doesn't throw for invalid result value in release builds"); } }); + +let booleanEnumJson = [{ + namespace: "booleanEnum", + + types: [ + { + "id": "enumTrue", + "type": "boolean", + "enum": [true], + }, + ], + functions: [ + { + name: "paramMustBeTrue", + type: "function", + parameters: [ + {name: "arg", "$ref": "enumTrue"}, + ], + }, + ], +}]; + +add_task(async function testBooleanEnum() { + let url = "data:," + JSON.stringify(booleanEnumJson); + Schemas._rootSchema = null; + await Schemas.load(url); + + let root = {}; + tallied = null; + Schemas.inject(root, wrapper); + Assert.equal(tallied, null); + + ok(root.booleanEnum, "namespace exists"); + root.booleanEnum.paramMustBeTrue(true); + verify("call", "booleanEnum", "paramMustBeTrue", [true]); + Assert.throws(() => root.booleanEnum.paramMustBeTrue(false), + /Type error for parameter arg \(Invalid value false\) for booleanEnum\.paramMustBeTrue\./, + "should throw because enum of the type restricts parameter to true"); +});