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

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

Issue 2686623003: Enable tests in TrayIMETest for MD (Closed)
Patch Set: Addressed review comments Created 3 years, 10 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
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/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/chromeos/ime_menu/ime_list_view.h"
9 #include "ash/common/system/tray/system_tray_notifier.h" 10 #include "ash/common/system/tray/system_tray_notifier.h"
10 #include "ash/common/system/tray/tray_details_view.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "base/command_line.h"
14 #include "ui/events/devices/device_data_manager.h" 13 #include "ui/events/devices/device_data_manager.h"
15 #include "ui/keyboard/keyboard_util.h" 14 #include "ui/keyboard/keyboard_util.h"
16 15
17 namespace ash { 16 namespace ash {
18 17
19 class TrayIMETest : public test::AshTestBase { 18 class TrayIMETest : public test::AshTestBase {
20 public: 19 public:
21 TrayIMETest() {} 20 TrayIMETest() {}
22 ~TrayIMETest() override {} 21 ~TrayIMETest() override {}
23 22
24 TrayIME* tray() { return tray_.get(); } 23 views::View* default_view() const { return default_view_.get(); }
25 24
26 views::View* default_view() { return default_view_.get(); } 25 views::View* detailed_view() const { return detailed_view_.get(); }
27
28 views::View* detailed_view() { return detailed_view_.get(); }
29 26
30 // Mocks enabling the a11y virtual keyboard since the actual a11y manager 27 // Mocks enabling the a11y virtual keyboard since the actual a11y manager
31 // is not created in ash tests. 28 // is not created in ash tests.
32 void SetAccessibilityKeyboardEnabled(bool enabled); 29 void SetAccessibilityKeyboardEnabled(bool enabled);
33 30
34 // Sets the current number of active IMEs. 31 // Sets the current number of active IMEs.
35 void SetIMELength(int length); 32 void SetIMELength(int length);
36 33
37 // Returns the view in the detailed views scroll content at the provided 34 // Returns the view responsible for toggling virtual keyboard.
38 // index. 35 views::View* GetToggleView() const;
39 views::View* GetScrollChildView(int index);
40 36
41 void SuppressKeyboard(); 37 void SuppressKeyboard();
42 void RestoreKeyboard(); 38 void RestoreKeyboard();
43 39
44 // test::AshTestBase: 40 // test::AshTestBase:
45 void SetUp() override; 41 void SetUp() override;
46 void TearDown() override; 42 void TearDown() override;
47 43
48 private: 44 private:
49 std::unique_ptr<TrayIME> tray_; 45 std::unique_ptr<TrayIME> tray_;
(...skipping 18 matching lines...) Expand all
68 64
69 void TrayIMETest::SetIMELength(int length) { 65 void TrayIMETest::SetIMELength(int length) {
70 tray_->ime_list_.clear(); 66 tray_->ime_list_.clear();
71 IMEInfo ime; 67 IMEInfo ime;
72 for (int i = 0; i < length; i++) { 68 for (int i = 0; i < length; i++) {
73 tray_->ime_list_.push_back(ime); 69 tray_->ime_list_.push_back(ime);
74 } 70 }
75 tray_->Update(); 71 tray_->Update();
76 } 72 }
77 73
78 views::View* TrayIMETest::GetScrollChildView(int index) { 74 views::View* TrayIMETest::GetToggleView() const {
79 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); 75 ImeListViewTestApi test_api(static_cast<ImeListView*>(detailed_view()));
80 views::View* content = details->scroll_content(); 76 return test_api.GetToggleView();
81 EXPECT_TRUE(content);
82 EXPECT_GT(content->child_count(), index);
83 return content->child_at(index);
84 } 77 }
85 78
86 void TrayIMETest::SuppressKeyboard() { 79 void TrayIMETest::SuppressKeyboard() {
87 DCHECK(!keyboard_suppressed_); 80 DCHECK(!keyboard_suppressed_);
88 keyboard_suppressed_ = true; 81 keyboard_suppressed_ = true;
89 82
90 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 83 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
91 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices(); 84 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices();
92 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices(); 85 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices();
93 86
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 SetAccessibilityKeyboardEnabled(false); 119 SetAccessibilityKeyboardEnabled(false);
127 tray_.reset(); 120 tray_.reset();
128 default_view_.reset(); 121 default_view_.reset();
129 detailed_view_.reset(); 122 detailed_view_.reset();
130 test::AshTestBase::TearDown(); 123 test::AshTestBase::TearDown();
131 } 124 }
132 125
133 // Tests that if the keyboard is not suppressed the default view is hidden 126 // Tests that if the keyboard is not suppressed the default view is hidden
134 // if less than 2 IMEs are present. 127 // if less than 2 IMEs are present.
135 TEST_F(TrayIMETest, HiddenWithNoIMEs) { 128 TEST_F(TrayIMETest, HiddenWithNoIMEs) {
136 if (MaterialDesignController::IsSystemTrayMenuMaterial())
137 return;
138
139 SetIMELength(0); 129 SetIMELength(0);
140 EXPECT_FALSE(default_view()->visible()); 130 EXPECT_FALSE(default_view()->visible());
141 SetIMELength(1); 131 SetIMELength(1);
142 EXPECT_FALSE(default_view()->visible()); 132 EXPECT_FALSE(default_view()->visible());
143 SetIMELength(2); 133 SetIMELength(2);
144 EXPECT_TRUE(default_view()->visible()); 134 EXPECT_TRUE(default_view()->visible());
145 } 135 }
146 136
147 // Tests that if no IMEs are present the default view is hidden when a11y is 137 // Tests that if no IMEs are present the default view is hidden when a11y is
148 // enabled. 138 // enabled.
149 TEST_F(TrayIMETest, HidesOnA11yEnabled) { 139 TEST_F(TrayIMETest, HidesOnA11yEnabled) {
150 if (MaterialDesignController::IsSystemTrayMenuMaterial())
151 return;
152
153 SetIMELength(0); 140 SetIMELength(0);
154 SuppressKeyboard(); 141 SuppressKeyboard();
155 EXPECT_TRUE(default_view()->visible()); 142 EXPECT_TRUE(default_view()->visible());
156 // Enable a11y keyboard. 143 // Enable a11y keyboard.
157 SetAccessibilityKeyboardEnabled(true); 144 SetAccessibilityKeyboardEnabled(true);
158 EXPECT_FALSE(default_view()->visible()); 145 EXPECT_FALSE(default_view()->visible());
159 // Disable the a11y keyboard. 146 // Disable the a11y keyboard.
160 SetAccessibilityKeyboardEnabled(false); 147 SetAccessibilityKeyboardEnabled(false);
161 EXPECT_TRUE(default_view()->visible()); 148 EXPECT_TRUE(default_view()->visible());
162 } 149 }
163 150
164 // Tests that clicking on the keyboard toggle causes the virtual keyboard 151 // Tests that clicking on the keyboard toggle causes the virtual keyboard
165 // to toggle between enabled and disabled. 152 // to toggle between enabled and disabled.
166 TEST_F(TrayIMETest, PerformActionOnDetailedView) { 153 TEST_F(TrayIMETest, PerformActionOnDetailedView) {
167 if (MaterialDesignController::IsSystemTrayMenuMaterial())
168 return;
169
170 SetIMELength(0); 154 SetIMELength(0);
171 SuppressKeyboard(); 155 SuppressKeyboard();
172 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 156 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
173 views::View* toggle = GetScrollChildView(0); 157 views::View* toggle = GetToggleView();
174 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), 158 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
175 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); 159 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
176 // Enable the keyboard. 160 // Enable the keyboard.
177 toggle->OnGestureEvent(&tap); 161 toggle->OnGestureEvent(&tap);
178 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 162 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
179 EXPECT_TRUE(default_view()->visible()); 163 EXPECT_TRUE(default_view()->visible());
180 // With no IMEs the toggle should be the first child. 164
181 toggle = GetScrollChildView(0);
182 // Clicking again should disable the keyboard. 165 // Clicking again should disable the keyboard.
166 toggle = GetToggleView();
183 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), 167 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(),
184 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); 168 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
185 toggle->OnGestureEvent(&tap); 169 toggle->OnGestureEvent(&tap);
186 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 170 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
187 EXPECT_TRUE(default_view()->visible()); 171 EXPECT_TRUE(default_view()->visible());
188 } 172 }
189 173
190 } // namespace ash 174 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698