| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/accelerators/accelerator_controller.h" | 7 #include "ash/common/accelerators/accelerator_controller.h" |
| 8 #include "ash/common/accessibility_delegate.h" | 8 #include "ash/common/accessibility_delegate.h" |
| 9 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | 9 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
| 10 #include "ash/common/system/status_area_widget.h" | 10 #include "ash/common/system/status_area_widget.h" |
| 11 #include "ash/common/system/tray/ime_info.h" | 11 #include "ash/common/system/tray/ime_info.h" |
| 12 #include "ash/common/system/tray/system_tray_notifier.h" | 12 #include "ash/common/system/tray/system_tray_notifier.h" |
| 13 #include "ash/common/test/test_system_tray_delegate.h" | 13 #include "ash/common/test/test_system_tray_delegate.h" |
| 14 #include "ash/common/wm_shell.h" | |
| 15 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 16 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/status_area_widget_test_helper.h" | 16 #include "ash/test/status_area_widget_test_helper.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #include "ui/accessibility/ax_node_data.h" | 18 #include "ui/accessibility/ax_node_data.h" |
| 20 #include "ui/base/ime/chromeos/input_method_manager.h" | 19 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 21 #include "ui/base/ime/chromeos/mock_input_method_manager.h" | 20 #include "ui/base/ime/chromeos/mock_input_method_manager.h" |
| 22 #include "ui/base/ime/ime_bridge.h" | 21 #include "ui/base/ime/ime_bridge.h" |
| 23 #include "ui/base/ime/text_input_flags.h" | 22 #include "ui/base/ime/text_input_flags.h" |
| 24 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 89 |
| 91 private: | 90 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | 91 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 // Tests that visibility of IME menu tray should be consistent with the | 94 // Tests that visibility of IME menu tray should be consistent with the |
| 96 // activation of the IME menu. | 95 // activation of the IME menu. |
| 97 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | 96 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
| 98 ASSERT_FALSE(IsVisible()); | 97 ASSERT_FALSE(IsVisible()); |
| 99 | 98 |
| 100 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 99 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 101 EXPECT_TRUE(IsVisible()); | 100 EXPECT_TRUE(IsVisible()); |
| 102 | 101 |
| 103 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 102 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 104 EXPECT_FALSE(IsVisible()); | 103 EXPECT_FALSE(IsVisible()); |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Tests that IME menu tray shows the right info of the current IME. | 106 // Tests that IME menu tray shows the right info of the current IME. |
| 108 TEST_F(ImeMenuTrayTest, TrayLabelTest) { | 107 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
| 109 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 108 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 110 ASSERT_TRUE(IsVisible()); | 109 ASSERT_TRUE(IsVisible()); |
| 111 | 110 |
| 112 // Changes the input method to "ime1". | 111 // Changes the input method to "ime1". |
| 113 IMEInfo info1; | 112 IMEInfo info1; |
| 114 info1.id = "ime1"; | 113 info1.id = "ime1"; |
| 115 info1.name = UTF8ToUTF16("English"); | 114 info1.name = UTF8ToUTF16("English"); |
| 116 info1.medium_name = UTF8ToUTF16("English"); | 115 info1.medium_name = UTF8ToUTF16("English"); |
| 117 info1.short_name = UTF8ToUTF16("US"); | 116 info1.short_name = UTF8ToUTF16("US"); |
| 118 info1.third_party = false; | 117 info1.third_party = false; |
| 119 info1.selected = true; | 118 info1.selected = true; |
| 120 GetSystemTrayDelegate()->SetCurrentIME(info1); | 119 GetSystemTrayDelegate()->SetCurrentIME(info1); |
| 121 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 120 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 122 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 121 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
| 123 | 122 |
| 124 // Changes the input method to a third-party IME extension. | 123 // Changes the input method to a third-party IME extension. |
| 125 IMEInfo info2; | 124 IMEInfo info2; |
| 126 info2.id = "ime2"; | 125 info2.id = "ime2"; |
| 127 info2.name = UTF8ToUTF16("English UK"); | 126 info2.name = UTF8ToUTF16("English UK"); |
| 128 info2.medium_name = UTF8ToUTF16("English UK"); | 127 info2.medium_name = UTF8ToUTF16("English UK"); |
| 129 info2.short_name = UTF8ToUTF16("UK"); | 128 info2.short_name = UTF8ToUTF16("UK"); |
| 130 info2.third_party = true; | 129 info2.third_party = true; |
| 131 info2.selected = true; | 130 info2.selected = true; |
| 132 GetSystemTrayDelegate()->SetCurrentIME(info2); | 131 GetSystemTrayDelegate()->SetCurrentIME(info2); |
| 133 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 132 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 134 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); | 133 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); |
| 135 } | 134 } |
| 136 | 135 |
| 137 // Tests that IME menu tray changes background color when tapped/clicked. And | 136 // Tests that IME menu tray changes background color when tapped/clicked. And |
| 138 // tests that the background color becomes 'inactive' when disabling the IME | 137 // tests that the background color becomes 'inactive' when disabling the IME |
| 139 // menu feature. | 138 // menu feature. |
| 140 TEST_F(ImeMenuTrayTest, PerformAction) { | 139 TEST_F(ImeMenuTrayTest, PerformAction) { |
| 141 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 140 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 142 ASSERT_TRUE(IsVisible()); | 141 ASSERT_TRUE(IsVisible()); |
| 143 ASSERT_FALSE(IsTrayBackgroundActive()); | 142 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 144 | 143 |
| 145 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 144 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 146 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 145 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 147 GetTray()->PerformAction(tap); | 146 GetTray()->PerformAction(tap); |
| 148 EXPECT_TRUE(IsTrayBackgroundActive()); | 147 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 149 EXPECT_TRUE(IsBubbleShown()); | 148 EXPECT_TRUE(IsBubbleShown()); |
| 150 | 149 |
| 151 GetTray()->PerformAction(tap); | 150 GetTray()->PerformAction(tap); |
| 152 EXPECT_FALSE(IsTrayBackgroundActive()); | 151 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 153 EXPECT_FALSE(IsBubbleShown()); | 152 EXPECT_FALSE(IsBubbleShown()); |
| 154 | 153 |
| 155 // If disabling the IME menu feature when the menu tray is activated, the tray | 154 // If disabling the IME menu feature when the menu tray is activated, the tray |
| 156 // element will be deactivated. | 155 // element will be deactivated. |
| 157 GetTray()->PerformAction(tap); | 156 GetTray()->PerformAction(tap); |
| 158 EXPECT_TRUE(IsTrayBackgroundActive()); | 157 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 159 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 158 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 160 EXPECT_FALSE(IsVisible()); | 159 EXPECT_FALSE(IsVisible()); |
| 161 EXPECT_FALSE(IsBubbleShown()); | 160 EXPECT_FALSE(IsBubbleShown()); |
| 162 EXPECT_FALSE(IsTrayBackgroundActive()); | 161 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Tests that IME menu list updates when changing the current IME. This should | 164 // Tests that IME menu list updates when changing the current IME. This should |
| 166 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to | 165 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to |
| 167 // switch IMEs. | 166 // switch IMEs. |
| 168 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) { | 167 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) { |
| 169 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 168 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 info3.name = UTF8ToUTF16("Pinyin"); | 191 info3.name = UTF8ToUTF16("Pinyin"); |
| 193 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); | 192 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); |
| 194 info3.short_name = UTF8ToUTF16("拼"); | 193 info3.short_name = UTF8ToUTF16("拼"); |
| 195 info3.third_party = false; | 194 info3.third_party = false; |
| 196 info3.selected = false; | 195 info3.selected = false; |
| 197 | 196 |
| 198 std::vector<IMEInfo> ime_info_list{info1, info2, info3}; | 197 std::vector<IMEInfo> ime_info_list{info1, info2, info3}; |
| 199 | 198 |
| 200 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | 199 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); |
| 201 GetSystemTrayDelegate()->SetCurrentIME(info1); | 200 GetSystemTrayDelegate()->SetCurrentIME(info1); |
| 202 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 201 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 203 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 202 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
| 204 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); | 203 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); |
| 205 | 204 |
| 206 ime_info_list[0].selected = false; | 205 ime_info_list[0].selected = false; |
| 207 ime_info_list[2].selected = true; | 206 ime_info_list[2].selected = true; |
| 208 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | 207 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); |
| 209 GetSystemTrayDelegate()->SetCurrentIME(info3); | 208 GetSystemTrayDelegate()->SetCurrentIME(info3); |
| 210 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 209 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 211 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); | 210 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); |
| 212 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); | 211 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); |
| 213 | 212 |
| 214 // Closes the menu before quitting. | 213 // Closes the menu before quitting. |
| 215 GetTray()->PerformAction(tap); | 214 GetTray()->PerformAction(tap); |
| 216 EXPECT_FALSE(IsTrayBackgroundActive()); | 215 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 217 EXPECT_FALSE(IsBubbleShown()); | 216 EXPECT_FALSE(IsBubbleShown()); |
| 218 } | 217 } |
| 219 | 218 |
| 220 // Tests that quits Chrome with IME menu openned will not crash. | 219 // Tests that quits Chrome with IME menu openned will not crash. |
| 221 TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) { | 220 TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) { |
| 222 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 221 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 223 ASSERT_TRUE(IsVisible()); | 222 ASSERT_TRUE(IsVisible()); |
| 224 ASSERT_FALSE(IsTrayBackgroundActive()); | 223 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 225 | 224 |
| 226 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 225 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 227 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 226 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 228 GetTray()->PerformAction(tap); | 227 GetTray()->PerformAction(tap); |
| 229 EXPECT_TRUE(IsTrayBackgroundActive()); | 228 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 230 EXPECT_TRUE(IsBubbleShown()); | 229 EXPECT_TRUE(IsBubbleShown()); |
| 231 } | 230 } |
| 232 | 231 |
| 233 // Tests using 'Alt+Shift+K' to open the menu. | 232 // Tests using 'Alt+Shift+K' to open the menu. |
| 234 TEST_F(ImeMenuTrayTest, TestAccelerator) { | 233 TEST_F(ImeMenuTrayTest, TestAccelerator) { |
| 235 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 234 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 236 ASSERT_TRUE(IsVisible()); | 235 ASSERT_TRUE(IsVisible()); |
| 237 ASSERT_FALSE(IsTrayBackgroundActive()); | 236 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 238 | 237 |
| 239 Shell::Get()->accelerator_controller()->PerformActionIfEnabled( | 238 Shell::Get()->accelerator_controller()->PerformActionIfEnabled( |
| 240 SHOW_IME_MENU_BUBBLE); | 239 SHOW_IME_MENU_BUBBLE); |
| 241 EXPECT_TRUE(IsTrayBackgroundActive()); | 240 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 242 EXPECT_TRUE(IsBubbleShown()); | 241 EXPECT_TRUE(IsBubbleShown()); |
| 243 | 242 |
| 244 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 243 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 245 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 244 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 246 GetTray()->PerformAction(tap); | 245 GetTray()->PerformAction(tap); |
| 247 EXPECT_FALSE(IsTrayBackgroundActive()); | 246 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 248 EXPECT_FALSE(IsBubbleShown()); | 247 EXPECT_FALSE(IsBubbleShown()); |
| 249 } | 248 } |
| 250 | 249 |
| 251 TEST_F(ImeMenuTrayTest, ShowEmojiKeyset) { | 250 TEST_F(ImeMenuTrayTest, ShowEmojiKeyset) { |
| 252 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 251 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 253 ASSERT_TRUE(IsVisible()); | 252 ASSERT_TRUE(IsVisible()); |
| 254 ASSERT_FALSE(IsTrayBackgroundActive()); | 253 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 255 | 254 |
| 256 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 255 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 257 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 256 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 258 GetTray()->PerformAction(tap); | 257 GetTray()->PerformAction(tap); |
| 259 EXPECT_TRUE(IsTrayBackgroundActive()); | 258 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 260 EXPECT_TRUE(IsBubbleShown()); | 259 EXPECT_TRUE(IsBubbleShown()); |
| 261 | 260 |
| 262 AccessibilityDelegate* accessibility_delegate = | 261 AccessibilityDelegate* accessibility_delegate = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 input_method_manager = chromeos::input_method::InputMethodManager::Get(); | 304 input_method_manager = chromeos::input_method::InputMethodManager::Get(); |
| 306 EXPECT_TRUE(input_method_manager && | 305 EXPECT_TRUE(input_method_manager && |
| 307 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); | 306 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); |
| 308 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 307 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
| 309 | 308 |
| 310 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | 309 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 311 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 310 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
| 312 } | 311 } |
| 313 | 312 |
| 314 } // namespace ash | 313 } // namespace ash |
| OLD | NEW |