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

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

Issue 2151603002: ash: Fix flaky TrayIME* tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/ash.gyp ('k') | ash/test/virtual_keyboard_test_helper.h » ('j') | 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/tray/system_tray_notifier.h" 9 #include "ash/common/system/tray/system_tray_notifier.h"
10 #include "ash/common/system/tray/tray_details_view.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 "ash/test/virtual_keyboard_test_helper.h"
14 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "ui/events/devices/device_data_manager.h"
15 #include "ui/keyboard/keyboard_util.h" 15 #include "ui/keyboard/keyboard_util.h"
16 16
17 namespace ash { 17 namespace ash {
18 18
19 class TrayIMETest : public test::AshTestBase { 19 class TrayIMETest : public test::AshTestBase {
20 public: 20 public:
21 TrayIMETest() {} 21 TrayIMETest() {}
22 ~TrayIMETest() override {} 22 ~TrayIMETest() override {}
23 23
24 TrayIME* tray() { return tray_.get(); } 24 TrayIME* tray() { return tray_.get(); }
25 25
26 views::View* default_view() { return default_view_.get(); } 26 views::View* default_view() { return default_view_.get(); }
27 27
28 views::View* detailed_view() { return detailed_view_.get(); } 28 views::View* detailed_view() { return detailed_view_.get(); }
29 29
30 // Mocks enabling the a11y virtual keyboard since the actual a11y manager 30 // Mocks enabling the a11y virtual keyboard since the actual a11y manager
31 // is not created in ash tests. 31 // is not created in ash tests.
32 void SetAccessibilityKeyboardEnabled(bool enabled); 32 void SetAccessibilityKeyboardEnabled(bool enabled);
33 33
34 // Sets the current number of active IMEs. 34 // Sets the current number of active IMEs.
35 void SetIMELength(int length); 35 void SetIMELength(int length);
36 36
37 // 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
38 // index. 38 // index.
39 views::View* GetScrollChildView(int index); 39 views::View* GetScrollChildView(int index);
40 40
41 void SuppressKeyboard();
42 void RestoreKeyboard();
43
41 // test::AshTestBase: 44 // test::AshTestBase:
42 void SetUp() override; 45 void SetUp() override;
43 void TearDown() override; 46 void TearDown() override;
44 47
45 private: 48 private:
46 std::unique_ptr<TrayIME> tray_; 49 std::unique_ptr<TrayIME> tray_;
47 std::unique_ptr<views::View> default_view_; 50 std::unique_ptr<views::View> default_view_;
48 std::unique_ptr<views::View> detailed_view_; 51 std::unique_ptr<views::View> detailed_view_;
52
53 bool keyboard_suppressed_ = false;
54 std::vector<ui::TouchscreenDevice> touchscreen_devices_to_restore_;
55 std::vector<ui::InputDevice> keyboard_devices_to_restore_;
56
57 DISALLOW_COPY_AND_ASSIGN(TrayIMETest);
49 }; 58 };
50 59
51 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { 60 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) {
52 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled( 61 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(
53 enabled); 62 enabled);
54 keyboard::SetAccessibilityKeyboardEnabled(enabled); 63 keyboard::SetAccessibilityKeyboardEnabled(enabled);
55 AccessibilityNotificationVisibility notification = 64 AccessibilityNotificationVisibility notification =
56 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE; 65 enabled ? A11Y_NOTIFICATION_SHOW : A11Y_NOTIFICATION_NONE;
57 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged( 66 WmShell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged(
58 notification); 67 notification);
59 } 68 }
60 69
61 void TrayIMETest::SetIMELength(int length) { 70 void TrayIMETest::SetIMELength(int length) {
62 tray_->ime_list_.clear(); 71 tray_->ime_list_.clear();
63 IMEInfo ime; 72 IMEInfo ime;
64 for (int i = 0; i < length; i++) { 73 for (int i = 0; i < length; i++) {
65 tray_->ime_list_.push_back(ime); 74 tray_->ime_list_.push_back(ime);
66 } 75 }
67 tray_->Update(); 76 tray_->Update();
68 } 77 }
69 78
70 views::View* TrayIMETest::GetScrollChildView(int index) { 79 views::View* TrayIMETest::GetScrollChildView(int index) {
71 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); 80 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view());
72 views::View* content = details->scroll_content(); 81 views::View* content = details->scroll_content();
73 EXPECT_TRUE(content); 82 EXPECT_TRUE(content);
74 EXPECT_GT(content->child_count(), index); 83 EXPECT_GT(content->child_count(), index);
75 return content->child_at(index); 84 return content->child_at(index);
76 } 85 }
77 86
87 void TrayIMETest::SuppressKeyboard() {
88 DCHECK(!keyboard_suppressed_);
89 keyboard_suppressed_ = true;
90
91 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
92 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices();
93 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices();
94
95 ui::DeviceHotplugEventObserver* manager =
96 ui::DeviceDataManager::GetInstance();
97 std::vector<ui::TouchscreenDevice> screens;
98 screens.push_back(
99 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
100 "Touchscreen", gfx::Size(1024, 768), 0));
101 manager->OnTouchscreenDevicesUpdated(screens);
102
103 std::vector<ui::InputDevice> keyboards;
104 keyboards.push_back(ui::InputDevice(
105 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
106 manager->OnKeyboardDevicesUpdated(keyboards);
107 }
108
109 void TrayIMETest::RestoreKeyboard() {
110 DCHECK(keyboard_suppressed_);
111 ui::DeviceHotplugEventObserver* manager =
112 ui::DeviceDataManager::GetInstance();
113 manager->OnTouchscreenDevicesUpdated(touchscreen_devices_to_restore_);
114 manager->OnKeyboardDevicesUpdated(keyboard_devices_to_restore_);
115 }
116
78 void TrayIMETest::SetUp() { 117 void TrayIMETest::SetUp() {
79 test::AshTestBase::SetUp(); 118 test::AshTestBase::SetUp();
80 tray_.reset(new TrayIME(GetPrimarySystemTray())); 119 tray_.reset(new TrayIME(GetPrimarySystemTray()));
81 default_view_.reset(tray_->CreateDefaultView(LoginStatus::USER)); 120 default_view_.reset(tray_->CreateDefaultView(LoginStatus::USER));
82 detailed_view_.reset(tray_->CreateDetailedView(LoginStatus::USER)); 121 detailed_view_.reset(tray_->CreateDetailedView(LoginStatus::USER));
83 } 122 }
84 123
85 void TrayIMETest::TearDown() { 124 void TrayIMETest::TearDown() {
125 if (keyboard_suppressed_)
126 RestoreKeyboard();
86 SetAccessibilityKeyboardEnabled(false); 127 SetAccessibilityKeyboardEnabled(false);
87 tray_.reset(); 128 tray_.reset();
88 default_view_.reset(); 129 default_view_.reset();
89 detailed_view_.reset(); 130 detailed_view_.reset();
90 test::AshTestBase::TearDown(); 131 test::AshTestBase::TearDown();
91 } 132 }
92 133
93 // Tests that if the keyboard is not suppressed the default view is hidden 134 // Tests that if the keyboard is not suppressed the default view is hidden
94 // if less than 2 IMEs are present. 135 // if less than 2 IMEs are present.
95 TEST_F(TrayIMETest, HiddenWithNoIMEs) { 136 TEST_F(TrayIMETest, HiddenWithNoIMEs) {
96 SetIMELength(0); 137 SetIMELength(0);
97 EXPECT_FALSE(default_view()->visible()); 138 EXPECT_FALSE(default_view()->visible());
98 SetIMELength(1); 139 SetIMELength(1);
99 EXPECT_FALSE(default_view()->visible()); 140 EXPECT_FALSE(default_view()->visible());
100 SetIMELength(2); 141 SetIMELength(2);
101 EXPECT_TRUE(default_view()->visible()); 142 EXPECT_TRUE(default_view()->visible());
102 } 143 }
103 144
104 // Tests that if no IMEs are present the default view is hidden when a11y is 145 // Tests that if no IMEs are present the default view is hidden when a11y is
105 // enabled. 146 // enabled.
106 TEST_F(TrayIMETest, HidesOnA11yEnabled) { 147 TEST_F(TrayIMETest, HidesOnA11yEnabled) {
107 SetIMELength(0); 148 SetIMELength(0);
108 test::VirtualKeyboardTestHelper::SuppressKeyboard(); 149 SuppressKeyboard();
109 EXPECT_TRUE(default_view()->visible()); 150 EXPECT_TRUE(default_view()->visible());
110 // Enable a11y keyboard. 151 // Enable a11y keyboard.
111 SetAccessibilityKeyboardEnabled(true); 152 SetAccessibilityKeyboardEnabled(true);
112 EXPECT_FALSE(default_view()->visible()); 153 EXPECT_FALSE(default_view()->visible());
113 // Disable the a11y keyboard. 154 // Disable the a11y keyboard.
114 SetAccessibilityKeyboardEnabled(false); 155 SetAccessibilityKeyboardEnabled(false);
115 EXPECT_TRUE(default_view()->visible()); 156 EXPECT_TRUE(default_view()->visible());
116 } 157 }
117 158
118 // Tests that clicking on the keyboard toggle causes the virtual keyboard 159 // Tests that clicking on the keyboard toggle causes the virtual keyboard
119 // to toggle between enabled and disabled. 160 // to toggle between enabled and disabled.
120 TEST_F(TrayIMETest, PerformActionOnDetailedView) { 161 TEST_F(TrayIMETest, PerformActionOnDetailedView) {
121 SetIMELength(0); 162 SetIMELength(0);
122 test::VirtualKeyboardTestHelper::SuppressKeyboard(); 163 SuppressKeyboard();
123 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 164 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
124 views::View* toggle = GetScrollChildView(0); 165 views::View* toggle = GetScrollChildView(0);
125 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), 166 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
126 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); 167 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
127 // Enable the keyboard. 168 // Enable the keyboard.
128 toggle->OnGestureEvent(&tap); 169 toggle->OnGestureEvent(&tap);
129 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 170 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
130 EXPECT_TRUE(default_view()->visible()); 171 EXPECT_TRUE(default_view()->visible());
131 // With no IMEs the toggle should be the first child. 172 // With no IMEs the toggle should be the first child.
132 toggle = GetScrollChildView(0); 173 toggle = GetScrollChildView(0);
133 // Clicking again should disable the keyboard. 174 // Clicking again should disable the keyboard.
134 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), 175 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(),
135 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); 176 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
136 toggle->OnGestureEvent(&tap); 177 toggle->OnGestureEvent(&tap);
137 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 178 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
138 EXPECT_TRUE(default_view()->visible()); 179 EXPECT_TRUE(default_view()->visible());
139 } 180 }
140 181
141 } // namespace ash 182 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash.gyp ('k') | ash/test/virtual_keyboard_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698