Bug 1382819 - Allow non-lowercase names for API extension experiments
Modify test_ext_experiments.js to use a non-lowercase id and name to catch a future regression
MozReview-Commit-ID: BRy2XNOtBXO
--- a/toolkit/components/extensions/test/xpcshell/test_ext_experiments.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_experiments.js
@@ -10,21 +10,21 @@ add_task(async function setup() {
});
add_task(async function test_experiments_api() {
let apiAddonFile = Extension.generateZipFile({
"install.rdf": `<?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest"
- em:id="meh@experiments.addons.mozilla.org"
- em:name="Meh Experiment"
+ em:id="fooBar@experiments.addons.mozilla.org"
+ em:name="FooBar Experiment"
em:type="256"
em:version="0.1"
- em:description="Meh experiment"
+ em:description="FooBar experiment"
em:creator="Mozilla">
<em:targetApplication>
<Description
em:id="xpcshell@tests.mozilla.org"
em:minVersion="48"
em:maxVersion="*"/>
</em:targetApplication>
@@ -35,73 +35,73 @@ add_task(async function test_experiments
"api.js": String.raw`
Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.notifyObservers(null, "webext-api-loaded", "");
class API extends ExtensionAPI {
getAPI(context) {
return {
- meh: {
+ fooBar: {
hello(text) {
- console.log('meh.hello API called', text);
+ console.log('fooBar.hello API called', text);
Services.obs.notifyObservers(null, "webext-api-hello", text);
}
}
}
}
}
`,
"schema.json": [
{
- "namespace": "meh",
- "description": "All full of meh.",
- "permissions": ["experiments.meh"],
+ "namespace": "fooBar",
+ "description": "All full of fooBar.",
+ "permissions": ["experiments.fooBar"],
"functions": [
{
"name": "hello",
"type": "function",
"description": "Hates you. This is all.",
"parameters": [
{"type": "string", "name": "text"},
],
},
],
},
],
});
let addonFile = Extension.generateXPI({
manifest: {
- applications: {gecko: {id: "meh@web.extension"}},
- permissions: ["experiments.meh"],
+ applications: {gecko: {id: "fooBar@web.extension"}},
+ permissions: ["experiments.fooBar"],
},
background() {
// The test code below checks that hello() is called at the right
// time with the string "Here I am". Verify that the api schema is
// being correctly interpreted by calling hello() with bad arguments
// and only calling hello() with the magic string if the call with
// bad arguments throws.
try {
- browser.meh.hello("I should not see this", "since two arguments are bad");
+ browser.fooBar.hello("I should not see this", "since two arguments are bad");
} catch (err) {
- browser.meh.hello("Here I am");
+ browser.fooBar.hello("Here I am");
}
},
});
let boringAddonFile = Extension.generateXPI({
manifest: {
applications: {gecko: {id: "boring@web.extension"}},
},
background() {
- if (browser.meh) {
- browser.meh.hello("Here I should not be");
+ if (browser.fooBar) {
+ browser.fooBar.hello("Here I should not be");
}
},
});
do_register_cleanup(() => {
for (let file of [apiAddonFile, addonFile, boringAddonFile]) {
Services.obs.notifyObservers(file, "flush-cache-entry");
file.remove(false);
@@ -125,17 +125,17 @@ add_task(async function test_experiments
Services.obs.removeObserver(observer, "webext-api-hello");
});
// Install API add-on.
let apiAddon = await AddonManager.installTemporaryAddon(apiAddonFile);
let {ExtensionAPIs} = Cu.import("resource://gre/modules/ExtensionAPI.jsm", {});
- ok(ExtensionAPIs.apis.has("meh"), "Should have meh API.");
+ ok(ExtensionAPIs.apis.has("fooBar"), "Should have fooBar API.");
// Install boring WebExtension add-on.
let boringAddon = await AddonManager.installTemporaryAddon(boringAddonFile);
await AddonTestUtils.promiseWebExtensionStartup();
// Install interesting WebExtension add-on.
let promise = new Promise(resolve => {
--- a/toolkit/mozapps/extensions/internal/APIExtensionBootstrap.js
+++ b/toolkit/mozapps/extensions/internal/APIExtensionBootstrap.js
@@ -13,17 +13,17 @@ var namespace;
var resource;
var resProto;
function install(data, reason) {
}
function startup(data, reason) {
namespace = data.id.replace(/@.*/, "");
- resource = `extension-${namespace}-api`;
+ resource = `extension-${namespace.toLowerCase()}-api`;
resProto = Services.io.getProtocolHandler("resource")
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
resProto.setSubstitution(resource, data.resourceURI);
ExtensionAPIs.register(
namespace,