зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1522757 - Remove addons with no shortcut from extension shortcut page r=mstriemer,Gijs,flod
Remove addons with no shortcut from extension shortcut page Differential Revision: https://phabricator.services.mozilla.com/D17861 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e5944cdd0e
Коммит
dd84380f1c
|
@ -300,8 +300,8 @@ extensions-updates-update-selected =
|
|||
manage-extensions-shortcuts =
|
||||
.label = Manage Extension Shortcuts
|
||||
.accesskey = S
|
||||
shortcuts-empty-message = There are no shortcuts for this extension.
|
||||
shortcuts-no-addons = You don’t have any extensions enabled.
|
||||
shortcuts-no-commands = The following extensions do not have shortcuts:
|
||||
shortcuts-input =
|
||||
.placeholder = Type a shortcut
|
||||
|
||||
|
|
|
@ -44,14 +44,15 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<template id="shortcuts-empty-template">
|
||||
<div class="shortcuts-empty-label" data-l10n-id="shortcuts-empty-message"></div>
|
||||
</template>
|
||||
|
||||
<template id="shortcuts-no-addons">
|
||||
<div data-l10n-id="shortcuts-no-addons"></div>
|
||||
</template>
|
||||
|
||||
<template id="shortcuts-no-commands-template">
|
||||
<div data-l10n-id="shortcuts-no-commands"></div>
|
||||
<ul class="shortcuts-no-commands-list"></ul>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -28,9 +28,9 @@ function loadTemplates() {
|
|||
|
||||
templates.card = document.getElementById("card-template");
|
||||
templates.row = document.getElementById("shortcut-row-template");
|
||||
templates.empty = document.getElementById("shortcuts-empty-template");
|
||||
templates.noAddons = document.getElementById("shortcuts-no-addons");
|
||||
templates.expandRow = document.getElementById("expand-row-template");
|
||||
templates.noShortcutAddons = document.getElementById("shortcuts-no-commands-template");
|
||||
}
|
||||
|
||||
function extensionForAddonId(id) {
|
||||
|
@ -261,14 +261,29 @@ function onShortcutChange(e) {
|
|||
}
|
||||
}
|
||||
|
||||
function renderNoShortcutAddons(addons) {
|
||||
let fragment = document.importNode(templates.noShortcutAddons.content, true);
|
||||
let list = fragment.querySelector(".shortcuts-no-commands-list");
|
||||
for (let addon of addons) {
|
||||
let addonItem = document.createElement("li");
|
||||
addonItem.textContent = addon.name;
|
||||
addonItem.setAttribute("addon-id", addon.id);
|
||||
list.appendChild(addonItem);
|
||||
}
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
async function renderAddons(addons) {
|
||||
let frag = document.createDocumentFragment();
|
||||
let noShortcutAddons = [];
|
||||
for (let addon of addons) {
|
||||
let extension = extensionForAddonId(addon.id);
|
||||
|
||||
// Skip this extension if it isn't a webextension.
|
||||
if (!extension) continue;
|
||||
|
||||
if (extension.shortcuts) {
|
||||
let card = document.importNode(
|
||||
templates.card.content, true).firstElementChild;
|
||||
let icon = AddonManager.getPreferredIconURL(addon, 24, window);
|
||||
|
@ -276,7 +291,6 @@ async function renderAddons(addons) {
|
|||
card.querySelector(".addon-icon").src = icon || FALLBACK_ICON;
|
||||
card.querySelector(".addon-name").textContent = addon.name;
|
||||
|
||||
if (extension.shortcuts) {
|
||||
let commands = await extension.shortcuts.allCommands();
|
||||
|
||||
// Sort the commands so the ones with shortcuts are at the top.
|
||||
|
@ -353,12 +367,17 @@ async function renderAddons(addons) {
|
|||
});
|
||||
card.appendChild(row);
|
||||
}
|
||||
} else {
|
||||
card.appendChild(document.importNode(templates.empty.content, true));
|
||||
}
|
||||
|
||||
frag.appendChild(card);
|
||||
} else {
|
||||
noShortcutAddons.push({ id: addon.id, name: addon.name });
|
||||
}
|
||||
}
|
||||
|
||||
if (noShortcutAddons.length > 0) {
|
||||
frag.appendChild(renderNoShortcutAddons(noShortcutAddons));
|
||||
}
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,24 @@ add_task(async function testUpdatingCommands() {
|
|||
await extension.startup();
|
||||
await extension.awaitMessage("ready");
|
||||
|
||||
let extension2 = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
browser_specific_settings: {
|
||||
gecko: {
|
||||
id: "addons@noShorcut",
|
||||
},
|
||||
},
|
||||
name: "no shortcut addon",
|
||||
},
|
||||
background() {
|
||||
browser.test.sendMessage("ready");
|
||||
},
|
||||
useAddonManager: "temporary",
|
||||
});
|
||||
|
||||
await extension2.startup();
|
||||
await extension2.awaitMessage("ready");
|
||||
|
||||
async function checkShortcut(name, key, modifiers) {
|
||||
EventUtils.synthesizeKey(key, modifiers);
|
||||
let message = await extension.awaitMessage("oncommand");
|
||||
|
@ -135,8 +153,22 @@ add_task(async function testUpdatingCommands() {
|
|||
checkLabel("commandTwo", "Command Two!");
|
||||
checkLabel("_execute_browser_action", "shortcuts-browserAction");
|
||||
|
||||
// Check there is only 1 shortcut card.
|
||||
let shortcutAddonsList = doc.querySelectorAll(".shortcut");
|
||||
is(shortcutAddonsList.length, 1, "There is only 1 addon card with shortcut");
|
||||
|
||||
// Check there is unordered list of shortcut-less addons.
|
||||
let noShortcutAddonsList = doc.querySelector(".shortcuts-no-commands-list");
|
||||
ok(noShortcutAddonsList, "There is an unordered list of addons without shortcuts");
|
||||
|
||||
// Check there is shortcut-less addon in the list.
|
||||
let addon = noShortcutAddonsList.querySelector(`[addon-id="addons@noShorcut"]`);
|
||||
ok(addon, "There is addon without shortcut in unordered list");
|
||||
is(addon.textContent, "no shortcut addon", "The add-on's name is set in the list");
|
||||
|
||||
await closeView();
|
||||
await extension.unload();
|
||||
await extension2.unload();
|
||||
});
|
||||
|
||||
async function startExtensionWithCommands(numCommands) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче