Backed out changeset 70960616621c (bug 1246035) for eslint failures

--HG--
extra : rebase_source : 1aabe3c342278594617826d065640425eb557b19
This commit is contained in:
Carsten "Tomcat" Book 2016-03-18 10:04:15 +01:00
Родитель c3b26a6305
Коммит df65ba1904
6 изменённых файлов: 46 добавлений и 215 удалений

Просмотреть файл

@ -17,6 +17,10 @@ const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
// WeakMap[Extension -> BrowserAction]
var browserActionMap = new WeakMap();
function browserActionOf(extension) {
return browserActionMap.get(extension);
}
// Responsible for the browser_action section of the manifest as well
// as the associated popup.
function BrowserAction(options, extension) {
@ -199,12 +203,6 @@ BrowserAction.prototype = {
},
};
BrowserAction.for = (extension) => {
return browserActionMap.get(extension);
};
global.browserActionFor = BrowserAction.for;
/* eslint-disable mozilla/balanced-listeners */
extensions.on("manifest_browser_action", (type, directive, extension, manifest) => {
let browserAction = new BrowserAction(manifest.browser_action, extension);
@ -228,20 +226,20 @@ extensions.registerSchemaAPI("browserAction", null, (extension, context) => {
let tab = TabManager.activeTab;
fire(TabManager.convert(extension, tab));
};
BrowserAction.for(extension).on("click", listener);
browserActionOf(extension).on("click", listener);
return () => {
BrowserAction.for(extension).off("click", listener);
browserActionOf(extension).off("click", listener);
};
}).api(),
enable: function(tabId) {
let tab = tabId !== null ? TabManager.getTab(tabId) : null;
BrowserAction.for(extension).setProperty(tab, "enabled", true);
browserActionOf(extension).setProperty(tab, "enabled", true);
},
disable: function(tabId) {
let tab = tabId !== null ? TabManager.getTab(tabId) : null;
BrowserAction.for(extension).setProperty(tab, "enabled", false);
browserActionOf(extension).setProperty(tab, "enabled", false);
},
setTitle: function(details) {
@ -252,30 +250,30 @@ extensions.registerSchemaAPI("browserAction", null, (extension, context) => {
if (tab && title == "") {
title = null;
}
BrowserAction.for(extension).setProperty(tab, "title", title);
browserActionOf(extension).setProperty(tab, "title", title);
},
getTitle: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
let title = BrowserAction.for(extension).getProperty(tab, "title");
let title = browserActionOf(extension).getProperty(tab, "title");
return Promise.resolve(title);
},
setIcon: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
let icon = IconDetails.normalize(details, extension, context);
BrowserAction.for(extension).setProperty(tab, "icon", icon);
browserActionOf(extension).setProperty(tab, "icon", icon);
return Promise.resolve();
},
setBadgeText: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
BrowserAction.for(extension).setProperty(tab, "badgeText", details.text);
browserActionOf(extension).setProperty(tab, "badgeText", details.text);
},
getBadgeText: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
let text = BrowserAction.for(extension).getProperty(tab, "badgeText");
let text = browserActionOf(extension).getProperty(tab, "badgeText");
return Promise.resolve(text);
},
@ -287,23 +285,23 @@ extensions.registerSchemaAPI("browserAction", null, (extension, context) => {
// For internal consistency, we currently resolve both relative to the
// calling context.
let url = details.popup && context.uri.resolve(details.popup);
BrowserAction.for(extension).setProperty(tab, "popup", url);
browserActionOf(extension).setProperty(tab, "popup", url);
},
getPopup: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
let popup = BrowserAction.for(extension).getProperty(tab, "popup");
let popup = browserActionOf(extension).getProperty(tab, "popup");
return Promise.resolve(popup);
},
setBadgeBackgroundColor: function(details) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
BrowserAction.for(extension).setProperty(tab, "badgeBackgroundColor", details.color);
browserActionOf(extension).setProperty(tab, "badgeBackgroundColor", details.color);
},
getBadgeBackgroundColor: function(details, callback) {
let tab = details.tabId !== null ? TabManager.getTab(details.tabId) : null;
let color = BrowserAction.for(extension).getProperty(tab, "badgeBackgroundColor");
let color = browserActionOf(extension).getProperty(tab, "badgeBackgroundColor");
return Promise.resolve(color);
},
},

Просмотреть файл

