Bug 1493646 - Browser toolbox shortcut closes the regular toolbox; r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D7092

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan Odvarko 2018-10-03 11:38:49 +00:00
parent 1f43e0e744
commit e3949549a8
2 changed files with 46 additions and 1 deletions

View File

@ -223,9 +223,16 @@ KeyShortcuts.prototype = {
return false;
}
if (shortcut.shift != event.shiftKey) {
// Check the `keyCode` to see whether it's a character (see also Bug 1493646)
const char = String.fromCharCode(event.keyCode);
let isAlphabetical = (char.length == 1 && char.match(/[a-zA-Z]/));
// Shift is a special modifier, it may implicitly be required if the expected key
// is a special character accessible via shift.
const isAlphabetical = event.key && event.key.match(/[a-zA-Z]/);
if (!isAlphabetical) {
isAlphabetical = event.key && event.key.match(/[a-zA-Z]/);
}
// OSX: distinguish cmd+[key] from cmd+shift+[key] shortcuts (Bug 1300458)
const cmdShortcut = shortcut.meta && !shortcut.alt && !shortcut.ctrl;
if (isAlphabetical || cmdShortcut) {

View File

@ -24,6 +24,7 @@ add_task(async function() {
await testCtrlModifier(shortcuts);
await testInvalidShortcutString(shortcuts);
await testCmdShiftShortcut(shortcuts);
await testTabCharacterShortcut(shortcuts);
shortcuts.destroy();
await testTarget();
@ -422,3 +423,40 @@ function testInvalidShortcutString(shortcuts) {
shortcuts.on("Cmmd+F", function() {});
ok(true, "on() shouldn't throw when passing invalid shortcut string");
}
/**
* Shift+Alt+I generates ^ key (`event.key`) on OSX and KeyShortcuts module
* must ensure that this doesn't interfere with shortcuts CmdOrCtrl+Alt+Shift+I
* for opening the Browser Toolbox and CmdOrCtrl+Alt+I for toggling the Toolbox.
*/
async function testTabCharacterShortcut(shortcuts) {
if (!isOSX) {
return;
}
info("Test tab character shortcut");
once(shortcuts, "CmdOrCtrl+Alt+I", event => {
ok(false, "This handler must not be executed");
});
const onKey = once(shortcuts, "CmdOrCtrl+Alt+Shift+I", event => {
info("Test for CmdOrCtrl+Alt+Shift+I");
is(event.key, "^");
is(event.keyCode, 73);
});
// Simulate `CmdOrCtrl+Alt+Shift+I` shortcut. Note that EventUtils doesn't
// generate `^` like real keyboard, so we need to pass it explicitly
// and use proper keyCode for `I` character.
EventUtils.synthesizeKey("^", {
code: "KeyI",
key: "^",
keyCode: 73,
shiftKey: true,
altKey: true,
metaKey: true,
}, window);
await onKey;
}