mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 18:55:30 +00:00
Bug 1421811 - Part 2: Support commands.reset() to reset a command's updates r=mixedpuppy
MozReview-Commit-ID: 4hWGo1ZH6tn --HG-- extra : rebase_source : afa5b3dff8f77b5d5f87e71aa63918e1a4d31bfd
This commit is contained in:
parent
35992a1b90
commit
8c26de1d7c
@ -335,6 +335,24 @@ this.commands = class extends ExtensionAPI {
|
||||
|
||||
this.registerKeys(commands);
|
||||
},
|
||||
reset: async (name) => {
|
||||
let {extension, manifestCommands} = this;
|
||||
let commands = await this.commands;
|
||||
let command = commands.get(name);
|
||||
|
||||
if (!command) {
|
||||
throw new ExtensionError(`Unknown command "${name}"`);
|
||||
}
|
||||
|
||||
let storedCommand = ExtensionSettingsStore.getSetting(
|
||||
"commands", name, extension.id);
|
||||
|
||||
if (storedCommand && storedCommand.value) {
|
||||
commands.set(name, {...manifestCommands.get(name)});
|
||||
ExtensionSettingsStore.removeSetting(extension.id, "commands", name);
|
||||
this.registerKeys(commands);
|
||||
}
|
||||
},
|
||||
onCommand: new EventManager(context, "commands.onCommand", fire => {
|
||||
let listener = (eventName, commandName) => {
|
||||
fire.async(commandName);
|
||||
|
@ -152,6 +152,19 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "reset",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"description": "Reset a command's details to what is specified in the manifest.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"description": "The name of the command."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "getAll",
|
||||
"type": "function",
|
||||
|
@ -72,6 +72,9 @@ add_task(async function test_update_defined_command() {
|
||||
if (msg == "update") {
|
||||
await browser.commands.update(data);
|
||||
return browser.test.sendMessage("updateDone");
|
||||
} else if (msg == "reset") {
|
||||
await browser.commands.reset(data);
|
||||
return browser.test.sendMessage("resetDone");
|
||||
} else if (msg != "run") {
|
||||
return;
|
||||
}
|
||||
@ -187,6 +190,12 @@ add_task(async function test_update_defined_command() {
|
||||
is(storedCommand.value.shortcut, "Alt+Shift+P", "The shortcut is saved correctly");
|
||||
is(storedCommand.value.description, "description only", "The description is saved correctly");
|
||||
|
||||
// Calling browser.commands.reset("foo") should reset to manifest version.
|
||||
extension.sendMessage("reset", "foo");
|
||||
await extension.awaitMessage("resetDone");
|
||||
|
||||
checkKey(extension.id, "I", "accel shift");
|
||||
|
||||
// Check that enable/disable removes the keyset and reloads the saved command.
|
||||
let addon = await AddonManager.getAddonByID(extension.id);
|
||||
await disableAddon(addon);
|
||||
|
Loading…
Reference in New Issue
Block a user