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_menu/ime_list_view.h" | 10 #include "ash/system/ime_menu/ime_list_view.h" |
11 #include "ash/system/status_area_widget.h" | 11 #include "ash/system/status_area_widget.h" |
12 #include "ash/system/tray/ime_info.h" | 12 #include "ash/system/tray/ime_info.h" |
13 #include "ash/system/tray/system_tray_notifier.h" | 13 #include "ash/system/tray/system_tray_notifier.h" |
14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
15 #include "ash/test/status_area_widget_test_helper.h" | 15 #include "ash/test/status_area_widget_test_helper.h" |
16 #include "ash/test/test_system_tray_delegate.h" | 16 #include "ash/test/test_system_tray_delegate.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
20 #include "ui/base/ime/chromeos/input_method_manager.h" | 20 #include "ui/base/ime/chromeos/input_method_manager.h" |
21 #include "ui/base/ime/chromeos/mock_input_method_manager.h" | 21 #include "ui/base/ime/chromeos/mock_input_method_manager.h" |
22 #include "ui/base/ime/ime_bridge.h" | 22 #include "ui/base/ime/ime_bridge.h" |
23 #include "ui/base/ime/text_input_flags.h" | 23 #include "ui/base/ime/text_input_flags.h" |
24 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
25 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
26 | 26 |
27 using base::UTF8ToUTF16; | 27 using base::UTF8ToUTF16; |
| 28 using chromeos::input_method::InputMethodManager; |
| 29 using chromeos::input_method::MockInputMethodManager; |
28 | 30 |
29 namespace ash { | 31 namespace ash { |
30 | 32 |
31 ImeMenuTray* GetTray() { | 33 ImeMenuTray* GetTray() { |
32 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); | 34 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); |
33 } | 35 } |
34 | 36 |
| 37 // An InputMethodManager that always returns an active IME state. |
| 38 class TestInputMethodManager : public MockInputMethodManager { |
| 39 public: |
| 40 TestInputMethodManager() : state_(new MockInputMethodManager::State) {} |
| 41 ~TestInputMethodManager() override = default; |
| 42 |
| 43 // MockInputMethodManager: |
| 44 scoped_refptr<InputMethodManager::State> GetActiveIMEState() override { |
| 45 return state_; |
| 46 } |
| 47 |
| 48 scoped_refptr<MockInputMethodManager::State> state_; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(TestInputMethodManager); |
| 52 }; |
| 53 |
35 class ImeMenuTrayTest : public test::AshTestBase { | 54 class ImeMenuTrayTest : public test::AshTestBase { |
36 public: | 55 public: |
37 ImeMenuTrayTest() {} | 56 ImeMenuTrayTest() = default; |
38 ~ImeMenuTrayTest() override {} | 57 ~ImeMenuTrayTest() override = default; |
| 58 |
| 59 // test::AshTestBase: |
| 60 void SetUp() override { |
| 61 test::AshTestBase::SetUp(); |
| 62 // Takes ownership. |
| 63 InputMethodManager::Initialize(new TestInputMethodManager); |
| 64 } |
| 65 void TearDown() override { |
| 66 InputMethodManager::Shutdown(); |
| 67 test::AshTestBase::TearDown(); |
| 68 } |
39 | 69 |
40 protected: | 70 protected: |
41 // Returns true if the IME menu tray is visible. | 71 // Returns true if the IME menu tray is visible. |
42 bool IsVisible() { return GetTray()->visible(); } | 72 bool IsVisible() { return GetTray()->visible(); } |
43 | 73 |
44 // Returns the label text of the tray. | 74 // Returns the label text of the tray. |
45 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 75 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
46 | 76 |
47 // Returns true if the background color of the tray is active. | 77 // Returns true if the background color of the tray is active. |
48 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } | 78 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 327 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
298 | 328 |
299 // Hides the keyboard. | 329 // Hides the keyboard. |
300 GetTray()->OnKeyboardHidden(); | 330 GetTray()->OnKeyboardHidden(); |
301 // The keyboard should still be disabled, which is a posted task. | 331 // The keyboard should still be disabled, which is a posted task. |
302 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
303 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 333 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
304 } | 334 } |
305 | 335 |
306 TEST_F(ImeMenuTrayTest, ShowEmojiHandwritingVoiceButtons) { | 336 TEST_F(ImeMenuTrayTest, ShowEmojiHandwritingVoiceButtons) { |
| 337 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 338 ASSERT_TRUE(input_method_manager); |
| 339 // Feature is enabled. |
| 340 ASSERT_TRUE(input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); |
| 341 |
| 342 // Text fields should show the buttons. |
307 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | 343 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
| 344 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
| 345 |
| 346 // Password fields should not show the buttons. |
| 347 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
308 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 348 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
309 | 349 |
310 chromeos::input_method::InputMethodManager* input_method_manager = | 350 // Lock screen should not show the buttons. |
311 chromeos::input_method::InputMethodManager::Get(); | 351 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
312 EXPECT_FALSE(input_method_manager); | 352 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
313 chromeos::input_method::InputMethodManager::Initialize( | |
314 new chromeos::input_method::MockInputMethodManager); | |
315 input_method_manager = chromeos::input_method::InputMethodManager::Get(); | |
316 EXPECT_TRUE(input_method_manager && | |
317 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); | |
318 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | |
319 | |
320 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | |
321 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 353 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
322 } | 354 } |
323 | 355 |
324 } // namespace ash | 356 } // namespace ash |
OLD | NEW |