| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/sticky_keys/sticky_keys_controller.h" | 8 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 9 #include "ash/sticky_keys/sticky_keys_overlay.h" | 9 #include "ash/sticky_keys/sticky_keys_overlay.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 CheckKeyTestCase(rewriter_, test); | 972 CheckKeyTestCase(rewriter_, test); |
| 973 } | 973 } |
| 974 | 974 |
| 975 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { | 975 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { |
| 976 // Remap Search to Caps Lock. | 976 // Remap Search to Caps Lock. |
| 977 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); | 977 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); |
| 978 IntegerPrefMember search; | 978 IntegerPrefMember search; |
| 979 search.Init(prefs::kLanguageRemapSearchKeyTo, prefs()); | 979 search.Init(prefs::kLanguageRemapSearchKeyTo, prefs()); |
| 980 search.SetValue(chromeos::input_method::kCapsLockKey); | 980 search.SetValue(chromeos::input_method::kCapsLockKey); |
| 981 | 981 |
| 982 chromeos::input_method::FakeImeKeyboard ime_keyboard; | |
| 983 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 982 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
| 984 rewriter_->set_ime_keyboard_for_testing(&ime_keyboard); | |
| 985 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | |
| 986 | 983 |
| 987 // Press Search. | 984 // Press Search. |
| 988 EXPECT_EQ(GetExpectedResultAsString( | 985 EXPECT_EQ(GetExpectedResultAsString( |
| 989 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 986 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 990 ui::EF_MOD3_DOWN | ui::EF_CAPS_LOCK_ON, ui::DomKey::CAPS_LOCK), | 987 ui::EF_MOD3_DOWN | ui::EF_CAPS_LOCK_ON, ui::DomKey::CAPS_LOCK), |
| 991 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, | 988 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, |
| 992 ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 989 ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
| 993 ui::EF_COMMAND_DOWN, ui::DomKey::META)); | 990 ui::EF_COMMAND_DOWN, ui::DomKey::META)); |
| 994 // Confirm that the Caps Lock status is changed. | |
| 995 EXPECT_TRUE(ime_keyboard.caps_lock_is_enabled_); | |
| 996 | 991 |
| 997 // Release Search. | 992 // Release Search. |
| 998 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, | 993 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, |
| 999 ui::DomCode::CAPS_LOCK, ui::EF_NONE, | 994 ui::DomCode::CAPS_LOCK, ui::EF_NONE, |
| 1000 ui::DomKey::CAPS_LOCK), | 995 ui::DomKey::CAPS_LOCK), |
| 1001 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, | 996 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, |
| 1002 ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 997 ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
| 1003 ui::EF_NONE, ui::DomKey::META)); | 998 ui::EF_NONE, ui::DomKey::META)); |
| 1004 // Confirm that the Caps Lock status is not changed. | |
| 1005 EXPECT_TRUE(ime_keyboard.caps_lock_is_enabled_); | |
| 1006 | 999 |
| 1007 // Press Search. | 1000 // Press Search. |
| 1008 EXPECT_EQ(GetExpectedResultAsString( | 1001 EXPECT_EQ(GetExpectedResultAsString( |
| 1009 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 1002 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 1010 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), | 1003 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), |
| 1011 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, | 1004 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, |
| 1012 ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 1005 ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
| 1013 ui::EF_COMMAND_DOWN | ui::EF_CAPS_LOCK_ON, | 1006 ui::EF_COMMAND_DOWN | ui::EF_CAPS_LOCK_ON, |
| 1014 ui::DomKey::META)); | 1007 ui::DomKey::META)); |
| 1015 // Confirm that the Caps Lock status is changed. | |
| 1016 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | |
| 1017 | 1008 |
| 1018 // Release Search. | 1009 // Release Search. |
| 1019 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, | 1010 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, |
| 1020 ui::DomCode::CAPS_LOCK, ui::EF_NONE, | 1011 ui::DomCode::CAPS_LOCK, ui::EF_NONE, |
| 1021 ui::DomKey::CAPS_LOCK), | 1012 ui::DomKey::CAPS_LOCK), |
| 1022 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, | 1013 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, |
| 1023 ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 1014 ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
| 1024 ui::EF_NONE, ui::DomKey::META)); | 1015 ui::EF_NONE, ui::DomKey::META)); |
| 1025 // Confirm that the Caps Lock status is not changed. | |
| 1026 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | |
| 1027 | 1016 |
| 1028 // Press Caps Lock (on an external keyboard). | 1017 // Press Caps Lock (on an external keyboard). |
| 1029 EXPECT_EQ(GetExpectedResultAsString( | 1018 EXPECT_EQ(GetExpectedResultAsString( |
| 1030 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 1019 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 1031 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), | 1020 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), |
| 1032 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, | 1021 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, |
| 1033 ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 1022 ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 1034 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, | 1023 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, |
| 1035 ui::DomKey::CAPS_LOCK)); | 1024 ui::DomKey::CAPS_LOCK)); |
| 1036 | 1025 |
| 1037 #if defined(USE_X11) | |
| 1038 // Confirm that calling RewriteForTesting() does not change the state of | |
| 1039 // |ime_keyboard|. In this case, X Window system itself should change the | |
| 1040 // Caps Lock state, not ash::EventRewriter. | |
| 1041 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | |
| 1042 #elif defined(USE_OZONE) | |
| 1043 // Under Ozone the rewriter is responsible for changing the caps lock | |
| 1044 // state when the final key is Caps Lock, regardless of whether the | |
| 1045 // initial key is Caps Lock. | |
| 1046 EXPECT_TRUE(ime_keyboard.caps_lock_is_enabled_); | |
| 1047 #endif | |
| 1048 | |
| 1049 // Release Caps Lock (on an external keyboard). | 1026 // Release Caps Lock (on an external keyboard). |
| 1050 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, | 1027 EXPECT_EQ(GetExpectedResultAsString(ui::ET_KEY_RELEASED, ui::VKEY_CAPITAL, |
| 1051 ui::DomCode::CAPS_LOCK, ui::EF_NONE, | 1028 ui::DomCode::CAPS_LOCK, ui::EF_NONE, |
| 1052 ui::DomKey::CAPS_LOCK), | 1029 ui::DomKey::CAPS_LOCK), |
| 1053 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, | 1030 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_RELEASED, |
| 1054 ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 1031 ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 1055 ui::EF_NONE, ui::DomKey::CAPS_LOCK)); | 1032 ui::EF_NONE, ui::DomKey::CAPS_LOCK)); |
| 1056 #if defined(USE_X11) | |
| 1057 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | |
| 1058 #elif defined(USE_OZONE) | |
| 1059 EXPECT_TRUE(ime_keyboard.caps_lock_is_enabled_); | |
| 1060 #endif | |
| 1061 } | 1033 } |
| 1062 | 1034 |
| 1063 TEST_F(EventRewriterTest, TestRewriteCapsLock) { | 1035 TEST_F(EventRewriterTest, TestRewriteCapsLock) { |
| 1064 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); | 1036 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); |
| 1065 | 1037 |
| 1066 chromeos::input_method::FakeImeKeyboard ime_keyboard; | 1038 chromeos::input_method::FakeImeKeyboard ime_keyboard; |
| 1067 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 1039 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
| 1068 rewriter_->set_ime_keyboard_for_testing(&ime_keyboard); | 1040 rewriter_->set_ime_keyboard_for_testing(&ime_keyboard); |
| 1069 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); | 1041 EXPECT_FALSE(ime_keyboard.caps_lock_is_enabled_); |
| 1070 | 1042 |
| 1071 // On Chrome OS, CapsLock is mapped to F16 with Mod3Mask. | 1043 // On Chrome OS, CapsLock is mapped to F16 with Mod3Mask. |
| 1072 EXPECT_EQ(GetExpectedResultAsString( | 1044 EXPECT_EQ(GetExpectedResultAsString( |
| 1073 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, | 1045 ui::ET_KEY_PRESSED, ui::VKEY_CAPITAL, ui::DomCode::CAPS_LOCK, |
| 1074 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), | 1046 ui::EF_CAPS_LOCK_ON | ui::EF_MOD3_DOWN, ui::DomKey::CAPS_LOCK), |
| 1075 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, | 1047 GetRewrittenEventAsString(rewriter_, ui::ET_KEY_PRESSED, |
| 1076 ui::VKEY_F16, ui::DomCode::F16, | 1048 ui::VKEY_F16, ui::DomCode::F16, |
| 1077 ui::EF_MOD3_DOWN, ui::DomKey::F16)); | 1049 ui::EF_MOD3_DOWN, ui::DomKey::F16)); |
| 1078 EXPECT_TRUE(ime_keyboard.caps_lock_is_enabled_); | |
| 1079 } | 1050 } |
| 1080 | 1051 |
| 1081 TEST_F(EventRewriterTest, TestRewriteDiamondKey) { | 1052 TEST_F(EventRewriterTest, TestRewriteDiamondKey) { |
| 1082 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); | 1053 chromeos::Preferences::RegisterProfilePrefs(prefs()->registry()); |
| 1083 | 1054 |
| 1084 chromeos::input_method::FakeImeKeyboard ime_keyboard; | 1055 chromeos::input_method::FakeImeKeyboard ime_keyboard; |
| 1085 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 1056 rewriter_->KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
| 1086 rewriter_->set_ime_keyboard_for_testing(&ime_keyboard); | 1057 rewriter_->set_ime_keyboard_for_testing(&ime_keyboard); |
| 1087 | 1058 |
| 1088 KeyTestCase tests[] = { | 1059 KeyTestCase tests[] = { |
| (...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2569 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
| 2599 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2570 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
| 2600 | 2571 |
| 2601 // Turn off AltGr and Mod3. | 2572 // Turn off AltGr and Mod3. |
| 2602 sticky_keys_controller_->SetModifiersEnabled(false, false); | 2573 sticky_keys_controller_->SetModifiersEnabled(false, false); |
| 2603 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2574 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
| 2604 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2575 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
| 2605 } | 2576 } |
| 2606 | 2577 |
| 2607 } // namespace chromeos | 2578 } // namespace chromeos |
| OLD | NEW |