| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | |
| 9 | 8 |
| 10 #include "ash/display/display_configuration_controller.h" | 9 #include "ash/display/display_configuration_controller.h" |
| 11 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 16 #include "ui/display/display_observer.h" | 15 #include "ui/display/display_observer.h" |
| 17 #include "ui/display/manager/chromeos/touchscreen_util.h" | |
| 18 #include "ui/display/manager/display_manager.h" | 16 #include "ui/display/manager/display_manager.h" |
| 19 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 20 #include "ui/display/test/display_manager_test_api.h" | 18 #include "ui/display/test/display_manager_test_api.h" |
| 21 #include "ui/events/devices/device_data_manager.h" | |
| 22 #include "ui/events/devices/touchscreen_device.h" | |
| 23 | 19 |
| 24 namespace chromeos { | 20 namespace chromeos { |
| 25 | 21 |
| 26 namespace { | 22 namespace { |
| 27 | 23 |
| 28 class OobeDisplayChooserTest : public ash::test::AshTestBase { | 24 class OobeDisplayChooserTest : public ash::test::AshTestBase { |
| 29 public: | 25 public: |
| 30 OobeDisplayChooserTest() : ash::test::AshTestBase() {} | 26 OobeDisplayChooserTest() : ash::test::AshTestBase() {} |
| 31 | 27 |
| 28 void SetUp() override { |
| 29 ash::test::AshTestBase::SetUp(); |
| 30 display_manager_test_api_.reset( |
| 31 new display::test::DisplayManagerTestApi(display_manager())); |
| 32 } |
| 33 |
| 34 void EnableTouch(int64_t id) { |
| 35 display_manager_test_api_->SetTouchSupport( |
| 36 id, display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE); |
| 37 } |
| 38 |
| 39 void DisableTouch(int64_t id) { |
| 40 display_manager_test_api_->SetTouchSupport( |
| 41 id, display::Display::TouchSupport::TOUCH_SUPPORT_UNAVAILABLE); |
| 42 } |
| 43 |
| 32 int64_t GetPrimaryDisplay() { | 44 int64_t GetPrimaryDisplay() { |
| 33 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 45 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 34 } | 46 } |
| 35 | 47 |
| 36 void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) { | 48 private: |
| 37 std::vector<ui::TouchscreenDevice> devices{touchscreen}; | 49 std::unique_ptr<display::test::DisplayManagerTestApi> |
| 50 display_manager_test_api_; |
| 38 | 51 |
| 39 ui::DeviceHotplugEventObserver* manager = | |
| 40 ui::DeviceDataManager::GetInstance(); | |
| 41 manager->OnTouchscreenDevicesUpdated(devices); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest); | 52 DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest); |
| 46 }; | 53 }; |
| 47 | 54 |
| 48 const uint16_t kWhitelistedId = 0x266e; | |
| 49 | |
| 50 } // namespace | 55 } // namespace |
| 51 | 56 |
| 52 TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { | 57 TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { |
| 53 // Setup 2 displays, second one is intended to be a touch display | 58 OobeDisplayChooser display_chooser; |
| 54 std::vector<display::ManagedDisplayInfo> display_info; | 59 |
| 55 display_info.push_back( | 60 UpdateDisplay("3000x2000,800x600"); |
| 56 display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1)); | 61 display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); |
| 57 display_info.push_back( | 62 DisableTouch(ids[0]); |
| 58 display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2)); | 63 EnableTouch(ids[1]); |
| 59 display_manager()->OnNativeDisplaysChanged(display_info); | 64 |
| 65 EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| 66 display_chooser.TryToPlaceUiOnTouchDisplay(); |
| 60 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
| 61 | 68 |
| 62 // Make sure the non-touch display is primary | 69 EXPECT_EQ(ids[1], GetPrimaryDisplay()); |
| 63 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1); | 70 } |
| 64 | 71 |
| 65 // Setup corresponding TouchscreenDevice object | 72 TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) { |
| 66 ui::TouchscreenDevice touchscreen = | 73 OobeDisplayChooser display_chooser; |
| 67 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, | 74 |
| 68 "Touchscreen", gfx::Size(800, 600), 1); | 75 UpdateDisplay("3000x2000,800x600"); |
| 69 touchscreen.vendor_id = kWhitelistedId; | 76 display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); |
| 70 UpdateTouchscreenDevices(touchscreen); | 77 EnableTouch(ids[0]); |
| 78 EnableTouch(ids[1]); |
| 79 |
| 80 EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| 81 display_chooser.TryToPlaceUiOnTouchDisplay(); |
| 71 base::RunLoop().RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
| 72 | 83 |
| 73 // Associate touchscreen device with display | 84 EXPECT_EQ(ids[0], GetPrimaryDisplay()); |
| 74 display_info[1].AddInputDevice(touchscreen.id); | |
| 75 display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); | |
| 76 display_manager()->OnNativeDisplaysChanged(display_info); | |
| 77 base::RunLoop().RunUntilIdle(); | |
| 78 | |
| 79 OobeDisplayChooser display_chooser; | |
| 80 EXPECT_EQ(1, GetPrimaryDisplay()); | |
| 81 display_chooser.TryToPlaceUiOnTouchDisplay(); | |
| 82 base::RunLoop().RunUntilIdle(); | |
| 83 EXPECT_EQ(2, GetPrimaryDisplay()); | |
| 84 } | |
| 85 | |
| 86 TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) { | |
| 87 // Setup 2 displays, second one is intended to be a touch display | |
| 88 std::vector<display::ManagedDisplayInfo> display_info; | |
| 89 display_info.push_back( | |
| 90 display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1)); | |
| 91 display_info.push_back( | |
| 92 display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2)); | |
| 93 display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); | |
| 94 display_manager()->OnNativeDisplaysChanged(display_info); | |
| 95 base::RunLoop().RunUntilIdle(); | |
| 96 | |
| 97 // Make sure the non-touch display is primary | |
| 98 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1); | |
| 99 | |
| 100 // Setup corresponding TouchscreenDevice object | |
| 101 ui::TouchscreenDevice touchscreen = | |
| 102 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, | |
| 103 "Touchscreen", gfx::Size(800, 600), 1); | |
| 104 touchscreen.vendor_id = kWhitelistedId; | |
| 105 UpdateTouchscreenDevices(touchscreen); | |
| 106 base::RunLoop().RunUntilIdle(); | |
| 107 | |
| 108 // Associate touchscreen device with display | |
| 109 display_info[1].AddInputDevice(touchscreen.id); | |
| 110 display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); | |
| 111 display_manager()->OnNativeDisplaysChanged(display_info); | |
| 112 base::RunLoop().RunUntilIdle(); | |
| 113 | |
| 114 OobeDisplayChooser display_chooser; | |
| 115 EXPECT_EQ(1, GetPrimaryDisplay()); | |
| 116 display_chooser.TryToPlaceUiOnTouchDisplay(); | |
| 117 base::RunLoop().RunUntilIdle(); | |
| 118 EXPECT_EQ(1, GetPrimaryDisplay()); | |
| 119 } | 85 } |
| 120 | 86 |
| 121 } // namespace chromeos | 87 } // namespace chromeos |
| OLD | NEW |