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; | |
30 | 28 |
31 namespace ash { | 29 namespace ash { |
32 | 30 |
33 ImeMenuTray* GetTray() { | 31 ImeMenuTray* GetTray() { |
34 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); | 32 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); |
35 } | 33 } |
36 | 34 |
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 | |
54 class ImeMenuTrayTest : public test::AshTestBase { | 35 class ImeMenuTrayTest : public test::AshTestBase { |
55 public: | 36 public: |
56 ImeMenuTrayTest() = default; | 37 ImeMenuTrayTest() {} |
57 ~ImeMenuTrayTest() override = default; | 38 ~ImeMenuTrayTest() override {} |
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 } | |
69 | 39 |
70 protected: | 40 protected: |
71 // Returns true if the IME menu tray is visible. | 41 // Returns true if the IME menu tray is visible. |
72 bool IsVisible() { return GetTray()->visible(); } | 42 bool IsVisible() { return GetTray()->visible(); } |
73 | 43 |
74 // Returns the label text of the tray. | 44 // Returns the label text of the tray. |
75 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 45 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
76 | 46 |
77 // Returns true if the background color of the tray is active. | 47 // Returns true if the background color of the tray is active. |
78 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } | 48 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 297 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
328 | 298 |
329 // Hides the keyboard. | 299 // Hides the keyboard. |
330 GetTray()->OnKeyboardHidden(); | 300 GetTray()->OnKeyboardHidden(); |
331 // The keyboard should still be disabled, which is a posted task. | 301 // The keyboard should still be disabled, which is a posted task. |
332 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
333 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 303 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
334 } | 304 } |
335 | 305 |
336 TEST_F(ImeMenuTrayTest, ShowEmojiHandwritingVoiceButtons) { | 306 TEST_F(ImeMenuTrayTest, ShowEmojiHandwritingVoiceButtons) { |
337 InputMethodManager* input_method_manager = InputMethodManager::Get(); | 307 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
338 ASSERT_TRUE(input_method_manager); | 308 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
339 // Feature is enabled. | |
340 ASSERT_TRUE(input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); | |
341 | 309 |
342 // Text fields should show the buttons. | 310 chromeos::input_method::InputMethodManager* input_method_manager = |
343 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | 311 chromeos::input_method::InputMethodManager::Get(); |
| 312 EXPECT_FALSE(input_method_manager); |
| 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()); |
344 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 318 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
345 | 319 |
346 // Password fields should not show the buttons. | |
347 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | 320 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
348 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 321 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
349 | |
350 // Lock screen should not show the buttons. | |
351 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | |
352 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | |
353 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | |
354 } | 322 } |
355 | 323 |
356 } // namespace ash | 324 } // namespace ash |
OLD | NEW |