-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1924542 - Add test coverage for WebExtensions commands shortcuts …
…using F1-F19 keys. r=willdurand Depends on D230108 Differential Revision: https://phabricator.services.mozilla.com/D229813 UltraBlame original commit: 7711a1e3e9ae283378d663e435694845f35883c3
- Loading branch information
Showing
3 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,22 +39,28 @@ function disableAddon(addon) { | |
add_task(async function test_update_defined_command() { | ||
let extension; | ||
let updatedExtension; | ||
|
||
registerCleanupFunction(async () => { | ||
await extension.unload(); | ||
let needsCleanup = true; | ||
const cleanup = async () => { | ||
if (!needsCleanup) { | ||
return; | ||
} | ||
needsCleanup = false; | ||
const extensionId = extension.id; | ||
await extension?.unload(); | ||
|
||
await updatedExtension?.unload(); | ||
|
||
|
||
if (updatedExtension) { | ||
await updatedExtension.unload(); | ||
if (extensionId) { | ||
let storedCommands = ExtensionSettingsStore.getAllForExtension( | ||
extensionId, | ||
"commands" | ||
); | ||
is(storedCommands.length, 0, "There are no stored commands after unload"); | ||
} | ||
}; | ||
|
||
|
||
let storedCommands = ExtensionSettingsStore.getAllForExtension( | ||
extension.id, | ||
"commands" | ||
); | ||
is(storedCommands.length, 0, "There are no stored commands after unload"); | ||
}); | ||
registerCleanupFunction(cleanup); | ||
|
||
extension = ExtensionTestUtils.loadExtension({ | ||
useAddonManager: "permanent", | ||
|
@@ -352,6 +358,8 @@ add_task(async function test_update_defined_command() { | |
await TestUtils.waitForCondition(() => extensionKeyset(extension.id)); | ||
|
||
checkNumericKey(extension.id, "9", "alt,shift"); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
add_task(async function updateSidebarCommand() { | ||
|
@@ -517,3 +525,59 @@ add_task(async function test_extension_sidebar_shortcuts() { | |
|
||
await SpecialPowers.popPrefEnv(); | ||
}); | ||
|
||
add_task(async function test_extended_function_keys() { | ||
const extension = ExtensionTestUtils.loadExtension({ | ||
useAddonManager: "permanent", | ||
manifest: { | ||
version: "1.0", | ||
browser_specific_settings: { gecko: { id: "[email protected]" } }, | ||
commands: { | ||
foo: { | ||
suggested_key: { | ||
default: "Alt+Shift+F12", | ||
}, | ||
description: "The foo command", | ||
}, | ||
}, | ||
}, | ||
background() { | ||
browser.test.onMessage.addListener(async (msg, data) => { | ||
if (msg == "update") { | ||
await browser.commands.update(data); | ||
return browser.test.sendMessage("updateDone"); | ||
} | ||
}); | ||
browser.commands.onCommand.addListener(name => | ||
browser.test.sendMessage("oncommand", name) | ||
); | ||
browser.test.sendMessage("bgpage:ready"); | ||
}, | ||
}); | ||
|
||
await extension.startup(); | ||
await extension.awaitMessage("bgpage:ready"); | ||
|
||
|
||
info("Verify command listener called on original manifest-assigned shortcut"); | ||
EventUtils.synthesizeKey("VK_F12", { altKey: true, shiftKey: true }); | ||
is( | ||
await extension.awaitMessage("oncommand"), | ||
"foo", | ||
"Expect onCommand listener call for command foo on Alt+Shift+F12" | ||
); | ||
|
||
info("Update foo command shortcut to be set to Alt+Shift+F19"); | ||
extension.sendMessage("update", { name: "foo", shortcut: "Alt+Shift+F19" }); | ||
await extension.awaitMessage("updateDone"); | ||
|
||
info("Verify command listener called on extension-updated shortcut"); | ||
EventUtils.synthesizeKey("VK_F19", { altKey: true, shiftKey: true }); | ||
is( | ||
await extension.awaitMessage("oncommand"), | ||
"foo", | ||
"Expect onCommand listener call for command foo on Alt+Shift+F19" | ||
); | ||
|
||
await extension.unload(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters