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,
ApplyAppsRequestedLocksOnlyInUITabletMode) {
std::unique_ptr<aura::Window> window(CreateAppWindowInShellWithId(0));
TabletModeControllerTestApi tablet_mode_controller_test_api;
// To prevent flakes, detach all external mouse devices first.
tablet_mode_controller_test_api.DettachAllMouseDevices();
// Unit tests are supposed to be in reference to a hypothetical computer, but
// 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);
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
......@@ -827,7 +832,7 @@ TEST_F(ScreenOrientationControllerTest,
// When UI tablet mode triggers again, the most recent app requested
// 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.IsTabletModeStarted());
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
......
......@@ -52,8 +52,20 @@ void TabletModeControllerTestApi::AttachExternalMouse() {
}
}
void TabletModeControllerTestApi::DettachAllMouseDevices() {
// See comment in AttachExternalMouse() for why we need RunUntilIdle().
void TabletModeControllerTestApi::AttachExternalTouchpad() {
// 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();
ui::DeviceDataManagerTestApi().SetMouseDevices({});
if (!IsTabletModeControllerInitialized()) {
......@@ -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) {
scoped_refptr<AccelerometerUpdate> update(new AccelerometerUpdate());
update->Set(ACCELEROMETER_SOURCE_SCREEN, false, lid.x(), lid.y(), lid.z());
......
......@@ -30,12 +30,14 @@ class TabletModeControllerTestApi {
void EnterTabletMode();
void LeaveTabletMode();
// Called to attach an external mouse. If we're currently in tablet mode,
// tablet mode will be ended because of this.
// Called to attach an external mouse/touchpad. If we're currently in tablet
// mode, tablet mode will be ended because of this.
void AttachExternalMouse();
void AttachExternalTouchpad();
// Called in association with the above to remove all attached mouse devices.
void DettachAllMouseDevices();
// Called in association with the above to remove all mice/touchpads.
void DetachAllMice();
void DetachAllTouchpads();
void TriggerLidUpdate(const gfx::Vector3dF& lid);
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