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 "ash/system/ime/tray_ime_chromeos.h" | 5 #include "ash/common/system/ime/tray_ime_chromeos.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/accessibility_types.h" | 8 #include "ash/common/accessibility_types.h" |
9 #include "ash/common/system/tray/tray_details_view.h" | 9 #include "ash/common/system/tray/tray_details_view.h" |
10 #include "ash/common/system/tray/wm_system_tray_notifier.h" | 10 #include "ash/common/system/tray/wm_system_tray_notifier.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/system/status_area_widget.h" | |
13 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
14 #include "ash/test/status_area_widget_test_helper.h" | |
15 #include "ash/test/virtual_keyboard_test_helper.h" | 13 #include "ash/test/virtual_keyboard_test_helper.h" |
16 #include "base/command_line.h" | 14 #include "base/command_line.h" |
17 #include "ui/keyboard/keyboard_util.h" | 15 #include "ui/keyboard/keyboard_util.h" |
18 | 16 |
19 namespace ash { | 17 namespace ash { |
20 | 18 |
21 class TrayIMETest : public test::AshTestBase { | 19 class TrayIMETest : public test::AshTestBase { |
22 public: | 20 public: |
23 TrayIMETest() {} | 21 TrayIMETest() {} |
24 ~TrayIMETest() override {} | 22 ~TrayIMETest() override {} |
25 | 23 |
26 TrayIME* tray() { return tray_.get(); } | 24 TrayIME* tray() { return tray_.get(); } |
27 | 25 |
28 views::View* default_view() { return default_view_.get(); } | 26 views::View* default_view() { return default_view_.get(); } |
29 | 27 |
30 views::View* detailed_view() { return detailed_view_.get(); } | 28 views::View* detailed_view() { return detailed_view_.get(); } |
31 | 29 |
32 // Sets up a TrayIME and its default view. | |
33 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); | |
34 | |
35 // Mocks enabling the a11y virtual keyboard since the actual a11y manager | 30 // Mocks enabling the a11y virtual keyboard since the actual a11y manager |
36 // is not created in ash tests. | 31 // is not created in ash tests. |
37 void SetAccessibilityKeyboardEnabled(bool enabled); | 32 void SetAccessibilityKeyboardEnabled(bool enabled); |
38 | 33 |
39 // Resets |tray_| and |default_view_| so that all components of | |
40 // TrayIME have been cleared. Tests may then call | |
41 // SetUpForStatusAreaWidget in order to initialize the components. | |
42 void TearDownViews(); | |
43 | |
44 // Sets the current number of active IMEs. | 34 // Sets the current number of active IMEs. |
45 void SetIMELength(int length); | 35 void SetIMELength(int length); |
46 | 36 |
47 // Returns the view in the detailed views scroll content at the provided | 37 // Returns the view in the detailed views scroll content at the provided |
48 // index. | 38 // index. |
49 views::View* GetScrollChildView(int index); | 39 views::View* GetScrollChildView(int index); |
50 | 40 |
51 // test::AshTestBase: | 41 // test::AshTestBase: |
52 void SetUp() override; | 42 void SetUp() override; |
53 void TearDown() override; | 43 void TearDown() override; |
54 | 44 |
55 private: | 45 private: |
56 std::unique_ptr<TrayIME> tray_; | 46 std::unique_ptr<TrayIME> tray_; |
57 std::unique_ptr<views::View> default_view_; | 47 std::unique_ptr<views::View> default_view_; |
58 std::unique_ptr<views::View> detailed_view_; | 48 std::unique_ptr<views::View> detailed_view_; |
59 }; | 49 }; |
60 | 50 |
61 void TrayIMETest::SetUpForStatusAreaWidget( | |
62 StatusAreaWidget* status_area_widget) { | |
63 tray_.reset(new TrayIME(status_area_widget->system_tray())); | |
64 default_view_.reset(tray_->CreateDefaultView( | |
65 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
66 detailed_view_.reset(tray_->CreateDetailedView( | |
67 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
68 } | |
69 | |
70 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { | 51 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { |
71 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled( | 52 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled( |
72 enabled); | 53 enabled); |
73 keyboard::SetAccessibilityKeyboardEnabled(enabled); | 54 keyboard::SetAccessibilityKeyboardEnabled(enabled); |
74 AccessibilityNotificationVisibility notification = | 55 AccessibilityNotificationVisibility notification = |
75 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE; | 56 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE; |
76 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged( | 57 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged( |
77 notification); | 58 notification); |
78 } | 59 } |
79 | 60 |
80 void TrayIMETest::TearDownViews() { | |
81 tray_.reset(); | |
82 default_view_.reset(); | |
83 detailed_view_.reset(); | |
84 } | |
85 | |
86 void TrayIMETest::SetIMELength(int length) { | 61 void TrayIMETest::SetIMELength(int length) { |
87 tray_->ime_list_.clear(); | 62 tray_->ime_list_.clear(); |
88 IMEInfo ime; | 63 IMEInfo ime; |
89 for (int i = 0; i < length; i++) { | 64 for (int i = 0; i < length; i++) { |
90 tray_->ime_list_.push_back(ime); | 65 tray_->ime_list_.push_back(ime); |
91 } | 66 } |
92 tray_->Update(); | 67 tray_->Update(); |
93 } | 68 } |
94 | 69 |
95 views::View* TrayIMETest::GetScrollChildView(int index) { | 70 views::View* TrayIMETest::GetScrollChildView(int index) { |
96 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); | 71 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); |
97 views::View* content = details->scroll_content(); | 72 views::View* content = details->scroll_content(); |
98 EXPECT_TRUE(content); | 73 EXPECT_TRUE(content); |
99 EXPECT_GT(content->child_count(), index); | 74 EXPECT_GT(content->child_count(), index); |
100 return content->child_at(index); | 75 return content->child_at(index); |
101 } | 76 } |
102 | 77 |
103 void TrayIMETest::SetUp() { | 78 void TrayIMETest::SetUp() { |
104 test::AshTestBase::SetUp(); | 79 test::AshTestBase::SetUp(); |
105 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 80 tray_.reset(new TrayIME(GetPrimarySystemTray())); |
| 81 default_view_.reset(tray_->CreateDefaultView(LoginStatus::USER)); |
| 82 detailed_view_.reset(tray_->CreateDetailedView(LoginStatus::USER)); |
106 } | 83 } |
107 | 84 |
108 void TrayIMETest::TearDown() { | 85 void TrayIMETest::TearDown() { |
109 SetAccessibilityKeyboardEnabled(false); | 86 SetAccessibilityKeyboardEnabled(false); |
110 TearDownViews(); | 87 tray_.reset(); |
| 88 default_view_.reset(); |
| 89 detailed_view_.reset(); |
111 test::AshTestBase::TearDown(); | 90 test::AshTestBase::TearDown(); |
112 } | 91 } |
113 | 92 |
114 // Tests that if the keyboard is not suppressed the default view is hidden | 93 // Tests that if the keyboard is not suppressed the default view is hidden |
115 // if less than 2 IMEs are present. | 94 // if less than 2 IMEs are present. |
116 TEST_F(TrayIMETest, HiddenWithNoIMEs) { | 95 TEST_F(TrayIMETest, HiddenWithNoIMEs) { |
117 SetIMELength(0); | 96 SetIMELength(0); |
118 EXPECT_FALSE(default_view()->visible()); | 97 EXPECT_FALSE(default_view()->visible()); |
119 SetIMELength(1); | 98 SetIMELength(1); |
120 EXPECT_FALSE(default_view()->visible()); | 99 EXPECT_FALSE(default_view()->visible()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 toggle = GetScrollChildView(0); | 132 toggle = GetScrollChildView(0); |
154 // Clicking again should disable the keyboard. | 133 // Clicking again should disable the keyboard. |
155 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), | 134 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), |
156 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 135 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
157 toggle->OnGestureEvent(&tap); | 136 toggle->OnGestureEvent(&tap); |
158 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 137 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
159 EXPECT_TRUE(default_view()->visible()); | 138 EXPECT_TRUE(default_view()->visible()); |
160 } | 139 } |
161 | 140 |
162 } // namespace ash | 141 } // namespace ash |
OLD | NEW |