Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc

Issue 2964823002: Remove confusing keyboard test & focus on input device (Closed)
Patch Set: Break out device check code Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8 9
9 #include "ash/display/display_configuration_controller.h" 10 #include "ash/display/display_configuration_controller.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/display/display.h" 15 #include "ui/display/display.h"
15 #include "ui/display/display_observer.h" 16 #include "ui/display/display_observer.h"
17 #include "ui/display/manager/chromeos/touchscreen_util.h"
16 #include "ui/display/manager/display_manager.h" 18 #include "ui/display/manager/display_manager.h"
17 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
18 #include "ui/display/test/display_manager_test_api.h" 20 #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"
19 23
20 namespace chromeos { 24 namespace chromeos {
21 25
22 namespace { 26 namespace {
23 27
24 class OobeDisplayChooserTest : public ash::test::AshTestBase { 28 class OobeDisplayChooserTest : public ash::test::AshTestBase {
25 public: 29 public:
26 OobeDisplayChooserTest() : ash::test::AshTestBase() {} 30 OobeDisplayChooserTest() : ash::test::AshTestBase() {}
27 31
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
44 int64_t GetPrimaryDisplay() { 32 int64_t GetPrimaryDisplay() {
45 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); 33 return display::Screen::GetScreen()->GetPrimaryDisplay().id();
46 } 34 }
47 35
36 void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) {
37 std::vector<ui::TouchscreenDevice> vec;
jdufault 2017/07/06 18:19:35 nit: Use {} constructor, ie, std::vector<ui::Touc
Felix Ekblom 2017/07/06 19:37:09 Done.
38 vec.push_back(touchscreen);
39
40 ui::DeviceHotplugEventObserver* manager =
41 ui::DeviceDataManager::GetInstance();
42 manager->OnTouchscreenDevicesUpdated(vec);
43 }
44
48 private: 45 private:
49 std::unique_ptr<display::test::DisplayManagerTestApi>
50 display_manager_test_api_;
51
52 DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest); 46 DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest);
53 }; 47 };
54 48
55 } // namespace 49 } // namespace
56 50
57 TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { 51 TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
52 // Setup 2 displays, second one is intended to be a touch display
53 std::vector<display::ManagedDisplayInfo> display_info;
54 display_info.push_back(
55 display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
56 display_info.push_back(
57 display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
58 display_manager()->OnNativeDisplaysChanged(display_info);
59 base::RunLoop().RunUntilIdle();
60
61 // Make sure the non-touch display is primary
62 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
63
64 // Setup corresponding TouchscreenDevice object
65 ui::TouchscreenDevice touchscreen =
66 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
67 "Touchscreen", gfx::Size(800, 600), 1);
68 touchscreen.vendor_id = 0x266e;
69 UpdateTouchscreenDevices(touchscreen);
70 base::RunLoop().RunUntilIdle();
71
72 // Associate touchscreen device with display
73 display_info[1].AddInputDevice(touchscreen.id);
74 display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
75 display_manager()->OnNativeDisplaysChanged(display_info);
76 base::RunLoop().RunUntilIdle();
77
58 OobeDisplayChooser display_chooser; 78 OobeDisplayChooser display_chooser;
59 79 EXPECT_EQ(1, GetPrimaryDisplay());
60 UpdateDisplay("3000x2000,800x600");
61 display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
62 DisableTouch(ids[0]);
63 EnableTouch(ids[1]);
64
65 EXPECT_EQ(ids[0], GetPrimaryDisplay());
66 display_chooser.TryToPlaceUiOnTouchDisplay(); 80 display_chooser.TryToPlaceUiOnTouchDisplay();
67 base::RunLoop().RunUntilIdle(); 81 base::RunLoop().RunUntilIdle();
68 82 EXPECT_EQ(2, GetPrimaryDisplay());
69 EXPECT_EQ(ids[1], GetPrimaryDisplay());
70 } 83 }
71 84
72 TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) { 85 TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) {
86 // Setup 2 displays, second one is intended to be a touch display
87 std::vector<display::ManagedDisplayInfo> display_info;
88 display_info.push_back(
89 display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
90 display_info.push_back(
91 display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
92 display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
93 display_manager()->OnNativeDisplaysChanged(display_info);
94 base::RunLoop().RunUntilIdle();
95
96 // Make sure the non-touch display is primary
97 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
98
99 // Setup corresponding TouchscreenDevice object
100 ui::TouchscreenDevice touchscreen =
101 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
102 "Touchscreen", gfx::Size(800, 600), 1);
103 touchscreen.vendor_id = 0x266e;
104 UpdateTouchscreenDevices(touchscreen);
105 base::RunLoop().RunUntilIdle();
106
107 // Associate touchscreen device with display
108 display_info[1].AddInputDevice(touchscreen.id);
109 display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
110 display_manager()->OnNativeDisplaysChanged(display_info);
111 base::RunLoop().RunUntilIdle();
112
73 OobeDisplayChooser display_chooser; 113 OobeDisplayChooser display_chooser;
74 114 EXPECT_EQ(1, GetPrimaryDisplay());
75 UpdateDisplay("3000x2000,800x600");
76 display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
77 EnableTouch(ids[0]);
78 EnableTouch(ids[1]);
79
80 EXPECT_EQ(ids[0], GetPrimaryDisplay());
81 display_chooser.TryToPlaceUiOnTouchDisplay(); 115 display_chooser.TryToPlaceUiOnTouchDisplay();
82 base::RunLoop().RunUntilIdle(); 116 base::RunLoop().RunUntilIdle();
83 117 EXPECT_EQ(1, GetPrimaryDisplay());
84 EXPECT_EQ(ids[0], GetPrimaryDisplay());
85 } 118 }
86 119
87 } // namespace chromeos 120 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698