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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/display/chromeos/display_configurator.h" | 10 #include "ui/display/chromeos/display_configurator.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 class TouchscreenDelegateImplTest : public testing::Test { | 41 class TouchscreenDelegateImplTest : public testing::Test { |
42 public: | 42 public: |
43 TouchscreenDelegateImplTest() {} | 43 TouchscreenDelegateImplTest() {} |
44 virtual ~TouchscreenDelegateImplTest() {} | 44 virtual ~TouchscreenDelegateImplTest() {} |
45 | 45 |
46 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
47 device_manager_ = new MockTouchscreenDeviceManager(); | 47 device_manager_ = new MockTouchscreenDeviceManager(); |
48 delegate_.reset(new TouchscreenDelegateImpl( | 48 delegate_.reset(new TouchscreenDelegateImpl( |
49 scoped_ptr<TouchscreenDeviceManager>(device_manager_))); | 49 scoped_ptr<TouchscreenDeviceManager>(device_manager_))); |
50 | 50 |
51 // Internal display. Must not be matched to a touch screen unless the size | 51 // Internal display will always match to internal touchscreen. If internal |
52 // matches. | 52 // touchscreen can't be detected, it is then associated to a touch screen |
| 53 // with matching size. |
53 TestDisplaySnapshot* snapshot = new TestDisplaySnapshot(); | 54 TestDisplaySnapshot* snapshot = new TestDisplaySnapshot(); |
54 DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0); | 55 DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0); |
55 snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL); | 56 snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL); |
56 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode)); | 57 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode)); |
57 snapshot->set_native_mode(mode); | 58 snapshot->set_native_mode(mode); |
58 displays_.push_back(snapshot); | 59 displays_.push_back(snapshot); |
59 | 60 |
60 snapshot = new TestDisplaySnapshot(); | 61 snapshot = new TestDisplaySnapshot(); |
61 mode = new DisplayMode(gfx::Size(800, 600), false, 60.0); | 62 mode = new DisplayMode(gfx::Size(800, 600), false, 60.0); |
62 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode)); | 63 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) { | 104 TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) { |
104 std::vector<DisplayConfigurator::DisplayState> display_states = | 105 std::vector<DisplayConfigurator::DisplayState> display_states = |
105 GetDisplayStates(); | 106 GetDisplayStates(); |
106 delegate_->AssociateTouchscreens(&display_states); | 107 delegate_->AssociateTouchscreens(&display_states); |
107 | 108 |
108 for (size_t i = 0; i < display_states.size(); ++i) | 109 for (size_t i = 0; i < display_states.size(); ++i) |
109 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id); | 110 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id); |
110 } | 111 } |
111 | 112 |
112 TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) { | 113 TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) { |
113 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(800, 600))); | 114 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(800, 600), false)); |
114 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768))); | 115 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); |
115 | 116 |
116 std::vector<DisplayConfigurator::DisplayState> display_states = | 117 std::vector<DisplayConfigurator::DisplayState> display_states = |
117 GetDisplayStates(); | 118 GetDisplayStates(); |
118 delegate_->AssociateTouchscreens(&display_states); | 119 delegate_->AssociateTouchscreens(&display_states); |
119 | 120 |
120 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); | 121 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); |
121 EXPECT_EQ(1, display_states[1].touch_device_id); | 122 EXPECT_EQ(1, display_states[1].touch_device_id); |
122 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); | 123 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); |
123 EXPECT_EQ(2, display_states[3].touch_device_id); | 124 EXPECT_EQ(2, display_states[3].touch_device_id); |
124 } | 125 } |
125 | 126 |
126 TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) { | 127 TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) { |
127 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768))); | 128 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); |
128 | 129 |
129 std::vector<DisplayConfigurator::DisplayState> display_states = | 130 std::vector<DisplayConfigurator::DisplayState> display_states = |
130 GetDisplayStates(); | 131 GetDisplayStates(); |
131 delegate_->AssociateTouchscreens(&display_states); | 132 delegate_->AssociateTouchscreens(&display_states); |
132 | 133 |
133 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); | 134 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); |
134 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id); | 135 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id); |
135 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); | 136 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); |
136 EXPECT_EQ(2, display_states[3].touch_device_id); | 137 EXPECT_EQ(2, display_states[3].touch_device_id); |
137 } | 138 } |
138 | 139 |
139 TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) { | 140 TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) { |
140 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(801, 600))); | 141 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(801, 600), false)); |
141 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1023, 768))); | 142 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1023, 768), false)); |
142 | 143 |
143 std::vector<DisplayConfigurator::DisplayState> display_states = | 144 std::vector<DisplayConfigurator::DisplayState> display_states = |
144 GetDisplayStates(); | 145 GetDisplayStates(); |
145 delegate_->AssociateTouchscreens(&display_states); | 146 delegate_->AssociateTouchscreens(&display_states); |
146 | 147 |
147 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); | 148 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); |
148 EXPECT_EQ(1, display_states[1].touch_device_id); | 149 EXPECT_EQ(1, display_states[1].touch_device_id); |
149 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); | 150 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); |
150 EXPECT_EQ(2, display_states[3].touch_device_id); | 151 EXPECT_EQ(2, display_states[3].touch_device_id); |
151 } | 152 } |
152 | 153 |
153 TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) { | 154 TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) { |
154 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(1022, 768))); | 155 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(1022, 768), false)); |
155 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(802, 600))); | 156 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(802, 600), false)); |
156 | 157 |
157 std::vector<DisplayConfigurator::DisplayState> display_states = | 158 std::vector<DisplayConfigurator::DisplayState> display_states = |
158 GetDisplayStates(); | 159 GetDisplayStates(); |
159 delegate_->AssociateTouchscreens(&display_states); | 160 delegate_->AssociateTouchscreens(&display_states); |
160 | 161 |
161 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); | 162 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); |
162 EXPECT_EQ(1, display_states[1].touch_device_id); | 163 EXPECT_EQ(1, display_states[1].touch_device_id); |
163 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); | 164 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); |
164 EXPECT_EQ(2, display_states[3].touch_device_id); | 165 EXPECT_EQ(2, display_states[3].touch_device_id); |
165 } | 166 } |
166 | 167 |
| 168 TEST_F(TouchscreenDelegateImplTest, MapInternalTouchscreen) { |
| 169 device_manager_->AddDevice( |
| 170 TouchscreenDevice(1, gfx::Size(1920, 1080), false)); |
| 171 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(9999, 888), true)); |
| 172 |
| 173 std::vector<DisplayConfigurator::DisplayState> display_states = |
| 174 GetDisplayStates(); |
| 175 delegate_->AssociateTouchscreens(&display_states); |
| 176 |
| 177 // Internal touchscreen is always mapped to internal display. |
| 178 EXPECT_EQ(2, display_states[0].touch_device_id); |
| 179 EXPECT_EQ(1, display_states[1].touch_device_id); |
| 180 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); |
| 181 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[3].touch_device_id); |
| 182 } |
| 183 |
167 } // namespace ui | 184 } // namespace ui |
OLD | NEW |