Commit 0d3206ce authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: get OobeDisplayChooserTest tests working for mus

These tests used DeviceDataManager directly, which doesn't work for
mus. The fix is to use InputDeviceClientTestApi. PreferTouchAsPrimary
required an additional call because unit tests don't really bring up
mus.

BUG=776514
TEST=test only changes

Change-Id: Ica853e72d97bada225004bda7d30b507cef4cab0
Reviewed-on: https://chromium-review.googlesource.com/847688
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526556}
parent 4db8a8c4
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_observer.h" #include "ui/display/display_observer.h"
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h" #include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h" #include "ui/events/devices/touchscreen_device.h"
namespace chromeos { namespace chromeos {
...@@ -33,20 +33,10 @@ class OobeDisplayChooserTest : public ash::AshTestBase { ...@@ -33,20 +33,10 @@ class OobeDisplayChooserTest : public ash::AshTestBase {
return display::Screen::GetScreen()->GetPrimaryDisplay().id(); return display::Screen::GetScreen()->GetPrimaryDisplay().id();
} }
void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) {
std::vector<ui::TouchscreenDevice> devices{touchscreen};
ui::DeviceHotplugEventObserver* manager =
ui::DeviceDataManager::GetInstance();
manager->OnTouchscreenDevicesUpdated(devices);
}
// ash::AshTestBase: // ash::AshTestBase:
void SetUp() override { void SetUp() override {
ash::AshTestBase::SetUp(); ash::AshTestBase::SetUp();
static_cast<ui::DeviceHotplugEventObserver*>( ui::InputDeviceClientTestApi().OnDeviceListsComplete();
ui::DeviceDataManager::GetInstance())
->OnDeviceListsComplete();
} }
private: private:
...@@ -75,7 +65,7 @@ TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { ...@@ -75,7 +65,7 @@ TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
"Touchscreen", gfx::Size(800, 600), 1); "Touchscreen", gfx::Size(800, 600), 1);
touchscreen.vendor_id = kWhitelistedId; touchscreen.vendor_id = kWhitelistedId;
UpdateTouchscreenDevices(touchscreen); ui::InputDeviceClientTestApi().SetTouchscreenDevices({touchscreen});
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Associate touchscreen device with display // Associate touchscreen device with display
...@@ -85,6 +75,14 @@ TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { ...@@ -85,6 +75,14 @@ TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
display_manager()->OnNativeDisplaysChanged(display_info); display_manager()->OnNativeDisplaysChanged(display_info);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// For mus we have to explicitly tell the InputDeviceClient the
// TouchscreenDevices. Normally InputDeviceClient is told of the
// TouchscreenDevices by way of implementing
// ui::mojom::InputDeviceObserverMojo. In unit tests InputDeviceClient is not
// wired to the window server (the window server isn't running).
touchscreen.target_display_id = display_info[1].id();
ui::InputDeviceClientTestApi().SetTouchscreenDevices({touchscreen}, true);
OobeDisplayChooser display_chooser; OobeDisplayChooser display_chooser;
EXPECT_EQ(1, GetPrimaryDisplay()); EXPECT_EQ(1, GetPrimaryDisplay());
display_chooser.TryToPlaceUiOnTouchDisplay(); display_chooser.TryToPlaceUiOnTouchDisplay();
...@@ -111,7 +109,7 @@ TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) { ...@@ -111,7 +109,7 @@ TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) {
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
"Touchscreen", gfx::Size(800, 600), 1); "Touchscreen", gfx::Size(800, 600), 1);
touchscreen.vendor_id = kWhitelistedId; touchscreen.vendor_id = kWhitelistedId;
UpdateTouchscreenDevices(touchscreen); ui::InputDeviceClientTestApi().SetTouchscreenDevices({touchscreen});
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Associate touchscreen device with display // Associate touchscreen device with display
......
...@@ -69,12 +69,13 @@ void InputDeviceClientTestApi::SetKeyboardDevices( ...@@ -69,12 +69,13 @@ void InputDeviceClientTestApi::SetKeyboardDevices(
} }
void InputDeviceClientTestApi::SetTouchscreenDevices( void InputDeviceClientTestApi::SetTouchscreenDevices(
const std::vector<TouchscreenDevice>& devices) { const std::vector<TouchscreenDevice>& devices,
bool are_touchscreen_target_displays_valid) {
if (DeviceDataManager::instance_) { if (DeviceDataManager::instance_) {
DeviceDataManager::instance_->OnTouchscreenDevicesUpdated(devices); DeviceDataManager::instance_->OnTouchscreenDevicesUpdated(devices);
} else { } else {
GetInputDeviceClient()->OnTouchscreenDeviceConfigurationChanged(devices, GetInputDeviceClient()->OnTouchscreenDeviceConfigurationChanged(
false); devices, are_touchscreen_target_displays_valid);
} }
} }
......
...@@ -37,7 +37,13 @@ class InputDeviceClientTestApi { ...@@ -37,7 +37,13 @@ class InputDeviceClientTestApi {
void OnDeviceListsComplete(); void OnDeviceListsComplete();
void SetKeyboardDevices(const std::vector<InputDevice>& devices); void SetKeyboardDevices(const std::vector<InputDevice>& devices);
void SetTouchscreenDevices(const std::vector<TouchscreenDevice>& devices);
// |are_touchscreen_target_displays_valid| is only applicable to
// InputDeviceClient. See
// InputDeviceClient::OnTouchscreenDeviceConfigurationChanged() for details.
void SetTouchscreenDevices(
const std::vector<TouchscreenDevice>& devices,
bool are_touchscreen_target_displays_valid = false);
InputDeviceClient* GetInputDeviceClient(); InputDeviceClient* GetInputDeviceClient();
......
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