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 @@ ...@@ -18,6 +18,11 @@
// Used by tests to set internal state without having to change global input // Used by tests to set internal state without having to change global input
// source. // 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_ #endif // CHROME_BROWSER_UI_COCOA_NSMENUITEM_ADDITIONS_H_
...@@ -11,11 +11,16 @@ ...@@ -11,11 +11,16 @@
#include "ui/events/keycodes/keyboard_code_conversion_mac.h" #include "ui/events/keycodes/keyboard_code_conversion_mac.h"
namespace { namespace {
bool g_is_input_source_dvorak_qwerty = false; bool g_is_input_source_command_qwerty = false;
} // namespace } // namespace
void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { void SetIsInputSourceCommandQwertyForTesting(bool is_command_qwerty) {
g_is_input_source_dvorak_qwerty = is_dvorak_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 @interface KeyboardInputSourceListener : NSObject
...@@ -43,10 +48,9 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { ...@@ -43,10 +48,9 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
- (void)updateInputSource { - (void)updateInputSource {
base::ScopedCFTypeRef<TISInputSourceRef> inputSource( base::ScopedCFTypeRef<TISInputSourceRef> inputSource(
TISCopyCurrentKeyboardInputSource()); TISCopyCurrentKeyboardInputSource());
NSString* inputSourceID = (NSString*)TISGetInputSourceProperty( NSString* layoutId = (NSString*)TISGetInputSourceProperty(
inputSource.get(), kTISPropertyInputSourceID); inputSource.get(), kTISPropertyInputSourceID);
g_is_input_source_dvorak_qwerty = g_is_input_source_command_qwerty = IsKeyboardLayoutCommandQwerty(layoutId);
[inputSourceID isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"];
} }
- (void)inputSourceDidChange:(NSNotification*)notification { - (void)inputSourceDidChange:(NSNotification*)notification {
...@@ -132,11 +136,11 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { ...@@ -132,11 +136,11 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
[[KeyboardInputSourceListener alloc] init]; [[KeyboardInputSourceListener alloc] init];
// We typically want to compare [NSMenuItem keyEquivalent] against [NSEvent // We typically want to compare [NSMenuItem keyEquivalent] against [NSEvent
// charactersIgnoringModifiers]. There is a special keyboard layout "Dvorak - // charactersIgnoringModifiers]. There are special command-qwerty layouts
// QWERTY" which uses QWERTY-style shortcuts when the Command key is held // (such as DVORAK-QWERTY) which use QWERTY-style shortcuts when the Command
// down. In this case, we want to use the keycode of the event rather than // key is held down. In this case, we want to use the keycode of the event
// looking at the characters. // rather than looking at the characters.
if (g_is_input_source_dvorak_qwerty) { if (g_is_input_source_command_qwerty) {
ui::KeyboardCode windows_keycode = ui::KeyboardCode windows_keycode =
ui::KeyboardCodeFromKeyCode(event.keyCode); ui::KeyboardCodeFromKeyCode(event.keyCode);
unichar shifted_character, character; unichar shifted_character, character;
......
...@@ -46,6 +46,15 @@ std::ostream& operator<<(std::ostream& out, NSMenuItem* item) { ...@@ -46,6 +46,15 @@ std::ostream& operator<<(std::ostream& out, NSMenuItem* item) {
return out << "NSMenuItem " << base::SysNSStringToUTF8([item keyEquivalent]); 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, void ExpectKeyFiresItemEq(bool result, NSEvent* key, NSMenuItem* item,
bool compareCocoa) { bool compareCocoa) {
EXPECT_EQ(result, [item cr_firesForKeyEvent:key]) << key << '\n' << item; EXPECT_EQ(result, [item cr_firesForKeyEvent:key]) << key << '\n' << item;
...@@ -267,8 +276,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) { ...@@ -267,8 +276,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
ExpectKeyDoesntFireItem(key, MenuItem(@"z", 0x100000)); ExpectKeyDoesntFireItem(key, MenuItem(@"z", 0x100000));
ExpectKeyFiresItem(key, MenuItem(@";", 0x100000)); ExpectKeyFiresItem(key, MenuItem(@";", 0x100000));
// Change to Dvorak-QWERTY // Change to Command-QWERTY
SetIsInputSourceDvorakQwertyForTesting(true); SetIsInputSourceCommandQwertyForTesting(true);
// cmd-z on dvorak qwerty layout (so that the key produces ';', but 'z' if // cmd-z on dvorak qwerty layout (so that the key produces ';', but 'z' if
// cmd is down) // cmd is down)
...@@ -296,8 +305,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) { ...@@ -296,8 +305,8 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
false); false);
ExpectKeyDoesntFireItem(key, MenuItem(@"\x9", NSControlKeyMask), false); ExpectKeyDoesntFireItem(key, MenuItem(@"\x9", NSControlKeyMask), false);
// Change away from Dvorak-QWERTY // Change away from Command-QWERTY
SetIsInputSourceDvorakQwertyForTesting(false); SetIsInputSourceCommandQwertyForTesting(false);
// cmd-shift-z on dvorak layout (so that we get a ':') // cmd-shift-z on dvorak layout (so that we get a ':')
key = KeyEvent(0x12010a, @";", @":", 6); key = KeyEvent(0x12010a, @";", @":", 6);
...@@ -417,10 +426,14 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) { ...@@ -417,10 +426,14 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) {
// to trigger a keyEquivalent, since then it won't be possible to type // to trigger a keyEquivalent, since then it won't be possible to type
// "m". // "m".
continue; 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"]) { if (IsKeyboardLayoutCommandQwerty(layoutId)) {
SetIsInputSourceDvorakQwertyForTesting(true); SetIsInputSourceCommandQwertyForTesting(true);
} }
EventModifiers modifiers = cmdKey >> 8; EventModifiers modifiers = cmdKey >> 8;
...@@ -438,8 +451,8 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) { ...@@ -438,8 +451,8 @@ TEST(NSMenuItemAdditionsTest, TestMOnDifferentLayouts) {
ExpectKeyFiresItem(key, item, false); ExpectKeyFiresItem(key, item, false);
} }
if ([layoutId isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"]) { if (IsKeyboardLayoutCommandQwerty(layoutId)) {
SetIsInputSourceDvorakQwertyForTesting(false); SetIsInputSourceCommandQwertyForTesting(false);
} }
} }
CFRelease(list); 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