Commit 7918420b authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cocoa: fix TestMOnDifferentLayouts keyequivalent test

10.15 introduced three new keyboard layouts that this test didn't
handle:
* Dhivehi-QWERTY, which behaves like DVORAK-QWERTYCMD but with a
  different base layout
* Kyrgyz-Cyrillic, which generates cyrillic characters only and
  doesn't match any key equivalents
* Mongolian-Cyrillic, which is similar

This change:
1) Generalizes the DVORAK-QWERTYCMD logic to also handle the new
   Dhivehi-QWERTY layout (and others if needed later);
2) Skips this test on the two new Cyrillic layouts

Bug: 998755
Change-Id: I1527974222b9e962379c70f8a57da5bc9cdba8e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825140
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Auto-Submit: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699884}
parent 4bc95abf
......@@ -18,6 +18,11 @@
// Used by tests to set internal state without having to change global input
// source.
void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty);
void SetIsInputSourceCommandQwertyForTesting(bool is_command_qwerty);
// Returns whether the named keyboard layout has the command-qwerty behavior,
// meaning that the layout acts as though it was QWERTY when the command key is
// held.
bool IsKeyboardLayoutCommandQwerty(NSString* layout_id);
#endif // CHROME_BROWSER_UI_COCOA_NSMENUITEM_ADDITIONS_H_
......@@ -11,11 +11,16 @@
#include "ui/events/keycodes/keyboard_code_conversion_mac.h"
namespace {
bool g_is_input_source_dvorak_qwerty = false;
bool g_is_input_source_command_qwerty = false;
} // namespace
void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
g_is_input_source_dvorak_qwerty = is_dvorak_qwerty;
void SetIsInputSourceCommandQwertyForTesting(bool is_command_qwerty) {
g_is_input_source_command_qwerty = is_command_qwerty;
}
bool IsKeyboardLayoutCommandQwerty(NSString* layout_id) {
return [layout_id isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"] ||
[layout_id isEqualToString:@"com.apple.keylayout.Dhivehi-QWERTY"];
}
@interface KeyboardInputSourceListener : NSObject
......@@ -43,10 +48,9 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
- (void)updateInputSource {
base::ScopedCFTypeRef<TISInputSourceRef> inputSource(
TISCopyCurrentKeyboardInputSource());
NSString* inputSourceID = (NSString*)TISGetInputSourceProperty(
NSString* layoutId = (NSString*)TISGetInputSourceProperty(
inputSource.get(), kTISPropertyInputSourceID);
g_is_input_source_dvorak_qwerty =
[inputSourceID isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"];
g_is_input_source_command_qwerty = IsKeyboardLayoutCommandQwerty(layoutId);
}
- (void)inputSourceDidChange:(NSNotification*)notification {
......@@ -132,11 +136,11 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
[[KeyboardInputSourceListener alloc] init];
// We typically want to compare [NSMenuItem keyEquivalent] against [NSEvent
// charactersIgnoringModifiers]. There is a special keyboard layout "Dvorak -
// QWERTY" which uses QWERTY-style shortcuts when the Command key is held
// down. In this case, we want to use the keycode of the event rather than
// looking at the characters.
if (g_is_input_source_dvorak_qwerty) {
// charactersIgnoringModifiers]. There are special command-qwerty layouts
// (such as DVORAK-QWERTY) which use QWERTY-style shortcuts when the Command
// key is held down. In this case, we want to use the keycode of the event
// rather than looking at the characters.
if (g_is_input_source_command_qwerty) {
ui::KeyboardCode windows_keycode =
ui::KeyboardCodeFromKeyCode(event.keyCode);
unichar shifted_character, character;
......
......@@ -46,6 +46,15 @@ std::ostream& operator<<(std::ostream& out, NSMenuItem* item) {
return out << "NSMenuItem " << base::SysNSStringToUTF8([item keyEquivalent]);
}
// Returns whether a keyboard layout is one of the "commandless" cyrillic
// layouts introduced in 10.15: these layouts do not ever fire key equivalents
// (in any app, not just Chrome) and appear not to be intended for full-time
// use.
bool IsCommandlessCyrillicLayout(NSString* layoutId) {
return [layoutId isEqualToString:@"com.apple.keylayout.Kyrgyz-Cyrillic"] ||
[layoutId isEqualToString:@"com.apple.keylayout.Mongolian-Cyrillic"];
}
void ExpectKeyFiresItemEq(bool result, NSEvent* key, NSMenuItem* item,
bool compareCocoa) {
EXPECT_EQ(result, [item cr_firesForKeyEvent:key]) << key << '\n' << item;
......@@ -267,8 +276,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
ExpectKeyDoesntFireItem(key, MenuItem(@"z", 0x100000));
ExpectKeyFiresItem(key, MenuItem(@";", 0x100000));
// Change to Dvorak-QWERTY
SetIsInputSourceDvorakQwertyForTesting(true);
// Change to Command-QWERTY
SetIsInputSourceCommandQwertyForTesting(true);
// cmd-z on dvorak qwerty layout (so that the key produces ';', but 'z' if
// cmd is down)
......@@ -296,8 +305,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
false);
ExpectKeyDoesntFireItem(key, MenuItem(@"\x9", NSControlKeyMask), false);
// Change away from Dvorak-QWERTY
SetIsInputSourceDvorakQwertyForTesting(false);
// Change away from Command-QWERTY
SetIsInputSourceCommandQwertyForTesting(false);
// cmd-shift-z on dvorak layout (so that we get a ':')
key = KeyEvent(0x12010a, @";", @":", 6);
......@@ -417,10 +426,14 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) {
// to trigger a keyEquivalent, since then it won't be possible to type
// "m".
continue;
} else if (IsCommandlessCyrillicLayout(layoutId)) {
// Commandless layouts have no way to trigger a menu key equivalent at
// all, in any app.
continue;
}
if ([layoutId isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"]) {
SetIsInputSourceDvorakQwertyForTesting(true);
if (IsKeyboardLayoutCommandQwerty(layoutId)) {
SetIsInputSourceCommandQwertyForTesting(true);
}
EventModifiers modifiers = cmdKey >> 8;
......@@ -438,8 +451,8 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) {
ExpectKeyFiresItem(key, item, false);
}
if ([layoutId isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"]) {
SetIsInputSourceDvorakQwertyForTesting(false);
if (IsKeyboardLayoutCommandQwerty(layoutId)) {
SetIsInputSourceCommandQwertyForTesting(false);
}
}
CFRelease(list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment