Back out 6d8c09f110ee (bug 1246028) for landing before it got its nits picked

This commit is contained in:
Phil Ringnalda 2016-02-24 18:40:42 -08:00
parent 3acf3b28aa
commit f60f95e5a9
5 changed files with 0 additions and 133 deletions

View File

@ -1,53 +0,0 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
PlatformInfo,
} = ExtensionUtils;
// WeakMap[Extension -> Map[name => Command]]
var commandsMap = new WeakMap();
function Command(description, shortcut) {
this.description = description;
this.shortcut = shortcut;
}
/* eslint-disable mozilla/balanced-listeners */
extensions.on("manifest_commands", (type, directive, extension, manifest) => {
let commands = new Map();
for (let name of Object.keys(manifest.commands)) {
let os = PlatformInfo.os == "win" ? "windows" : PlatformInfo.os;
let manifestCommand = manifest.commands[name];
let description = manifestCommand.description;
let shortcut = manifestCommand.suggested_key[os] || manifestCommand.suggested_key.default;
let command = new Command(description, shortcut);
commands.set(name, command);
}
commandsMap.set(extension, commands);
});
extensions.on("shutdown", (type, extension) => {
commandsMap.delete(extension);
});
/* eslint-enable mozilla/balanced-listeners */
extensions.registerSchemaAPI("commands", null, (extension, context) => {
return {
commands: {
getAll() {
let commands = Array.from(commandsMap.get(extension), ([name, command]) => {
return ({
name,
description: command.description,
shortcut: command.shortcut,
});
});
return Promise.resolve(commands);
},
},
};
});

View File

@ -5,7 +5,6 @@
browser.jar:
content/browser/extension.svg
content/browser/ext-utils.js
content/browser/ext-commands.js
content/browser/ext-contextMenus.js
content/browser/ext-browserAction.js
content/browser/ext-pageAction.js

View File

@ -9,7 +9,6 @@ support-files =
file_popup_api_injection_b.html
[browser_ext_simple.js]
[browser_ext_commands.js]
[browser_ext_currentWindow.js]
[browser_ext_browserAction_simple.js]
[browser_ext_browserAction_pageAction_icon.js]

View File

@ -1,77 +0,0 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
var {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm");
add_task(function* () {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"name": "Commands Extension",
"commands": {
"with-desciption": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
},
"description": "should have a description",
},
"without-description": {
"suggested_key": {
"default": "Ctrl+Shift+D",
},
},
"with-platform-info": {
"suggested_key": {
"mac": "Ctrl+Shift+M",
"linux": "Ctrl+Shift+L",
"windows": "Ctrl+Shift+W",
"android": "Ctrl+Shift+A",
},
},
},
},
background: function() {
browser.test.onMessage.addListener((message, additionalScope) => {
browser.commands.getAll((commands) => {
browser.test.log(JSON.stringify(commands));
browser.test.assertEq(commands.length, 3, "getAll should return an array of commands");
let command = commands.find(c => c.name == "with-desciption");
browser.test.assertEq("should have a description", command.description,
"The description should match what is provided in the manifest");
browser.test.assertEq("Ctrl+Shift+Y", command.shortcut,
"The shortcut should match the default shortcut provided in the manifest");
command = commands.find(c => c.name == "without-description");
browser.test.assertEq(null, command.description,
"The description should be empty when it is not provided");
browser.test.assertEq("Ctrl+Shift+D", command.shortcut,
"The shortcut should match the default shortcut provided in the manifest");
let platformKeys = {
macosx: "M",
linux: "L",
win: "W",
android: "A",
};
command = commands.find(c => c.name == "with-platform-info");
let platformKey = platformKeys[additionalScope.platform];
let shortcut = `Ctrl+Shift+${platformKey}`;
browser.test.assertEq(shortcut, command.shortcut,
`The shortcut should match the one provided in the manifest for OS='${additionalScope.platform}'`);
browser.test.notifyPass("commands");
});
});
browser.test.sendMessage("ready");
},
});
yield extension.startup();
yield extension.awaitMessage("ready");
extension.sendMessage("additional-scope", {platform: AppConstants.platform});
yield extension.awaitFinish("commands");
yield extension.unload();
});

View File

@ -546,7 +546,6 @@ BrowserGlue.prototype = {
ExtensionManagement.registerScript("chrome://browser/content/ext-utils.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-browserAction.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-pageAction.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-commands.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-contextMenus.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-desktop-runtime.js");
ExtensionManagement.registerScript("chrome://browser/content/ext-tabs.js");