| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "ash/common/display/display_info.h" | |
| 9 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/test/display_manager_test_api.h" | 9 #include "ash/test/display_manager_test_api.h" |
| 11 #include "ash/touch/touchscreen_util.h" | 10 #include "ash/touch/touchscreen_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/display/manager/managed_display_info.h" |
| 13 #include "ui/events/devices/input_device.h" | 13 #include "ui/events/devices/input_device.h" |
| 14 | 14 |
| 15 namespace ash { | 15 namespace ash { |
| 16 | 16 |
| 17 using DisplayInfoList = std::vector<display::ManagedDisplayInfo>; |
| 18 |
| 17 class TouchscreenUtilTest : public test::AshTestBase { | 19 class TouchscreenUtilTest : public test::AshTestBase { |
| 18 public: | 20 public: |
| 19 TouchscreenUtilTest() {} | 21 TouchscreenUtilTest() {} |
| 20 ~TouchscreenUtilTest() override {} | 22 ~TouchscreenUtilTest() override {} |
| 21 | 23 |
| 22 void SetUp() override { | 24 void SetUp() override { |
| 23 test::AshTestBase::SetUp(); | 25 test::AshTestBase::SetUp(); |
| 24 // Internal display will always match to internal touchscreen. If internal | 26 // Internal display will always match to internal touchscreen. If internal |
| 25 // touchscreen can't be detected, it is then associated to a touch screen | 27 // touchscreen can't be detected, it is then associated to a touch screen |
| 26 // with matching size. | 28 // with matching size. |
| 27 { | 29 { |
| 28 DisplayInfo display(1, "1", false); | 30 display::ManagedDisplayInfo display(1, "1", false); |
| 29 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 31 scoped_refptr<display::ManagedDisplayMode> mode( |
| 30 gfx::Size(1920, 1080), 60.0, false /* interlaced */, | 32 new display::ManagedDisplayMode(gfx::Size(1920, 1080), 60.0, |
| 31 true /* native */, 1.0 /* ui_scale */, | 33 false /* interlaced */, |
| 32 1.0 /* device_scale_factor */)); | 34 true /* native */, 1.0 /* ui_scale */, |
| 33 DisplayInfo::ManagedDisplayModeList modes(1, mode); | 35 1.0 /* device_scale_factor */)); |
| 36 display::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode); |
| 34 display.SetManagedDisplayModes(modes); | 37 display.SetManagedDisplayModes(modes); |
| 35 displays_.push_back(display); | 38 displays_.push_back(display); |
| 36 } | 39 } |
| 37 | 40 |
| 38 { | 41 { |
| 39 DisplayInfo display(2, "2", false); | 42 display::ManagedDisplayInfo display(2, "2", false); |
| 40 | 43 |
| 41 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 44 scoped_refptr<display::ManagedDisplayMode> mode( |
| 42 gfx::Size(800, 600), 60.0, false /* interlaced */, true /* native */, | 45 new display::ManagedDisplayMode(gfx::Size(800, 600), 60.0, |
| 43 1.0 /* ui_scale */, 1.0 /* device_scale_factor */)); | 46 false /* interlaced */, |
| 44 DisplayInfo::ManagedDisplayModeList modes(1, mode); | 47 true /* native */, 1.0 /* ui_scale */, |
| 48 1.0 /* device_scale_factor */)); |
| 49 display::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode); |
| 45 display.SetManagedDisplayModes(modes); | 50 display.SetManagedDisplayModes(modes); |
| 46 displays_.push_back(display); | 51 displays_.push_back(display); |
| 47 } | 52 } |
| 48 | 53 |
| 49 // Display without native mode. Must not be matched to any touch screen. | 54 // Display without native mode. Must not be matched to any touch screen. |
| 50 { | 55 { |
| 51 DisplayInfo display(3, "3", false); | 56 display::ManagedDisplayInfo display(3, "3", false); |
| 52 displays_.push_back(display); | 57 displays_.push_back(display); |
| 53 } | 58 } |
| 54 | 59 |
| 55 { | 60 { |
| 56 DisplayInfo display(4, "4", false); | 61 display::ManagedDisplayInfo display(4, "4", false); |
| 57 | 62 |
| 58 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 63 scoped_refptr<display::ManagedDisplayMode> mode( |
| 59 gfx::Size(1024, 768), 60.0, false /* interlaced */, | 64 new display::ManagedDisplayMode(gfx::Size(1024, 768), 60.0, |
| 60 /* native */ true, 1.0 /* ui_scale */, | 65 false /* interlaced */, |
| 61 1.0 /* device_scale_factor */)); | 66 /* native */ true, 1.0 /* ui_scale */, |
| 62 DisplayInfo::ManagedDisplayModeList modes(1, mode); | 67 1.0 /* device_scale_factor */)); |
| 68 display::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode); |
| 63 display.SetManagedDisplayModes(modes); | 69 display.SetManagedDisplayModes(modes); |
| 64 displays_.push_back(display); | 70 displays_.push_back(display); |
| 65 } | 71 } |
| 66 } | 72 } |
| 67 | 73 |
| 68 void TearDown() override { | 74 void TearDown() override { |
| 69 displays_.clear(); | 75 displays_.clear(); |
| 70 test::AshTestBase::TearDown(); | 76 test::AshTestBase::TearDown(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 protected: | 79 protected: |
| 74 std::vector<DisplayInfo> displays_; | 80 DisplayInfoList displays_; |
| 75 | 81 |
| 76 private: | 82 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest); | 83 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest); |
| 78 }; | 84 }; |
| 79 | 85 |
| 80 TEST_F(TouchscreenUtilTest, NoTouchscreens) { | 86 TEST_F(TouchscreenUtilTest, NoTouchscreens) { |
| 81 std::vector<ui::TouchscreenDevice> devices; | 87 std::vector<ui::TouchscreenDevice> devices; |
| 82 | 88 |
| 83 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); | 89 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); |
| 84 AssociateTouchscreens(&displays_, devices); | 90 AssociateTouchscreens(&displays_, devices); |
| 85 | 91 |
| 86 for (size_t i = 0; i < displays_.size(); ++i) | 92 for (size_t i = 0; i < displays_.size(); ++i) |
| 87 EXPECT_EQ(0u, displays_[i].input_devices().size()); | 93 EXPECT_EQ(0u, displays_[i].input_devices().size()); |
| 88 } | 94 } |
| 89 | 95 |
| 90 // Verify that if there are a lot of touchscreens, they will all get associated | 96 // Verify that if there are a lot of touchscreens, they will all get associated |
| 91 // with a display. | 97 // with a display. |
| 92 TEST_F(TouchscreenUtilTest, ManyTouchscreens) { | 98 TEST_F(TouchscreenUtilTest, ManyTouchscreens) { |
| 93 std::vector<ui::TouchscreenDevice> devices; | 99 std::vector<ui::TouchscreenDevice> devices; |
| 94 for (int i = 0; i < 5; ++i) { | 100 for (int i = 0; i < 5; ++i) { |
| 95 devices.push_back( | 101 devices.push_back( |
| 96 ui::TouchscreenDevice(i, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", | 102 ui::TouchscreenDevice(i, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", |
| 97 gfx::Size(256, 256), 0)); | 103 gfx::Size(256, 256), 0)); |
| 98 } | 104 } |
| 99 | 105 |
| 100 std::vector<DisplayInfo> displays; | 106 DisplayInfoList displays; |
| 101 displays.push_back(displays_[3]); | 107 displays.push_back(displays_[3]); |
| 102 | 108 |
| 103 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); | 109 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); |
| 104 AssociateTouchscreens(&displays, devices); | 110 AssociateTouchscreens(&displays, devices); |
| 105 | 111 |
| 106 for (int i = 0; i < 5; ++i) | 112 for (int i = 0; i < 5; ++i) |
| 107 EXPECT_EQ(i, displays[0].input_devices()[i]); | 113 EXPECT_EQ(i, displays[0].input_devices()[i]); |
| 108 } | 114 } |
| 109 | 115 |
| 110 TEST_F(TouchscreenUtilTest, OneToOneMapping) { | 116 TEST_F(TouchscreenUtilTest, OneToOneMapping) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 171 |
| 166 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) { | 172 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) { |
| 167 std::vector<ui::TouchscreenDevice> devices; | 173 std::vector<ui::TouchscreenDevice> devices; |
| 168 devices.push_back( | 174 devices.push_back( |
| 169 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", | 175 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", |
| 170 gfx::Size(1022, 768), 0)); | 176 gfx::Size(1022, 768), 0)); |
| 171 devices.push_back( | 177 devices.push_back( |
| 172 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "2", | 178 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "2", |
| 173 gfx::Size(802, 600), 0)); | 179 gfx::Size(802, 600), 0)); |
| 174 | 180 |
| 175 std::vector<DisplayInfo> displays; | 181 DisplayInfoList displays; |
| 176 displays.push_back(displays_[0]); | 182 displays.push_back(displays_[0]); |
| 177 displays.push_back(displays_[1]); | 183 displays.push_back(displays_[1]); |
| 178 | 184 |
| 179 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); | 185 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); |
| 180 AssociateTouchscreens(&displays, devices); | 186 AssociateTouchscreens(&displays, devices); |
| 181 | 187 |
| 182 EXPECT_EQ(0u, displays[0].input_devices().size()); | 188 EXPECT_EQ(0u, displays[0].input_devices().size()); |
| 183 EXPECT_EQ(2u, displays[1].input_devices().size()); | 189 EXPECT_EQ(2u, displays[1].input_devices().size()); |
| 184 EXPECT_EQ(1, displays[1].input_devices()[0]); | 190 EXPECT_EQ(1, displays[1].input_devices()[0]); |
| 185 EXPECT_EQ(2, displays[1].input_devices()[1]); | 191 EXPECT_EQ(2, displays[1].input_devices()[1]); |
| 186 } | 192 } |
| 187 | 193 |
| 188 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) { | 194 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) { |
| 189 std::vector<ui::TouchscreenDevice> devices; | 195 std::vector<ui::TouchscreenDevice> devices; |
| 190 devices.push_back( | 196 devices.push_back( |
| 191 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", | 197 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", |
| 192 gfx::Size(1920, 1080), 0)); | 198 gfx::Size(1920, 1080), 0)); |
| 193 devices.push_back( | 199 devices.push_back( |
| 194 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "2", | 200 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "2", |
| 195 gfx::Size(9999, 888), 0)); | 201 gfx::Size(9999, 888), 0)); |
| 196 | 202 |
| 197 std::vector<DisplayInfo> displays; | 203 DisplayInfoList displays; |
| 198 displays.push_back(displays_[0]); | 204 displays.push_back(displays_[0]); |
| 199 displays.push_back(displays_[1]); | 205 displays.push_back(displays_[1]); |
| 200 | 206 |
| 201 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); | 207 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); |
| 202 AssociateTouchscreens(&displays, devices); | 208 AssociateTouchscreens(&displays, devices); |
| 203 | 209 |
| 204 // Internal touchscreen is always mapped to internal display. | 210 // Internal touchscreen is always mapped to internal display. |
| 205 EXPECT_EQ(1u, displays[0].input_devices().size()); | 211 EXPECT_EQ(1u, displays[0].input_devices().size()); |
| 206 EXPECT_EQ(2, displays[0].input_devices()[0]); | 212 EXPECT_EQ(2, displays[0].input_devices()[0]); |
| 207 EXPECT_EQ(1u, displays[1].input_devices().size()); | 213 EXPECT_EQ(1u, displays[1].input_devices().size()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 AssociateTouchscreens(&displays_, devices); | 270 AssociateTouchscreens(&displays_, devices); |
| 265 | 271 |
| 266 EXPECT_EQ(1u, displays_[0].input_devices().size()); | 272 EXPECT_EQ(1u, displays_[0].input_devices().size()); |
| 267 EXPECT_EQ(1, displays_[0].input_devices()[0]); | 273 EXPECT_EQ(1, displays_[0].input_devices()[0]); |
| 268 EXPECT_EQ(0u, displays_[1].input_devices().size()); | 274 EXPECT_EQ(0u, displays_[1].input_devices().size()); |
| 269 EXPECT_EQ(0u, displays_[2].input_devices().size()); | 275 EXPECT_EQ(0u, displays_[2].input_devices().size()); |
| 270 EXPECT_EQ(0u, displays_[3].input_devices().size()); | 276 EXPECT_EQ(0u, displays_[3].input_devices().size()); |
| 271 } | 277 } |
| 272 | 278 |
| 273 } // namespace ash | 279 } // namespace ash |
| OLD | NEW |