@ -15,17 +15,10 @@ const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
// WeakMap[Extension -> CommandList]
var commandsMap = new WeakMap();
function CommandList(manifest, extension) {
this.extension = extension;
this.id = makeWidgetId(extension.id);
function CommandList(commandsObj, extensionID) {
this.commands = this.loadCommandsFromManifest(commandsObj);
this.keysetID = `ext-keyset-id-${makeWidgetId(extensionID)}`;
this.windowOpenListener = null;
// Map[{String} commandName -> {Object} commandProperties]
this.commands = this.loadCommandsFromManifest(manifest);
// WeakMap[Window -> <xul:keyset>]
this.keysetsMap = new WeakMap();
this.register();
EventEmitter.decorate(this);
}
@ -37,13 +30,11 @@ CommandList.prototype = {
*/
register() {
for (let window of WindowListManager.browserWindows()) {
this.registerKeysToDocument(window);
this.registerKeysToDocument(window.document);
}
this.windowOpenListener = (window) => {
if (!this.keysetsMap.has(window)) {
this.registerKeysToDocument(window);
}
this.registerKeysToDocument(window.document);
};
WindowListManager.addOpenListener(this.windowOpenListener);
@ -55,8 +46,9 @@ CommandList.prototype = {
*/
unregister() {
for (let window of WindowListManager.browserWindows()) {
if (this.keysetsMap.has(window)) {
this.keysetsMap.get(window).remove();
let keyset = window.document.getElementById(this.keysetID);
if (keyset) {
keyset.remove();
}
}
@ -65,15 +57,15 @@ CommandList.prototype = {
/**
* Creates a Map from commands for each command in the manifest.commands object.
* @param {Object} manifest The manifest JSON object.
* @param {Object} commandsObj The manifest.commands JSON object.
*/
loadCommandsFromManifest(manifest) {
loadCommandsFromManifest(commandsObj) {
let commands = new Map();
// For Windows, chrome.runtime expects 'win' while chrome.commands
// expects 'windows'. We can special case this for now.
let os = PlatformInfo.os == "win" ? "windows" : PlatformInfo.os;
for (let name of Object.keys(manifest.commands)) {
let command = manifest.commands[name];
for (let name of Object.keys(commandsObj)) {
let command = commandsObj[name];
commands.set(name, {
description: command.description,
shortcut: command.suggested_key[os] || command.suggested_key.default,
@ -84,18 +76,16 @@ CommandList.prototype = {
/**
* Registers the commands to a document.
* @param {ChromeWindow} window The XUL window to insert the Keyset.
* @param {Document} doc The XUL document to insert the Keyset.
*/
registerKeysToDocument(window) {
let doc = window.document;
registerKeysToDocument(doc) {
let keyset = doc.createElementNS(XUL_NS, "keyset");
keyset.id = `ext-keyset-id-${this.id}`;
keyset.id = this.keysetID;
this.commands.forEach((command, name) => {
let keyElement = this.buildKey(doc, name, command.shortcut);
keyset.appendChild(keyElement);
});
doc.documentElement.appendChild(keyset);
this.keysetsMap.set(window, keyset);
},
/**
@ -120,12 +110,7 @@ CommandList.prototype = {
// We remove all references to the key elements when the extension is shutdown,
// therefore the listeners for these elements will be garbage collected.
keyElement.addEventListener("command", (event) => {
if (name == "_execute_page_action") {
let win = event.target.ownerDocument.defaultView;
pageActionFor(this.extension).triggerAction(win);
} else {
this.emit("command", name);
}
this.emit("command", name);
});
/* eslint-enable mozilla/balanced-listeners */
@ -210,7 +195,7 @@ CommandList.prototype = {
/* eslint-disable mozilla/balanced-listeners */
extensions.on("manifest_commands", (type, directive, extension, manifest) => {
commandsMap.set(extension, new CommandList(manifest, extension));
commandsMap.set(extension, new CommandList(manifest.commands, extension.id));
});
extensions.on("shutdown", (type, extension) => {

Просмотреть файл

@ -2,7 +2,6 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
EventManager,
@ -11,6 +10,7 @@ var {
// WeakMap[Extension -> PageAction]
var pageActionMap = new WeakMap();
// Handles URL bar icons, including the |page_action| manifest entry
// and associated API.
function PageAction(options, extension) {
@ -123,19 +123,6 @@ PageAction.prototype = {
return this.buttons.get(window);
},
/**
* Triggers this page action for the given window, with the same effects as
* if it were clicked by a user.
*
* This has no effect if the page action is hidden for the selected tab.
*/
triggerAction(window) {
let pageAction = pageActionMap.get(this.extension);
if (pageAction.getProperty(window.gBrowser.selectedTab, "show")) {
pageAction.handleClick(window);
}
},
// Handles a click event on the page action button for the given
// window.
// If the page action has a |popup| property, a panel is opened to
@ -176,6 +163,11 @@ PageAction.prototype = {
},
};
PageAction.for = extension => {
return pageActionMap.get(extension);
};
/* eslint-disable mozilla/balanced-listeners */
extensions.on("manifest_page_action", (type, directive, extension, manifest) => {
let pageAction = new PageAction(manifest.page_action, extension);
@ -190,11 +182,6 @@ extensions.on("shutdown", (type, extension) => {
});
/* eslint-enable mozilla/balanced-listeners */
PageAction.for = extension => {
return pageActionMap.get(extension);
};
global.pageActionFor = PageAction.for;
extensions.registerSchemaAPI("pageAction", null, (extension, context) => {
return {

Просмотреть файл

@ -24,7 +24,6 @@ support-files =
[browser_ext_browserAction_popup.js]
[browser_ext_popup_api_injection.js]
[browser_ext_contextMenus.js]
[browser_ext_commands_execute_page_action.js]
[browser_ext_commands_getAll.js]
[browser_ext_commands_onCommand.js]
[browser_ext_getViews.js]

Просмотреть файл

@ -1,135 +0,0 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(function* test_execute_page_action_without_popup() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"commands": {
"_execute_page_action": {
"suggested_key": {
"default": "Alt+Shift+J",
},
},
"send-keys-command": {
"suggested_key": {
"default": "Alt+Shift+3",
},
},
},
"page_action": {},
},
background: function() {
let isShown = false;
browser.commands.onCommand.addListener((commandName) => {
if (commandName == "_execute_page_action") {
browser.test.fail(`The onCommand listener should never fire for ${commandName}.`);
} else if (commandName == "send-keys-command") {
if (!isShown) {
isShown = true;
browser.tabs.query({currentWindow: true, active: true}, tabs => {
tabs.forEach(tab => {
browser.pageAction.show(tab.id);
});
browser.test.sendMessage("send-keys");
});
}
}
});
browser.pageAction.onClicked.addListener(() => {
browser.test.assertTrue(isShown, "The onClicked event should fire if the page action is shown.");
browser.test.notifyPass("page-action-without-popup");
});
browser.test.sendMessage("send-keys");
},
});
yield extension.startup();
extension.onMessage("send-keys", () => {
EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
EventUtils.synthesizeKey("3", {altKey: true, shiftKey: true});
});
yield extension.awaitFinish("page-action-without-popup");
yield extension.unload();
});
add_task(function* test_execute_page_action_with_popup() {
let scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head><body>Test Popup</body></html>`;
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"commands": {
"_execute_page_action": {
"suggested_key": {
"default": "Alt+Shift+J",
},
},
"send-keys-command": {
"suggested_key": {
"default": "Alt+Shift+3",
},
},
},
"page_action": {
"default_popup": "popup.html",
},
},
files: {
"popup.html": scriptPage("popup.js"),
"popup.js": function() {
browser.runtime.sendMessage("popup-opened");
},
},
background: function() {
let isShown = false;
browser.commands.onCommand.addListener((message) => {
if (message == "_execute_page_action") {
browser.test.fail(`The onCommand listener should never fire for ${message}.`);
}
if (message == "send-keys-command") {
if (!isShown) {
isShown = true;
browser.tabs.query({currentWindow: true, active: true}, tabs => {
tabs.forEach(tab => {
browser.pageAction.show(tab.id);
});
browser.test.sendMessage("send-keys");
});
}
}
});
browser.pageAction.onClicked.addListener(() => {
browser.test.fail(`The onClicked listener should never fire when the pageAction has a popup.`);
});
browser.runtime.onMessage.addListener(msg => {
browser.test.assertEq(msg, "popup-opened", "expected popup opened");
browser.test.assertTrue(isShown, "The onClicked event should fire if the page action is shown.");
browser.test.notifyPass("page-action-with-popup");
});
browser.test.sendMessage("send-keys");
},
});
yield extension.startup();
extension.onMessage("send-keys", () => {
EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
EventUtils.synthesizeKey("3", {altKey: true, shiftKey: true});
});
yield extension.awaitFinish("page-action-with-popup");
yield extension.unload();
});

Просмотреть файл

@ -2,7 +2,7 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(function* test_user_defined_commands() {
add_task(function* () {
// Create a window before the extension is loaded.
let win1 = yield BrowserTestUtils.openNewBrowserWindow();
yield BrowserTestUtils.loadURI(win1.gBrowser.selectedBrowser, "about:robots");
@ -10,6 +10,7 @@ add_task(function* test_user_defined_commands() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"name": "Commands Extension",
"commands": {
"toggle-feature-using-alt-shift-3": {
"suggested_key": {
@ -26,8 +27,8 @@ add_task(function* test_user_defined_commands() {
},
background: function() {
browser.commands.onCommand.addListener((commandName) => {
browser.test.sendMessage("oncommand", commandName);
browser.commands.onCommand.addListener((message) => {
browser.test.sendMessage("oncommand", message);
});
browser.test.sendMessage("ready");
},
@ -52,12 +53,10 @@ add_task(function* test_user_defined_commands() {
// Confirm the keysets have been added to both windows.
let keysetID = `ext-keyset-id-${makeWidgetId(extension.id)}`;
let keyset = win1.document.getElementById(keysetID);
ok(keyset != null, "Expected keyset to exist");
is(keyset.childNodes.length, 2, "Expected keyset to have 2 children");
is(keyset.childNodes.length, 2, "Expected keyset to exist and have 2 children");
keyset = win2.document.getElementById(keysetID);
ok(keyset != null, "Expected keyset to exist");
is(keyset.childNodes.length, 2, "Expected keyset to have 2 children");
is(keyset.childNodes.length, 2, "Expected keyset to exist and have 2 children");
// Confirm that the commands are registered to both windows.
yield focusWindow(win1);
@ -85,5 +84,3 @@ add_task(function* test_user_defined_commands() {
SimpleTest.endMonitorConsole();
yield waitForConsole;
});