Commit 5a513860 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

tablet: Edit unit tests to more robustly handle external pointer devices

Bug: 1024309, 1024325
Change-Id: Idbbdcd0d6c79ce2feb3a6ed58a2436896d413840
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931542Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719434}
parent f977a717
...@@ -794,8 +794,13 @@ TEST_F(ScreenOrientationControllerTest, ...@@ -794,8 +794,13 @@ TEST_F(ScreenOrientationControllerTest,
ApplyAppsRequestedLocksOnlyInUITabletMode) { ApplyAppsRequestedLocksOnlyInUITabletMode) {
std::unique_ptr<aura::Window> window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> window(CreateAppWindowInShellWithId(0));
TabletModeControllerTestApi tablet_mode_controller_test_api; TabletModeControllerTestApi tablet_mode_controller_test_api;
// To prevent flakes, detach all external mouse devices first. // Unit tests are supposed to be in reference to a hypothetical computer, but
tablet_mode_controller_test_api.DettachAllMouseDevices(); // they can detect a mouse connected to the actual computer on which they are
// run. That is relevant here because external pointing devices prevent tablet
// mode. Detach all mice, so that this unit test will produce the same results
// whether the host machine has a mouse or not.
tablet_mode_controller_test_api.DetachAllMice();
tablet_mode_controller_test_api.OpenLidToAngle(270); tablet_mode_controller_test_api.OpenLidToAngle(270);
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState()); EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted()); EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
...@@ -827,7 +832,7 @@ TEST_F(ScreenOrientationControllerTest, ...@@ -827,7 +832,7 @@ TEST_F(ScreenOrientationControllerTest,
// When UI tablet mode triggers again, the most recent app requested // When UI tablet mode triggers again, the most recent app requested
// orientation lock for the active window will be applied. // orientation lock for the active window will be applied.
tablet_mode_controller_test_api.DettachAllMouseDevices(); tablet_mode_controller_test_api.DetachAllMice();
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState()); EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted()); EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
......
...@@ -52,8 +52,20 @@ void TabletModeControllerTestApi::AttachExternalMouse() { ...@@ -52,8 +52,20 @@ void TabletModeControllerTestApi::AttachExternalMouse() {
} }
} }
void TabletModeControllerTestApi::DettachAllMouseDevices() { void TabletModeControllerTestApi::AttachExternalTouchpad() {
// See comment in AttachExternalMouse() for why we need RunUntilIdle(). // Similar to |AttachExternalMouse|.
base::RunLoop().RunUntilIdle();
ui::DeviceDataManagerTestApi().SetTouchpadDevices(
{ui::InputDevice(4, ui::InputDeviceType::INPUT_DEVICE_USB, "touchpad")});
if (!IsTabletModeControllerInitialized()) {
tablet_mode_controller_->OnInputDeviceConfigurationChanged(
ui::InputDeviceEventObserver::kTouchpad);
}
}
void TabletModeControllerTestApi::DetachAllMice() {
// See comment in |AttachExternalMouse| for why we need to call
// |base::RunLoop::RunUntilIdle|.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ui::DeviceDataManagerTestApi().SetMouseDevices({}); ui::DeviceDataManagerTestApi().SetMouseDevices({});
if (!IsTabletModeControllerInitialized()) { if (!IsTabletModeControllerInitialized()) {
...@@ -64,6 +76,16 @@ void TabletModeControllerTestApi::DettachAllMouseDevices() { ...@@ -64,6 +76,16 @@ void TabletModeControllerTestApi::DettachAllMouseDevices() {
} }
} }
void TabletModeControllerTestApi::DetachAllTouchpads() {
// Similar to |DetachAllMice|.
base::RunLoop().RunUntilIdle();
ui::DeviceDataManagerTestApi().SetTouchpadDevices({});
if (!IsTabletModeControllerInitialized()) {
tablet_mode_controller_->OnInputDeviceConfigurationChanged(
ui::InputDeviceEventObserver::kTouchpad);
}
}
void TabletModeControllerTestApi::TriggerLidUpdate(const gfx::Vector3dF& lid) { void TabletModeControllerTestApi::TriggerLidUpdate(const gfx::Vector3dF& lid) {
scoped_refptr<AccelerometerUpdate> update(new AccelerometerUpdate()); scoped_refptr<AccelerometerUpdate> update(new AccelerometerUpdate());
update->Set(ACCELEROMETER_SOURCE_SCREEN, false, lid.x(), lid.y(), lid.z()); update->Set(ACCELEROMETER_SOURCE_SCREEN, false, lid.x(), lid.y(), lid.z());
......
...@@ -30,12 +30,14 @@ class TabletModeControllerTestApi { ...@@ -30,12 +30,14 @@ class TabletModeControllerTestApi {
void EnterTabletMode(); void EnterTabletMode();
void LeaveTabletMode(); void LeaveTabletMode();
// Called to attach an external mouse. If we're currently in tablet mode, // Called to attach an external mouse/touchpad. If we're currently in tablet
// tablet mode will be ended because of this. // mode, tablet mode will be ended because of this.
void AttachExternalMouse(); void AttachExternalMouse();
void AttachExternalTouchpad();
// Called in association with the above to remove all attached mouse devices. // Called in association with the above to remove all mice/touchpads.
void DettachAllMouseDevices(); void DetachAllMice();
void DetachAllTouchpads();
void TriggerLidUpdate(const gfx::Vector3dF& lid); void TriggerLidUpdate(const gfx::Vector3dF& lid);
void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base, void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment