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/system/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/ime/ime_util.h" | 10 #include "ash/system/ime/ime_util.h" |
11 #include "ash/system/ime_menu/ime_list_view.h" | 11 #include "ash/system/ime_menu/ime_list_view.h" |
12 #include "ash/system/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
13 #include "ash/system/tray/ime_info.h" | 13 #include "ash/system/tray/ime_info.h" |
14 #include "ash/system/tray/system_tray_notifier.h" | |
15 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
16 #include "ash/test/status_area_widget_test_helper.h" | 15 #include "ash/test/status_area_widget_test_helper.h" |
17 #include "ash/test/test_system_tray_delegate.h" | 16 #include "ash/test/test_system_tray_delegate.h" |
18 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
19 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
20 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
21 #include "ui/base/ime/chromeos/input_method_manager.h" | 20 #include "ui/base/ime/chromeos/input_method_manager.h" |
22 #include "ui/base/ime/chromeos/mock_input_method_manager.h" | 21 #include "ui/base/ime/chromeos/mock_input_method_manager.h" |
23 #include "ui/base/ime/ime_bridge.h" | 22 #include "ui/base/ime/ime_bridge.h" |
24 #include "ui/base/ime/text_input_flags.h" | 23 #include "ui/base/ime/text_input_flags.h" |
(...skipping 29 matching lines...) Expand all Loading... |
54 | 53 |
55 class ImeMenuTrayTest : public test::AshTestBase { | 54 class ImeMenuTrayTest : public test::AshTestBase { |
56 public: | 55 public: |
57 ImeMenuTrayTest() | 56 ImeMenuTrayTest() |
58 : scoped_current_ime_(¤t_ime_), | 57 : scoped_current_ime_(¤t_ime_), |
59 scoped_available_ime_list_(&available_ime_list_) {} | 58 scoped_available_ime_list_(&available_ime_list_) {} |
60 ~ImeMenuTrayTest() override = default; | 59 ~ImeMenuTrayTest() override = default; |
61 | 60 |
62 // test::AshTestBase: | 61 // test::AshTestBase: |
63 void SetUp() override { | 62 void SetUp() override { |
64 test::AshTestBase::SetUp(); | |
65 // Takes ownership. | 63 // Takes ownership. |
66 InputMethodManager::Initialize(new TestInputMethodManager); | 64 InputMethodManager::Initialize(new TestInputMethodManager); |
| 65 test::AshTestBase::SetUp(); |
67 } | 66 } |
68 void TearDown() override { | 67 void TearDown() override { |
| 68 test::AshTestBase::TearDown(); |
69 InputMethodManager::Shutdown(); | 69 InputMethodManager::Shutdown(); |
70 test::AshTestBase::TearDown(); | |
71 } | 70 } |
72 | 71 |
73 protected: | 72 protected: |
74 // Returns true if the IME menu tray is visible. | 73 // Returns true if the IME menu tray is visible. |
75 bool IsVisible() { return GetTray()->visible(); } | 74 bool IsVisible() { return GetTray()->visible(); } |
76 | 75 |
77 // Returns the label text of the tray. | 76 // Returns the label text of the tray. |
78 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 77 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
79 | 78 |
80 // Returns true if the background color of the tray is active. | 79 // Returns true if the background color of the tray is active. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return true; | 114 return true; |
116 } | 115 } |
117 | 116 |
118 // Focuses in the given type of input context. | 117 // Focuses in the given type of input context. |
119 void FocusInInputContext(ui::TextInputType input_type) { | 118 void FocusInInputContext(ui::TextInputType input_type) { |
120 ui::IMEEngineHandlerInterface::InputContext input_context( | 119 ui::IMEEngineHandlerInterface::InputContext input_context( |
121 input_type, ui::TEXT_INPUT_MODE_DEFAULT, ui::TEXT_INPUT_FLAG_NONE); | 120 input_type, ui::TEXT_INPUT_MODE_DEFAULT, ui::TEXT_INPUT_FLAG_NONE); |
122 ui::IMEBridge::Get()->SetCurrentInputContext(input_context); | 121 ui::IMEBridge::Get()->SetCurrentInputContext(input_context); |
123 } | 122 } |
124 | 123 |
125 void SetCurrentIme(const IMEInfo& info) { current_ime_ = info; } | 124 void SetCurrentIme(const IMEInfo& info) { |
| 125 current_ime_ = info; |
| 126 GetTray()->InputMethodChanged(nullptr, nullptr, false); |
| 127 } |
126 | 128 |
127 void SetAvailableImeList(const std::vector<IMEInfo>& list) { | 129 void SetAvailableImeList(const std::vector<IMEInfo>& list) { |
128 available_ime_list_ = list; | 130 available_ime_list_ = list; |
129 } | 131 } |
130 | 132 |
131 private: | 133 private: |
132 IMEInfo current_ime_; | 134 IMEInfo current_ime_; |
133 ime_util::ScopedCurrentImeForTesting scoped_current_ime_; | 135 ime_util::ScopedCurrentImeForTesting scoped_current_ime_; |
134 | 136 |
135 std::vector<IMEInfo> available_ime_list_; | 137 std::vector<IMEInfo> available_ime_list_; |
136 ime_util::ScopedAvailableImeListForTesting scoped_available_ime_list_; | 138 ime_util::ScopedAvailableImeListForTesting scoped_available_ime_list_; |
137 | 139 |
138 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | 140 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
139 }; | 141 }; |
140 | 142 |
141 // Tests that visibility of IME menu tray should be consistent with the | 143 // Tests that visibility of IME menu tray should be consistent with the |
142 // activation of the IME menu. | 144 // activation of the IME menu. |
143 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | 145 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
144 ASSERT_FALSE(IsVisible()); | 146 ASSERT_FALSE(IsVisible()); |
145 | 147 |
146 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 148 GetTray()->ImeMenuActivationChanged(true); |
147 EXPECT_TRUE(IsVisible()); | 149 EXPECT_TRUE(IsVisible()); |
148 | 150 |
149 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 151 GetTray()->ImeMenuActivationChanged(false); |
150 EXPECT_FALSE(IsVisible()); | 152 EXPECT_FALSE(IsVisible()); |
151 } | 153 } |
152 | 154 |
153 // Tests that IME menu tray shows the right info of the current IME. | 155 // Tests that IME menu tray shows the right info of the current IME. |
154 TEST_F(ImeMenuTrayTest, TrayLabelTest) { | 156 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
155 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 157 GetTray()->ImeMenuActivationChanged(true); |
156 ASSERT_TRUE(IsVisible()); | 158 ASSERT_TRUE(IsVisible()); |
157 | 159 |
158 // Changes the input method to "ime1". | 160 // Changes the input method to "ime1". |
159 IMEInfo info1; | 161 IMEInfo info1; |
160 info1.id = "ime1"; | 162 info1.id = "ime1"; |
161 info1.name = UTF8ToUTF16("English"); | 163 info1.name = UTF8ToUTF16("English"); |
162 info1.medium_name = UTF8ToUTF16("English"); | 164 info1.medium_name = UTF8ToUTF16("English"); |
163 info1.short_name = UTF8ToUTF16("US"); | 165 info1.short_name = UTF8ToUTF16("US"); |
164 info1.third_party = false; | 166 info1.third_party = false; |
165 info1.selected = true; | 167 info1.selected = true; |
166 SetCurrentIme(info1); | 168 SetCurrentIme(info1); |
167 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
168 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 169 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
169 | 170 |
170 // Changes the input method to a third-party IME extension. | 171 // Changes the input method to a third-party IME extension. |
171 IMEInfo info2; | 172 IMEInfo info2; |
172 info2.id = "ime2"; | 173 info2.id = "ime2"; |
173 info2.name = UTF8ToUTF16("English UK"); | 174 info2.name = UTF8ToUTF16("English UK"); |
174 info2.medium_name = UTF8ToUTF16("English UK"); | 175 info2.medium_name = UTF8ToUTF16("English UK"); |
175 info2.short_name = UTF8ToUTF16("UK"); | 176 info2.short_name = UTF8ToUTF16("UK"); |
176 info2.third_party = true; | 177 info2.third_party = true; |
177 info2.selected = true; | 178 info2.selected = true; |
178 SetCurrentIme(info2); | 179 SetCurrentIme(info2); |
179 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
180 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); | 180 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); |
181 } | 181 } |
182 | 182 |
183 // Tests that IME menu tray changes background color when tapped/clicked. And | 183 // Tests that IME menu tray changes background color when tapped/clicked. And |
184 // tests that the background color becomes 'inactive' when disabling the IME | 184 // tests that the background color becomes 'inactive' when disabling the IME |
185 // menu feature. Also makes sure that the shelf won't autohide as long as the | 185 // menu feature. Also makes sure that the shelf won't autohide as long as the |
186 // IME menu is open. | 186 // IME menu is open. |
187 TEST_F(ImeMenuTrayTest, PerformAction) { | 187 TEST_F(ImeMenuTrayTest, PerformAction) { |
188 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 188 GetTray()->ImeMenuActivationChanged(true); |
189 ASSERT_TRUE(IsVisible()); | 189 ASSERT_TRUE(IsVisible()); |
190 ASSERT_FALSE(IsTrayBackgroundActive()); | 190 ASSERT_FALSE(IsTrayBackgroundActive()); |
191 StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); | 191 StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); |
192 EXPECT_FALSE(status->ShouldShowShelf()); | 192 EXPECT_FALSE(status->ShouldShowShelf()); |
193 | 193 |
194 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 194 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
195 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 195 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
196 GetTray()->PerformAction(tap); | 196 GetTray()->PerformAction(tap); |
197 EXPECT_TRUE(IsTrayBackgroundActive()); | 197 EXPECT_TRUE(IsTrayBackgroundActive()); |
198 EXPECT_TRUE(IsBubbleShown()); | 198 EXPECT_TRUE(IsBubbleShown()); |
199 | 199 |
200 // Auto-hidden shelf would be forced to be visible as long as the bubble is | 200 // Auto-hidden shelf would be forced to be visible as long as the bubble is |
201 // open. | 201 // open. |
202 EXPECT_TRUE(status->ShouldShowShelf()); | 202 EXPECT_TRUE(status->ShouldShowShelf()); |
203 | 203 |
204 GetTray()->PerformAction(tap); | 204 GetTray()->PerformAction(tap); |
205 EXPECT_FALSE(IsTrayBackgroundActive()); | 205 EXPECT_FALSE(IsTrayBackgroundActive()); |
206 EXPECT_FALSE(IsBubbleShown()); | 206 EXPECT_FALSE(IsBubbleShown()); |
207 | 207 |
208 // If disabling the IME menu feature when the menu tray is activated, the tray | 208 // If disabling the IME menu feature when the menu tray is activated, the tray |
209 // element will be deactivated. | 209 // element will be deactivated. |
210 GetTray()->PerformAction(tap); | 210 GetTray()->PerformAction(tap); |
211 EXPECT_TRUE(IsTrayBackgroundActive()); | 211 EXPECT_TRUE(IsTrayBackgroundActive()); |
212 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 212 GetTray()->ImeMenuActivationChanged(false); |
213 EXPECT_FALSE(IsVisible()); | 213 EXPECT_FALSE(IsVisible()); |
214 EXPECT_FALSE(IsBubbleShown()); | 214 EXPECT_FALSE(IsBubbleShown()); |
215 EXPECT_FALSE(IsTrayBackgroundActive()); | 215 EXPECT_FALSE(IsTrayBackgroundActive()); |
216 EXPECT_FALSE(status->ShouldShowShelf()); | 216 EXPECT_FALSE(status->ShouldShowShelf()); |
217 } | 217 } |
218 | 218 |
219 // Tests that IME menu list updates when changing the current IME. This should | 219 // Tests that IME menu list updates when changing the current IME. This should |
220 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to | 220 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to |
221 // switch IMEs. | 221 // switch IMEs. |
222 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) { | 222 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) { |
(...skipping 24 matching lines...) Expand all Loading... |
247 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); | 247 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); |
248 info3.short_name = UTF8ToUTF16("拼"); | 248 info3.short_name = UTF8ToUTF16("拼"); |
249 info3.third_party = false; | 249 info3.third_party = false; |
250 info3.selected = false; | 250 info3.selected = false; |
251 | 251 |
252 std::vector<IMEInfo> ime_info_list = {info1, info2, info3}; | 252 std::vector<IMEInfo> ime_info_list = {info1, info2, info3}; |
253 | 253 |
254 // Simulate switch to IME 1. | 254 // Simulate switch to IME 1. |
255 SetAvailableImeList(ime_info_list); | 255 SetAvailableImeList(ime_info_list); |
256 SetCurrentIme(info1); | 256 SetCurrentIme(info1); |
257 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
258 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 257 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
259 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); | 258 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); |
260 | 259 |
261 // Simulate switch to IME 3. | 260 // Simulate switch to IME 3. |
262 ime_info_list[0].selected = false; | 261 ime_info_list[0].selected = false; |
263 ime_info_list[2].selected = true; | 262 ime_info_list[2].selected = true; |
264 SetAvailableImeList(ime_info_list); | 263 SetAvailableImeList(ime_info_list); |
265 SetCurrentIme(info3); | 264 SetCurrentIme(info3); |
266 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
267 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); | 265 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); |
268 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); | 266 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); |
269 | 267 |
270 // Closes the menu before quitting. | 268 // Closes the menu before quitting. |
271 GetTray()->PerformAction(tap); | 269 GetTray()->PerformAction(tap); |
272 EXPECT_FALSE(IsTrayBackgroundActive()); | 270 EXPECT_FALSE(IsTrayBackgroundActive()); |
273 EXPECT_FALSE(IsBubbleShown()); | 271 EXPECT_FALSE(IsBubbleShown()); |
274 } | 272 } |
275 | 273 |
276 // Tests that quits Chrome with IME menu openned will not crash. | 274 // Tests that quits Chrome with IME menu openned will not crash. |
277 TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) { | 275 TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) { |
278 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 276 GetTray()->ImeMenuActivationChanged(true); |
279 ASSERT_TRUE(IsVisible()); | 277 ASSERT_TRUE(IsVisible()); |
280 ASSERT_FALSE(IsTrayBackgroundActive()); | 278 ASSERT_FALSE(IsTrayBackgroundActive()); |
281 | 279 |
282 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 280 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
283 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 281 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
284 GetTray()->PerformAction(tap); | 282 GetTray()->PerformAction(tap); |
285 EXPECT_TRUE(IsTrayBackgroundActive()); | 283 EXPECT_TRUE(IsTrayBackgroundActive()); |
286 EXPECT_TRUE(IsBubbleShown()); | 284 EXPECT_TRUE(IsBubbleShown()); |
287 } | 285 } |
288 | 286 |
289 // Tests using 'Alt+Shift+K' to open the menu. | 287 // Tests using 'Alt+Shift+K' to open the menu. |
290 TEST_F(ImeMenuTrayTest, TestAccelerator) { | 288 TEST_F(ImeMenuTrayTest, TestAccelerator) { |
291 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 289 GetTray()->ImeMenuActivationChanged(true); |
292 ASSERT_TRUE(IsVisible()); | 290 ASSERT_TRUE(IsVisible()); |
293 ASSERT_FALSE(IsTrayBackgroundActive()); | 291 ASSERT_FALSE(IsTrayBackgroundActive()); |
294 | 292 |
295 Shell::Get()->accelerator_controller()->PerformActionIfEnabled( | 293 Shell::Get()->accelerator_controller()->PerformActionIfEnabled( |
296 SHOW_IME_MENU_BUBBLE); | 294 SHOW_IME_MENU_BUBBLE); |
297 EXPECT_TRUE(IsTrayBackgroundActive()); | 295 EXPECT_TRUE(IsTrayBackgroundActive()); |
298 EXPECT_TRUE(IsBubbleShown()); | 296 EXPECT_TRUE(IsBubbleShown()); |
299 | 297 |
300 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 298 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
301 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 299 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
302 GetTray()->PerformAction(tap); | 300 GetTray()->PerformAction(tap); |
303 EXPECT_FALSE(IsTrayBackgroundActive()); | 301 EXPECT_FALSE(IsTrayBackgroundActive()); |
304 EXPECT_FALSE(IsBubbleShown()); | 302 EXPECT_FALSE(IsBubbleShown()); |
305 } | 303 } |
306 | 304 |
307 TEST_F(ImeMenuTrayTest, ShowEmojiKeyset) { | 305 TEST_F(ImeMenuTrayTest, ShowEmojiKeyset) { |
308 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 306 GetTray()->ImeMenuActivationChanged(true); |
309 ASSERT_TRUE(IsVisible()); | 307 ASSERT_TRUE(IsVisible()); |
310 ASSERT_FALSE(IsTrayBackgroundActive()); | 308 ASSERT_FALSE(IsTrayBackgroundActive()); |
311 | 309 |
312 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 310 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
313 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 311 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
314 GetTray()->PerformAction(tap); | 312 GetTray()->PerformAction(tap); |
315 EXPECT_TRUE(IsTrayBackgroundActive()); | 313 EXPECT_TRUE(IsTrayBackgroundActive()); |
316 EXPECT_TRUE(IsBubbleShown()); | 314 EXPECT_TRUE(IsBubbleShown()); |
317 | 315 |
318 AccessibilityDelegate* accessibility_delegate = | 316 AccessibilityDelegate* accessibility_delegate = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | 362 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
365 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 363 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
366 | 364 |
367 // Lock screen should not show the buttons. | 365 // Lock screen should not show the buttons. |
368 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | 366 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
369 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | 367 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
370 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 368 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
371 } | 369 } |
372 | 370 |
373 } // namespace ash | 371 } // namespace ash |
OLD | NEW |