Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc |
| diff --git a/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc b/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc |
| index acf074ae225fd6af55f93ded65c3882bc3763420..32284ca15f3e62d68527f0bf3a6977068d4501fb 100644 |
| --- a/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc |
| +++ b/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" |
| #include <memory> |
| +#include <vector> |
| #include "ash/display/display_configuration_controller.h" |
| #include "ash/shell.h" |
| @@ -13,9 +14,12 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/display/display.h" |
| #include "ui/display/display_observer.h" |
| +#include "ui/display/manager/chromeos/touchscreen_util.h" |
| #include "ui/display/manager/display_manager.h" |
| #include "ui/display/screen.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" |
| namespace chromeos { |
| @@ -25,63 +29,91 @@ class OobeDisplayChooserTest : public ash::test::AshTestBase { |
| public: |
| OobeDisplayChooserTest() : ash::test::AshTestBase() {} |
| - void SetUp() override { |
| - ash::test::AshTestBase::SetUp(); |
| - display_manager_test_api_.reset( |
| - new display::test::DisplayManagerTestApi(display_manager())); |
| - } |
| - |
| - void EnableTouch(int64_t id) { |
| - display_manager_test_api_->SetTouchSupport( |
| - id, display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE); |
| + int64_t GetPrimaryDisplay() { |
| + return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| } |
| - void DisableTouch(int64_t id) { |
| - display_manager_test_api_->SetTouchSupport( |
| - id, display::Display::TouchSupport::TOUCH_SUPPORT_UNAVAILABLE); |
| - } |
| + void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) { |
| + std::vector<ui::TouchscreenDevice> vec{touchscreen}; |
| - int64_t GetPrimaryDisplay() { |
| - return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| + ui::DeviceHotplugEventObserver* manager = |
| + ui::DeviceDataManager::GetInstance(); |
| + manager->OnTouchscreenDevicesUpdated(vec); |
| } |
| private: |
| - std::unique_ptr<display::test::DisplayManagerTestApi> |
| - display_manager_test_api_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest); |
| }; |
| } // namespace |
| TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { |
| - OobeDisplayChooser display_chooser; |
| + // Setup 2 displays, second one is intended to be a touch display |
| + std::vector<display::ManagedDisplayInfo> display_info; |
| + display_info.push_back( |
| + display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1)); |
| + display_info.push_back( |
| + display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2)); |
| + display_manager()->OnNativeDisplaysChanged(display_info); |
| + base::RunLoop().RunUntilIdle(); |
| - UpdateDisplay("3000x2000,800x600"); |
| - display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); |
| - DisableTouch(ids[0]); |
| - EnableTouch(ids[1]); |
| + // Make sure the non-touch display is primary |
| + ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1); |
| - EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| - display_chooser.TryToPlaceUiOnTouchDisplay(); |
| + // Setup corresponding TouchscreenDevice object |
| + ui::TouchscreenDevice touchscreen = |
| + ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, |
| + "Touchscreen", gfx::Size(800, 600), 1); |
| + touchscreen.vendor_id = 0x266e; |
| + UpdateTouchscreenDevices(touchscreen); |
| base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(ids[1], GetPrimaryDisplay()); |
| -} |
| + // Associate touchscreen device with display |
| + display_info[1].AddInputDevice(touchscreen.id); |
| + display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); |
| + display_manager()->OnNativeDisplaysChanged(display_info); |
| + base::RunLoop().RunUntilIdle(); |
| -TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) { |
| OobeDisplayChooser display_chooser; |
| + EXPECT_EQ(1, GetPrimaryDisplay()); |
| + display_chooser.TryToPlaceUiOnTouchDisplay(); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(2, GetPrimaryDisplay()); |
| +} |
| - UpdateDisplay("3000x2000,800x600"); |
| - display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); |
| - EnableTouch(ids[0]); |
| - EnableTouch(ids[1]); |
| +TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) { |
| + // Setup 2 displays, second one is intended to be a touch display |
| + std::vector<display::ManagedDisplayInfo> display_info; |
| + display_info.push_back( |
| + display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1)); |
| + display_info.push_back( |
| + display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2)); |
| + display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); |
| + display_manager()->OnNativeDisplaysChanged(display_info); |
| + base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| - display_chooser.TryToPlaceUiOnTouchDisplay(); |
| + // Make sure the non-touch display is primary |
| + ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1); |
| + |
| + // Setup corresponding TouchscreenDevice object |
| + ui::TouchscreenDevice touchscreen = |
| + ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, |
| + "Touchscreen", gfx::Size(800, 600), 1); |
| + touchscreen.vendor_id = 0x266e; |
|
jdufault
2017/07/06 19:58:49
Please extract into named constant (ideally shared
|
| + UpdateTouchscreenDevices(touchscreen); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Associate touchscreen device with display |
| + display_info[1].AddInputDevice(touchscreen.id); |
| + display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); |
| + display_manager()->OnNativeDisplaysChanged(display_info); |
| base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| + OobeDisplayChooser display_chooser; |
| + EXPECT_EQ(1, GetPrimaryDisplay()); |
| + display_chooser.TryToPlaceUiOnTouchDisplay(); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(1, GetPrimaryDisplay()); |
| } |
| } // namespace chromeos |