Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: ash/common/system/ime/tray_ime_chromeos_unittest.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/common/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/chromeos/ime_menu/ime_list_view.h"
10 #include "ash/common/system/tray/system_tray_notifier.h"
11 #include "ash/common/wm_shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "ui/events/devices/device_data_manager.h"
15 #include "ui/keyboard/keyboard_util.h"
16
17 namespace ash {
18
19 class TrayIMETest : public test::AshTestBase {
20 public:
21 TrayIMETest() {}
22 ~TrayIMETest() override {}
23
24 views::View* default_view() const { return default_view_.get(); }
25
26 views::View* detailed_view() const { return detailed_view_.get(); }
27
28 // Mocks enabling the a11y virtual keyboard since the actual a11y manager
29 // is not created in ash tests.
30 void SetAccessibilityKeyboardEnabled(bool enabled);
31
32 // Sets the current number of active IMEs.
33 void SetIMELength(int length);
34
35 // Returns the view responsible for toggling virtual keyboard.
36 views::View* GetToggleView() const;
37
38 // Sets the managed IMEs tooltip message (and thus also if IMEs are managed =
39 // non-empty or not = empty)
40 void SetManagedMessage(base::string16 managed_message);
41
42 void SuppressKeyboard();
43 void RestoreKeyboard();
44
45 // test::AshTestBase:
46 void SetUp() override;
47 void TearDown() override;
48
49 private:
50 std::unique_ptr<TrayIME> tray_;
51 std::unique_ptr<views::View> default_view_;
52 std::unique_ptr<views::View> detailed_view_;
53
54 bool keyboard_suppressed_ = false;
55 std::vector<ui::TouchscreenDevice> touchscreen_devices_to_restore_;
56 std::vector<ui::InputDevice> keyboard_devices_to_restore_;
57
58 DISALLOW_COPY_AND_ASSIGN(TrayIMETest);
59 };
60
61 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) {
62 WmShell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(enabled);
63 keyboard::SetAccessibilityKeyboardEnabled(enabled);
64 AccessibilityNotificationVisibility notification =
65 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE;
66 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged(
67 notification);
68 }
69
70 void TrayIMETest::SetIMELength(int length) {
71 tray_->ime_list_.clear();
72 IMEInfo ime;
73 for (int i = 0; i < length; i++) {
74 tray_->ime_list_.push_back(ime);
75 }
76 tray_->Update();
77 }
78
79 views::View* TrayIMETest::GetToggleView() const {
80 ImeListViewTestApi test_api(static_cast<ImeListView*>(detailed_view()));
81 return test_api.GetToggleView();
82 }
83
84 void TrayIMETest::SetManagedMessage(base::string16 managed_message) {
85 tray_->ime_managed_message_ = managed_message;
86 tray_->Update();
87 }
88
89 void TrayIMETest::SuppressKeyboard() {
90 DCHECK(!keyboard_suppressed_);
91 keyboard_suppressed_ = true;
92
93 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
94 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices();
95 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices();
96
97 ui::DeviceHotplugEventObserver* manager =
98 ui::DeviceDataManager::GetInstance();
99 std::vector<ui::TouchscreenDevice> screens;
100 screens.push_back(
101 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
102 "Touchscreen", gfx::Size(1024, 768), 0));
103 manager->OnTouchscreenDevicesUpdated(screens);
104
105 std::vector<ui::InputDevice> keyboards;
106 keyboards.push_back(ui::InputDevice(
107 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
108 manager->OnKeyboardDevicesUpdated(keyboards);
109 }
110
111 void TrayIMETest::RestoreKeyboard() {
112 DCHECK(keyboard_suppressed_);
113 ui::DeviceHotplugEventObserver* manager =
114 ui::DeviceDataManager::GetInstance();
115 manager->OnTouchscreenDevicesUpdated(touchscreen_devices_to_restore_);
116 manager->OnKeyboardDevicesUpdated(keyboard_devices_to_restore_);
117 }
118
119 void TrayIMETest::SetUp() {
120 test::AshTestBase::SetUp();
121 tray_.reset(new TrayIME(GetPrimarySystemTray()));
122 default_view_.reset(tray_->CreateDefaultView(LoginStatus::USER));
123 detailed_view_.reset(tray_->CreateDetailedView(LoginStatus::USER));
124 }
125
126 void TrayIMETest::TearDown() {
127 if (keyboard_suppressed_)
128 RestoreKeyboard();
129 SetAccessibilityKeyboardEnabled(false);
130 tray_.reset();
131 default_view_.reset();
132 detailed_view_.reset();
133 test::AshTestBase::TearDown();
134 }
135
136 // Tests that if the keyboard is not suppressed the default view is hidden
137 // if less than 2 IMEs are present.
138 TEST_F(TrayIMETest, HiddenWithNoIMEs) {
139 SetIMELength(0);
140 EXPECT_FALSE(default_view()->visible());
141 SetIMELength(1);
142 EXPECT_FALSE(default_view()->visible());
143 SetIMELength(2);
144 EXPECT_TRUE(default_view()->visible());
145 }
146
147 // Tests that if IMEs are managed, the default view is displayed even for a
148 // single IME.
149 TEST_F(TrayIMETest, ShownWithSingleIMEWhenManaged) {
150 SetManagedMessage(base::ASCIIToUTF16("managed"));
151 SetIMELength(0);
152 EXPECT_FALSE(default_view()->visible());
153 SetIMELength(1);
154 EXPECT_TRUE(default_view()->visible());
155 SetIMELength(2);
156 EXPECT_TRUE(default_view()->visible());
157 }
158
159 // Tests that if no IMEs are present the default view is hidden when a11y is
160 // enabled.
161 TEST_F(TrayIMETest, HidesOnA11yEnabled) {
162 // TODO: investigate failure in mash. http://crbug.com/695561.
163 if (WmShell::Get()->IsRunningInMash())
164 return;
165
166 SetIMELength(0);
167 SuppressKeyboard();
168 EXPECT_TRUE(default_view()->visible());
169 // Enable a11y keyboard.
170 SetAccessibilityKeyboardEnabled(true);
171 EXPECT_FALSE(default_view()->visible());
172 // Disable the a11y keyboard.
173 SetAccessibilityKeyboardEnabled(false);
174 EXPECT_TRUE(default_view()->visible());
175 }
176
177 // Tests that clicking on the keyboard toggle causes the virtual keyboard
178 // to toggle between enabled and disabled.
179 TEST_F(TrayIMETest, PerformActionOnDetailedView) {
180 // TODO: investigate failure in mash. http://crbug.com/695561.
181 if (WmShell::Get()->IsRunningInMash())
182 return;
183
184 SetIMELength(0);
185 SuppressKeyboard();
186 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
187 views::View* toggle = GetToggleView();
188 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
189 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
190 // Enable the keyboard.
191 toggle->OnGestureEvent(&tap);
192 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
193 EXPECT_TRUE(default_view()->visible());
194
195 // Clicking again should disable the keyboard.
196 toggle = GetToggleView();
197 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(),
198 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
199 toggle->OnGestureEvent(&tap);
200 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
201 EXPECT_TRUE(default_view()->visible());
202 }
203
204 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/ime/tray_ime_chromeos.cc ('k') | ash/common/system/keyboard_brightness_control_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698