OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/ime/tray_ime_chromeos.h" | |
6 | |
7 #include "ash/common/accessibility_delegate.h" | |
8 #include "ash/common/accessibility_types.h" | |
9 #include "ash/common/system/tray/tray_details_view.h" | |
10 #include "ash/common/system/tray/wm_system_tray_notifier.h" | |
11 #include "ash/common/wm_shell.h" | |
12 #include "ash/system/status_area_widget.h" | |
13 #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" | |
16 #include "base/command_line.h" | |
17 #include "ui/keyboard/keyboard_util.h" | |
18 | |
19 namespace ash { | |
20 | |
21 class TrayIMETest : public test::AshTestBase { | |
22 public: | |
23 TrayIMETest() {} | |
24 ~TrayIMETest() override {} | |
25 | |
26 TrayIME* tray() { return tray_.get(); } | |
27 | |
28 views::View* default_view() { return default_view_.get(); } | |
29 | |
30 views::View* detailed_view() { return detailed_view_.get(); } | |
31 | |
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 | |
36 // is not created in ash tests. | |
37 void SetAccessibilityKeyboardEnabled(bool enabled); | |
38 | |
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. | |
45 void SetIMELength(int length); | |
46 | |
47 // Returns the view in the detailed views scroll content at the provided | |
48 // index. | |
49 views::View* GetScrollChildView(int index); | |
50 | |
51 // test::AshTestBase: | |
52 void SetUp() override; | |
53 void TearDown() override; | |
54 | |
55 private: | |
56 std::unique_ptr<TrayIME> tray_; | |
57 std::unique_ptr<views::View> default_view_; | |
58 std::unique_ptr<views::View> detailed_view_; | |
59 }; | |
60 | |
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) { | |
71 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled( | |
72 enabled); | |
73 keyboard::SetAccessibilityKeyboardEnabled(enabled); | |
74 AccessibilityNotificationVisibility notification = | |
75 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE; | |
76 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged( | |
77 notification); | |
78 } | |
79 | |
80 void TrayIMETest::TearDownViews() { | |
81 tray_.reset(); | |
82 default_view_.reset(); | |
83 detailed_view_.reset(); | |
84 } | |
85 | |
86 void TrayIMETest::SetIMELength(int length) { | |
87 tray_->ime_list_.clear(); | |
88 IMEInfo ime; | |
89 for (int i = 0; i < length; i++) { | |
90 tray_->ime_list_.push_back(ime); | |
91 } | |
92 tray_->Update(); | |
93 } | |
94 | |
95 views::View* TrayIMETest::GetScrollChildView(int index) { | |
96 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); | |
97 views::View* content = details->scroll_content(); | |
98 EXPECT_TRUE(content); | |
99 EXPECT_GT(content->child_count(), index); | |
100 return content->child_at(index); | |
101 } | |
102 | |
103 void TrayIMETest::SetUp() { | |
104 test::AshTestBase::SetUp(); | |
105 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
106 } | |
107 | |
108 void TrayIMETest::TearDown() { | |
109 SetAccessibilityKeyboardEnabled(false); | |
110 TearDownViews(); | |
111 test::AshTestBase::TearDown(); | |
112 } | |
113 | |
114 // Tests that if the keyboard is not suppressed the default view is hidden | |
115 // if less than 2 IMEs are present. | |
116 TEST_F(TrayIMETest, HiddenWithNoIMEs) { | |
117 SetIMELength(0); | |
118 EXPECT_FALSE(default_view()->visible()); | |
119 SetIMELength(1); | |
120 EXPECT_FALSE(default_view()->visible()); | |
121 SetIMELength(2); | |
122 EXPECT_TRUE(default_view()->visible()); | |
123 } | |
124 | |
125 // Tests that if no IMEs are present the default view is hidden when a11y is | |
126 // enabled. | |
127 TEST_F(TrayIMETest, HidesOnA11yEnabled) { | |
128 SetIMELength(0); | |
129 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | |
130 EXPECT_TRUE(default_view()->visible()); | |
131 // Enable a11y keyboard. | |
132 SetAccessibilityKeyboardEnabled(true); | |
133 EXPECT_FALSE(default_view()->visible()); | |
134 // Disable the a11y keyboard. | |
135 SetAccessibilityKeyboardEnabled(false); | |
136 EXPECT_TRUE(default_view()->visible()); | |
137 } | |
138 | |
139 // Tests that clicking on the keyboard toggle causes the virtual keyboard | |
140 // to toggle between enabled and disabled. | |
141 TEST_F(TrayIMETest, PerformActionOnDetailedView) { | |
142 SetIMELength(0); | |
143 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | |
144 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
145 views::View* toggle = GetScrollChildView(0); | |
146 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | |
147 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
148 // Enable the keyboard. | |
149 toggle->OnGestureEvent(&tap); | |
150 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | |
151 EXPECT_TRUE(default_view()->visible()); | |
152 // With no IMEs the toggle should be the first child. | |
153 toggle = GetScrollChildView(0); | |
154 // Clicking again should disable the keyboard. | |
155 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), | |
156 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
157 toggle->OnGestureEvent(&tap); | |
158 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
159 EXPECT_TRUE(default_view()->visible()); | |
160 } | |
161 | |
162 } // namespace ash | |
OLD | NEW |