diff --git a/testing/specialpowers/content/SpecialPowersObserverAPI.js b/testing/specialpowers/content/SpecialPowersObserverAPI.js
index 2a6999a1c2dc..fa7eee6b9347 100644
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -570,6 +570,7 @@ SpecialPowersObserverAPI.prototype = {
}).then(() => {
this._sendReply(aMessage, "SPExtensionMessage", {id, type: "extensionStarted", args: []});
}).catch(e => {
+ dump(`Extension startup failed: ${e}\n${e.stack}`);
this._sendReply(aMessage, "SPExtensionMessage", {id, type: "extensionFailed", args: []});
});
return undefined;
diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm
index 6389af9606be..574a3e06c352 100644
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -82,6 +82,7 @@ ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extensio
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/i18n.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/idle.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/runtime.json");
+ExtensionManagement.registerSchema("chrome://extensions/content/schemas/storage.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/test.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_navigation.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_request.json");
@@ -383,16 +384,23 @@ GlobalManager = {
injectAPI(api, browserObj);
let schemaApi = Management.generateAPIs(extension, context, Management.schemaApis);
+ function findPath(path) {
+ let obj = schemaApi;
+ for (let elt of path) {
+ obj = obj[elt];
+ }
+ return obj;
+ };
let schemaWrapper = {
get cloneScope() {
return context.cloneScope;
},
- callFunction(ns, name, args) {
- return schemaApi[ns][name](...args);
+ callFunction(path, name, args) {
+ return findPath(path)[name](...args);
},
- callAsyncFunction(ns, name, args, callback) {
+ callAsyncFunction(path, name, args, callback) {
// We pass an empty stub function as a default callback for
// the `chrome` API, so promise objects are not returned,
// and lastError values are reported immediately.
@@ -402,7 +410,7 @@ GlobalManager = {
let promise;
try {
- promise = schemaApi[ns][name](...args);
+ promise = findPath(path)[name](...args);
} catch (e) {
if (e instanceof context.cloneScope.Error) {
promise = Promise.reject(e);
@@ -415,22 +423,22 @@ GlobalManager = {
return context.wrapPromise(promise || Promise.resolve(), callback);
},
- getProperty(ns, name) {
- return schemaApi[ns][name];
+ getProperty(path, name) {
+ return findPath(path)[name];
},
- setProperty(ns, name, value) {
- schemaApi[ns][name] = value;
+ setProperty(path, name, value) {
+ findPath(path)[name] = value;
},
- addListener(ns, name, listener, args) {
- return schemaApi[ns][name].addListener.call(null, listener, ...args);
+ addListener(path, name, listener, args) {
+ return findPath(path)[name].addListener.call(null, listener, ...args);
},
- removeListener(ns, name, listener) {
- return schemaApi[ns][name].removeListener.call(null, listener);
+ removeListener(path, name, listener) {
+ return findPath(path)[name].removeListener.call(null, listener);
},
- hasListener(ns, name, listener) {
- return schemaApi[ns][name].hasListener.call(null, listener);
+ hasListener(path, name, listener) {
+ return findPath(path)[name].hasListener.call(null, listener);
},
};
Schemas.inject(browserObj, schemaWrapper);
diff --git a/toolkit/components/extensions/Schemas.jsm b/toolkit/components/extensions/Schemas.jsm
index 4894cdde2ed9..a91eab607da2 100644
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -305,7 +305,7 @@ class Entry {
// nothing. |context| is used to call the actual implementation
// of a given function or event. It's an object with properties
// callFunction, addListener, removeListener, and hasListener.
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
}
}
@@ -468,7 +468,7 @@ class StringType extends Type {
return baseType == "string";
}
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
if (this.enumeration) {
let obj = Cu.createObjectIn(dest, {defineAs: name});
for (let e of this.enumeration) {
@@ -623,6 +623,15 @@ class ObjectType extends Type {
}
}
+// This type is just a placeholder to be referred to by
+// SubModuleProperty. No value is ever expected to have this type.
+class SubModuleType extends Type {
+ constructor(functions) {
+ super();
+ this.functions = functions;
+ }
+};
+
class NumberType extends Type {
normalize(value, context) {
let r = this.normalizeBase("number", value, context);
@@ -749,7 +758,7 @@ class ValueProperty extends Entry {
this.value = value;
}
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
dest[name] = this.value;
}
}
@@ -769,14 +778,14 @@ class TypeProperty extends Entry {
throw context.makeError(`${msg} for ${this.namespaceName}.${this.name}.`);
}
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
if (this.unsupported) {
return;
}
let getStub = () => {
this.checkDeprecated(context);
- return context.getProperty(this.namespaceName, name);
+ return context.getProperty(path, name);
};
let desc = {
@@ -803,20 +812,57 @@ class TypeProperty extends Entry {
}
}
+class SubModuleProperty extends Entry {
+ // A SubModuleProperty represents a tree of objects and properties
+ // to expose to an extension. Currently we support only a limited
+ // form of sub-module properties, where "$ref" points to a
+ // SubModuleType containing a list of functions and "properties" is
+ // a list of additional simple properties.
+ //
+ // name: Name of the property stuff is being added to.
+ // namespaceName: Namespace in which the property lives.
+ // reference: Name of the type defining the functions to add to the property.
+ // properties: Additional properties to add to the module (unsupported).
+ constructor(name, namespaceName, reference, properties) {
+ super();
+ this.name = name;
+ this.namespaceName = namespaceName;
+ this.reference = reference;
+ this.properties = properties;
+ }
+
+ inject(path, name, dest, wrapperFuncs) {
+ let obj = Cu.createObjectIn(dest, {defineAs: name});
+
+ let ns = Schemas.namespaces.get(this.namespaceName);
+ let type = ns.get(this.reference);
+ if (!type || !(type instanceof SubModuleType)) {
+ throw new Error(`Internal error: ${this.namespaceName}.${this.reference} is not a sub-module`);
+ }
+
+ let functions = type.functions;
+ for (let fun of functions) {
+ fun.inject(path.concat(name), fun.name, obj, wrapperFuncs);
+ }
+
+ // TODO: Inject this.properties.
+ }
+};
+
// This class is a base class for FunctionEntrys and Events. It takes
// care of validating parameter lists (i.e., handling of optional
// parameters and parameter type checking).
class CallEntry extends Entry {
- constructor(schema, namespaceName, name, parameters, allowAmbiguousOptionalArguments) {
+ constructor(schema, path, name, parameters, allowAmbiguousOptionalArguments) {
super(schema);
- this.namespaceName = namespaceName;
+ this.path = path;
this.name = name;
this.parameters = parameters;
this.allowAmbiguousOptionalArguments = allowAmbiguousOptionalArguments;
}
throwError(context, msg) {
- throw context.makeError(`${msg} for ${this.namespaceName}.${this.name}.`);
+ throw context.makeError(`${msg} for ${this.path.join('.')}.${this.name}.`);
}
checkParameters(args, context) {
@@ -891,15 +937,15 @@ class CallEntry extends Entry {
// Represents a "function" defined in a schema namespace.
class FunctionEntry extends CallEntry {
- constructor(schema, namespaceName, name, type, unsupported, allowAmbiguousOptionalArguments, returns) {
- super(schema, namespaceName, name, type.parameters, allowAmbiguousOptionalArguments);
+ constructor(schema, path, name, type, unsupported, allowAmbiguousOptionalArguments, returns) {
+ super(schema, path, name, type.parameters, allowAmbiguousOptionalArguments);
this.unsupported = unsupported;
this.returns = returns;
this.isAsync = type.isAsync;
}
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
if (this.unsupported) {
return;
}
@@ -910,13 +956,13 @@ class FunctionEntry extends CallEntry {
this.checkDeprecated(context);
let actuals = this.checkParameters(args, context);
let callback = actuals.pop();
- return context.callAsyncFunction(this.namespaceName, name, actuals, callback);
+ return context.callAsyncFunction(path, name, actuals, callback);
};
} else {
stub = (...args) => {
this.checkDeprecated(context);
let actuals = this.checkParameters(args, context);
- return context.callFunction(this.namespaceName, name, actuals);
+ return context.callFunction(path, name, actuals);
};
}
Cu.exportFunction(stub, dest, {defineAs: name});
@@ -925,8 +971,8 @@ class FunctionEntry extends CallEntry {
// Represents an "event" defined in a schema namespace.
class Event extends CallEntry {
- constructor(schema, namespaceName, name, type, extraParameters, unsupported) {
- super(schema, namespaceName, name, extraParameters);
+ constructor(schema, path, name, type, extraParameters, unsupported) {
+ super(schema, path, name, extraParameters);
this.type = type;
this.unsupported = unsupported;
}
@@ -939,7 +985,7 @@ class Event extends CallEntry {
return r.value;
}
- inject(name, dest, context) {
+ inject(path, name, dest, context) {
if (this.unsupported) {
return;
}
@@ -947,17 +993,17 @@ class Event extends CallEntry {
let addStub = (listener, ...args) => {
listener = this.checkListener(listener, context);
let actuals = this.checkParameters(args, context);
- return context.addListener(this.namespaceName, name, listener, actuals);
+ return context.addListener(this.path, name, listener, actuals);
};
let removeStub = (listener) => {
listener = this.checkListener(listener, context);
- return context.removeListener(this.namespaceName, name, listener);
+ return context.removeListener(this.path, name, listener);
};
let hasStub = (listener) => {
listener = this.checkListener(listener, context);
- return context.hasListener(this.namespaceName, name, listener);
+ return context.hasListener(this.path, name, listener);
};
let obj = Cu.createObjectIn(dest, {defineAs: name});
@@ -981,7 +1027,7 @@ this.Schemas = {
ns.set(symbol, value);
},
- parseType(namespaceName, type, extraProperties = []) {
+ parseType(path, type, extraProperties = []) {
let allowedProperties = new Set(extraProperties);
// Do some simple validation of our own schemas.
@@ -989,7 +1035,7 @@ this.Schemas = {
let allowedSet = new Set([...allowedProperties, ...extra, "description", "deprecated"]);
for (let prop of Object.keys(type)) {
if (!allowedSet.has(prop)) {
- throw new Error(`Internal error: Namespace ${namespaceName} has invalid type property "${prop}" in type "${type.id || JSON.stringify(type)}"`);
+ throw new Error(`Internal error: Namespace ${path.join('.')} has invalid type property "${prop}" in type "${type.id || JSON.stringify(type)}"`);
}
}
}
@@ -997,12 +1043,12 @@ this.Schemas = {
if ("choices" in type) {
checkTypeProperties("choices");
- let choices = type.choices.map(t => this.parseType(namespaceName, t));
+ let choices = type.choices.map(t => this.parseType(path, t));
return new ChoiceType(type, choices);
} else if ("$ref" in type) {
checkTypeProperties("$ref");
let ref = type.$ref;
- let ns = namespaceName;
+ let ns = path[0];
if (ref.includes(".")) {
[ns, ref] = ref.split(".");
}
@@ -1054,10 +1100,17 @@ this.Schemas = {
type.maxLength || Infinity,
pattern,
format);
+ } else if (type.type == "object" && "functions" in type) {
+ checkTypeProperties("functions");
+
+ // The path we pass in here is only used for error messages.
+ let functions = type.functions.map(fun => this.parseFunction(path.concat(type.id), fun));
+
+ return new SubModuleType(functions);
} else if (type.type == "object") {
let parseProperty = (type, extraProps = []) => {
return {
- type: this.parseType(namespaceName, type,
+ type: this.parseType(path, type,
["unsupported", ...extraProps]),
optional: type.optional || false,
unsupported: type.unsupported || false,
@@ -1086,7 +1139,7 @@ this.Schemas = {
let additionalProperties = null;
if (type.additionalProperties) {
- additionalProperties = this.parseType(namespaceName, type.additionalProperties);
+ additionalProperties = this.parseType(path, type.additionalProperties);
}
if ("$extend" in type) {
@@ -1098,7 +1151,7 @@ this.Schemas = {
return new ObjectType(type, properties, additionalProperties, patternProperties, type.isInstanceOf || null);
} else if (type.type == "array") {
checkTypeProperties("items", "minItems", "maxItems");
- return new ArrayType(type, this.parseType(namespaceName, type.items),
+ return new ArrayType(type, this.parseType(path, type.items),
type.minItems || 0, type.maxItems || Infinity);
} else if (type.type == "number") {
checkTypeProperties();
@@ -1121,7 +1174,7 @@ this.Schemas = {
let isCallback = isAsync && param.name == type.async;
parameters.push({
- type: this.parseType(namespaceName, param, ["name", "optional"]),
+ type: this.parseType(path, param, ["name", "optional"]),
name: param.name,
optional: param.optional == null ? isCallback : param.optional,
});
@@ -1148,11 +1201,22 @@ this.Schemas = {
}
},
+ parseFunction(path, fun) {
+ let f = new FunctionEntry(fun, path, fun.name,
+ this.parseType(path, fun,
+ ["name", "unsupported", "returns",
+ "allowAmbiguousOptionalArguments"]),
+ fun.unsupported || false,
+ fun.allowAmbiguousOptionalArguments || false,
+ fun.returns || null);
+ return f;
+ },
+
loadType(namespaceName, type) {
if ("$extend" in type) {
this.extendType(namespaceName, type);
} else {
- this.register(namespaceName, type.id, this.parseType(namespaceName, type, ["id"]));
+ this.register(namespaceName, type.id, this.parseType([namespaceName], type, ["id"]));
}
},
@@ -1169,7 +1233,7 @@ this.Schemas = {
throw new Error(`Internal error: Attempt to extend a non-extensible type ${type.$extend}`);
}
- let parsed = this.parseType(namespaceName, type, ["$extend"]);
+ let parsed = this.parseType([namespaceName], type, ["$extend"]);
if (parsed.constructor !== targetType.constructor) {
throw new Error(`Internal error: Bad attempt to extend ${type.$extend}`);
}
@@ -1178,24 +1242,23 @@ this.Schemas = {
},
loadProperty(namespaceName, name, prop) {
- if ("value" in prop) {
+ if ("$ref" in prop) {
+ if (!prop.unsupported) {
+ this.register(namespaceName, name, new SubModuleProperty(name, namespaceName, prop["$ref"],
+ prop.properties || {}));
+ }
+ } else if ("value" in prop) {
this.register(namespaceName, name, new ValueProperty(prop, name, prop.value));
} else {
// We ignore the "optional" attribute on properties since we
// don't inject anything here anyway.
- let type = this.parseType(namespaceName, prop, ["optional", "writable"]);
+ let type = this.parseType([namespaceName], prop, ["optional", "writable"]);
this.register(namespaceName, name, new TypeProperty(prop, namespaceName, name, type, prop.writable || false));
}
},
loadFunction(namespaceName, fun) {
- let f = new FunctionEntry(fun, namespaceName, fun.name,
- this.parseType(namespaceName, fun,
- ["name", "unsupported", "returns",
- "allowAmbiguousOptionalArguments"]),
- fun.unsupported || false,
- fun.allowAmbiguousOptionalArguments || false,
- fun.returns || null);
+ let f = this.parseFunction([namespaceName], fun);
this.register(namespaceName, fun.name, f);
},
@@ -1203,7 +1266,7 @@ this.Schemas = {
let extras = event.extraParameters || [];
extras = extras.map(param => {
return {
- type: this.parseType(namespaceName, param, ["name", "optional"]),
+ type: this.parseType([namespaceName], param, ["name", "optional"]),
name: param.name,
optional: param.optional || false,
};
@@ -1215,11 +1278,11 @@ this.Schemas = {
let filters = event.filters;
/* eslint-enable no-unused-vars */
- let type = this.parseType(namespaceName, event,
+ let type = this.parseType([namespaceName], event,
["name", "unsupported",
"extraParameters", "returns", "filters"]);
- let e = new Event(event, namespaceName, event.name, type, extras,
+ let e = new Event(event, [namespaceName], event.name, type, extras,
event.unsupported || false);
this.register(namespaceName, event.name, e);
},
@@ -1256,7 +1319,7 @@ this.Schemas = {
for (let [namespace, ns] of this.namespaces) {
let obj = Cu.createObjectIn(dest, {defineAs: namespace});
for (let [name, entry] of ns) {
- entry.inject(name, obj, new Context(wrapperFuncs));
+ entry.inject([namespace], name, obj, new Context(wrapperFuncs));
}
if (!Object.keys(obj).length) {
diff --git a/toolkit/components/extensions/ext-storage.js b/toolkit/components/extensions/ext-storage.js
index f2f833954663..6396ae921a98 100644
--- a/toolkit/components/extensions/ext-storage.js
+++ b/toolkit/components/extensions/ext-storage.js
@@ -10,7 +10,7 @@ var {
EventManager,
} = ExtensionUtils;
-extensions.registerPrivilegedAPI("storage", (extension, context) => {
+extensions.registerSchemaAPI("storage", "storage", (extension, context) => {
return {
storage: {
local: {
diff --git a/toolkit/components/extensions/schemas/jar.mn b/toolkit/components/extensions/schemas/jar.mn
index 9ed73500645b..7696e70d0fd0 100644
--- a/toolkit/components/extensions/schemas/jar.mn
+++ b/toolkit/components/extensions/schemas/jar.mn
@@ -12,6 +12,7 @@ toolkit.jar:
content/extensions/schemas/idle.json
content/extensions/schemas/manifest.json
content/extensions/schemas/runtime.json
+ content/extensions/schemas/storage.json
content/extensions/schemas/test.json
content/extensions/schemas/web_navigation.json
content/extensions/schemas/web_request.json
diff --git a/toolkit/components/extensions/schemas/storage.json b/toolkit/components/extensions/schemas/storage.json
new file mode 100644
index 000000000000..a34803b406cb
--- /dev/null
+++ b/toolkit/components/extensions/schemas/storage.json
@@ -0,0 +1,222 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+[
+ {
+ "namespace": "storage",
+ "description": "Use the browser.storage
API to store, retrieve, and track changes to user data.",
+ "types": [
+ {
+ "id": "StorageChange",
+ "type": "object",
+ "properties": {
+ "oldValue": {
+ "type": "any",
+ "description": "The old value of the item, if there was an old value.",
+ "optional": true
+ },
+ "newValue": {
+ "type": "any",
+ "description": "The new value of the item, if there is a new value.",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "StorageArea",
+ "type": "object",
+ "functions": [
+ {
+ "name": "get",
+ "type": "function",
+ "description": "Gets one or more items from storage.",
+ "parameters": [
+ {
+ "name": "keys",
+ "choices": [
+ { "type": "string" },
+ { "type": "array", "items": { "type": "string" } },
+ {
+ "type": "object",
+ "description": "Storage items to return in the callback, where the values are replaced with those from storage if they exist.",
+ "additionalProperties": { "type": "any" }
+ }
+ ],
+ "description": "A single key to get, list of keys to get, or a dictionary specifying default values (see description of the object). An empty list or object will return an empty result object. Pass in null
to get the entire contents of storage.",
+ "optional": true
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "description": "Callback with storage items, or on failure (in which case $(ref:runtime.lastError) will be set).",
+ "parameters": [
+ {
+ "name": "items",
+ "type": "object",
+ "additionalProperties": { "type": "any" },
+ "description": "Object with items in their key-value mappings."
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "getBytesInUse",
+ "unsupported": true,
+ "type": "function",
+ "description": "Gets the amount of space (in bytes) being used by one or more items.",
+ "parameters": [
+ {
+ "name": "keys",
+ "choices": [
+ { "type": "string" },
+ { "type": "array", "items": { "type": "string" } }
+ ],
+ "description": "A single key or list of keys to get the total usage for. An empty list will return 0. Pass in null
to get the total usage of all of storage.",
+ "optional": true
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "description": "Callback with the amount of space being used by storage, or on failure (in which case $(ref:runtime.lastError) will be set).",
+ "parameters": [
+ {
+ "name": "bytesInUse",
+ "type": "integer",
+ "description": "Amount of space being used in storage, in bytes."
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "set",
+ "type": "function",
+ "description": "Sets multiple items.",
+ "parameters": [
+ {
+ "name": "items",
+ "type": "object",
+ "additionalProperties": { "type": "any" },
+ "description": "
An object which gives each key/value pair to update storage with. Any other key/value pairs in storage will not be affected.
Primitive values such as numbers will serialize as expected. Values with a typeof
\"object\"
and \"function\"
will typically serialize to {}
, with the exception of Array
(serializes as expected), Date
, and Regex
(serialize using their String
representation).
\"sync\"
, \"local\"
or \"managed\"
) the changes are for."
+ }
+ ]
+ }
+ ],
+ "properties": {
+ "sync": {
+ "unsupported": true,
+ "$ref": "StorageArea",
+ "description": "Items in the sync
storage area are synced by the browser.",
+ "properties": {
+ "QUOTA_BYTES": {
+ "value": 102400,
+ "description": "The maximum total amount (in bytes) of data that can be stored in sync storage, as measured by the JSON stringification of every value plus every key's length. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
+ },
+ "QUOTA_BYTES_PER_ITEM": {
+ "value": 8192,
+ "description": "The maximum size (in bytes) of each individual item in sync storage, as measured by the JSON stringification of its value plus its key length. Updates containing items larger than this limit will fail immediately and set $(ref:runtime.lastError)."
+ },
+ "MAX_ITEMS": {
+ "value": 512,
+ "description": "The maximum number of items that can be stored in sync storage. Updates that would cause this limit to be exceeded will fail immediately and set $(ref:runtime.lastError)."
+ },
+ "MAX_WRITE_OPERATIONS_PER_HOUR": {
+ "value": 1800,
+ "description": "The maximum number of set
, remove
, or clear
operations that can be performed each hour. This is 1 every 2 seconds, a lower ceiling than the short term higher writes-per-minute limit.
Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError).
" + }, + "MAX_WRITE_OPERATIONS_PER_MINUTE": { + "value": 120, + "description": "The maximum number of set
, remove
, or clear
operations that can be performed each minute. This is 2 per second, providing higher throughput than writes-per-hour over a shorter period of time.
Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError).
" + }, + "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE": { + "value": 1000000, + "deprecated": "The storage.sync API no longer has a sustained write operation quota.", + "description": "" + } + } + }, + "local": { + "$ref": "StorageArea", + "description": "Items in thelocal
storage area are local to each machine.",
+ "properties": {
+ "QUOTA_BYTES": {
+ "value": 5242880,
+ "description": "The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the unlimitedStorage
permission. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
+ }
+ }
+ },
+ "managed": {
+ "unsupported": true,
+ "$ref": "StorageArea",
+ "description": "Items in the managed
storage area are set by the domain administrator, and are read-only for the extension; trying to modify this namespace results in an error."
+ }
+ }
+ }
+]
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
index d994a8ae0c0f..9a90fd1e4f97 100644
--- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
@@ -9,6 +9,13 @@ let json = [
properties: {
PROP1: {value: 20},
prop2: {type: "string"},
+ prop3: {
+ $ref: "submodule",
+ },
+ prop4: {
+ $ref: "submodule",
+ unsupported: true,
+ },
},
types: [
@@ -55,6 +62,18 @@ let json = [
{type: "string"},
],
},
+
+ {
+ id: "submodule",
+ type: "object",
+ functions: [
+ {
+ name: "sub_foo",
+ type: "function",
+ parameters: []
+ },
+ ],
+ },
],
functions: [
@@ -298,25 +317,31 @@ let wrapper = {
talliedErrors.push(message);
},
- callFunction(ns, name, args) {
+ callFunction(path, name, args) {
+ let ns = path.join(".");
tally("call", ns, name, args);
},
- getProperty(ns, name) {
+ getProperty(path, name) {
+ let ns = path.join(".");
tally("get", ns, name);
},
- setProperty(ns, name, value) {
+ setProperty(path, name, value) {
+ let ns = path.join(".");
tally("set", ns, name, value);
},
- addListener(ns, name, listener, args) {
+ addListener(path, name, listener, args) {
+ let ns = path.join(".");
tally("addListener", ns, name, [listener, args]);
},
- removeListener(ns, name, listener) {
+ removeListener(path, name, listener) {
+ let ns = path.join(".");
tally("removeListener", ns, name, [listener]);
},
- hasListener(ns, name, listener) {
+ hasListener(path, name, listener) {
+ let ns = path.join(".");
tally("hasListener", ns, name, [listener]);
},
};
@@ -588,6 +613,14 @@ add_task(function* () {
Assert.throws(() => root.testing.extended2(true),
/Incorrect argument types/,
"should throw for wrong argument type");
+
+ root.testing.prop3.sub_foo();
+ verify("call", "testing.prop3", "sub_foo", []);
+ tallied = null;
+
+ Assert.throws(() => root.testing.prop4.sub_foo(),
+ /root.testing.prop4 is undefined/,
+ "should throw for unsupported submodule");
});
let deprecatedJson = [