Bug 1370077 - Avoid deprecation message when background.persistent is true r=robwu,aswan

Add support for enumerations to boolean types, and use it to only show
a deprecation message when background.persistent is false.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
edward.i.wu 2019-01-10 01:11:44 +00:00
parent e872cc3650
commit 06030d9eb9
4 changed files with 91 additions and 4 deletions

View File

@ -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) {

View File

@ -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."
}
]
}
]
}

View File

@ -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);
});

View File

@ -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");
});