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:
Mark Striemer 2018-01-31 15:49:20 -06:00
parent 35992a1b90
commit 8c26de1d7c
3 changed files with 40 additions and 0 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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);