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

Side by Side Diff: ui/display/win/screen_win_unittest.cc

Issue 1913613002: Add place holder to move gfx::Display/Screen to ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « ui/display/win/screen_win_display.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/display/win/screen_win.h" 5 #include "ui/display/win/screen_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <inttypes.h> 8 #include <inttypes.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <cwchar> 11 #include <cwchar>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <unordered_map> 14 #include <unordered_map>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/display/display.h"
20 #include "ui/display/screen.h"
19 #include "ui/display/win/display_info.h" 21 #include "ui/display/win/display_info.h"
20 #include "ui/display/win/dpi.h" 22 #include "ui/display/win/dpi.h"
21 #include "ui/display/win/screen_win_display.h" 23 #include "ui/display/win/screen_win_display.h"
22 #include "ui/gfx/display.h"
23 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/gfx/test/display_util.h" 25 #include "ui/gfx/test/display_util.h"
26 26
27 namespace display { 27 namespace display {
28 namespace win { 28 namespace win {
29 29
30 namespace { 30 namespace {
31 31
32 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, 32 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor,
33 gfx::Rect work, 33 gfx::Rect work,
34 std::wstring device_name) { 34 std::wstring device_name) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 HWND GetRootWindow(HWND hwnd) const override { 121 HWND GetRootWindow(HWND hwnd) const override {
122 return hwnd; 122 return hwnd;
123 } 123 }
124 124
125 std::vector<MONITORINFOEX> monitor_infos_; 125 std::vector<MONITORINFOEX> monitor_infos_;
126 std::unordered_map<HWND, gfx::Rect> hwnd_map_; 126 std::unordered_map<HWND, gfx::Rect> hwnd_map_;
127 127
128 DISALLOW_COPY_AND_ASSIGN(TestScreenWin); 128 DISALLOW_COPY_AND_ASSIGN(TestScreenWin);
129 }; 129 };
130 130
131 gfx::Screen* GetScreen() { 131 Screen* GetScreen() {
132 return gfx::Screen::GetScreen(); 132 return Screen::GetScreen();
133 } 133 }
134 134
135 // Allows tests to specify the screen and associated state. 135 // Allows tests to specify the screen and associated state.
136 class TestScreenWinInitializer { 136 class TestScreenWinInitializer {
137 public: 137 public:
138 virtual void AddMonitor(const gfx::Rect& pixel_bounds, 138 virtual void AddMonitor(const gfx::Rect& pixel_bounds,
139 const gfx::Rect& pixel_work, 139 const gfx::Rect& pixel_work,
140 const wchar_t* device_name, 140 const wchar_t* device_name,
141 float device_scale_factor) = 0; 141 float device_scale_factor) = 0;
142 142
143 virtual HWND CreateFakeHwnd(const gfx::Rect& bounds) = 0; 143 virtual HWND CreateFakeHwnd(const gfx::Rect& bounds) = 0;
144 }; 144 };
145 145
146 class TestScreenWinManager : public TestScreenWinInitializer { 146 class TestScreenWinManager : public TestScreenWinInitializer {
147 public: 147 public:
148 TestScreenWinManager() = default; 148 TestScreenWinManager() = default;
149 149
150 ~TestScreenWinManager() { 150 ~TestScreenWinManager() { Screen::SetScreenInstance(nullptr); }
151 gfx::Screen::SetScreenInstance(nullptr);
152 }
153 151
154 void AddMonitor(const gfx::Rect& pixel_bounds, 152 void AddMonitor(const gfx::Rect& pixel_bounds,
155 const gfx::Rect& pixel_work, 153 const gfx::Rect& pixel_work,
156 const wchar_t* device_name, 154 const wchar_t* device_name,
157 float device_scale_factor) override { 155 float device_scale_factor) override {
158 MONITORINFOEX monitor_info = CreateMonitorInfo(pixel_bounds, 156 MONITORINFOEX monitor_info = CreateMonitorInfo(pixel_bounds,
159 pixel_work, 157 pixel_work,
160 device_name); 158 device_name);
161 monitor_infos_.push_back(monitor_info); 159 monitor_infos_.push_back(monitor_info);
162 display_infos_.push_back(DisplayInfo(monitor_info, 160 display_infos_.push_back(DisplayInfo(monitor_info, device_scale_factor,
163 device_scale_factor, 161 Display::ROTATE_0));
164 gfx::Display::ROTATE_0));
165 } 162 }
166 163
167 HWND CreateFakeHwnd(const gfx::Rect& bounds) override { 164 HWND CreateFakeHwnd(const gfx::Rect& bounds) override {
168 EXPECT_EQ(screen_win_, nullptr); 165 EXPECT_EQ(screen_win_, nullptr);
169 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds)); 166 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds));
170 return hwndLast_; 167 return hwndLast_;
171 } 168 }
172 169
173 void InitializeScreenWin() { 170 void InitializeScreenWin() {
174 ASSERT_EQ(screen_win_, nullptr); 171 ASSERT_EQ(screen_win_, nullptr);
175 screen_win_.reset(new TestScreenWin(display_infos_, 172 screen_win_.reset(new TestScreenWin(display_infos_,
176 monitor_infos_, 173 monitor_infos_,
177 hwnd_map_)); 174 hwnd_map_));
178 gfx::Screen::SetScreenInstance(screen_win_.get()); 175 Screen::SetScreenInstance(screen_win_.get());
179 } 176 }
180 177
181 ScreenWin* GetScreenWin() { 178 ScreenWin* GetScreenWin() {
182 return screen_win_.get(); 179 return screen_win_.get();
183 } 180 }
184 181
185 private: 182 private:
186 HWND hwndLast_ = nullptr; 183 HWND hwndLast_ = nullptr;
187 std::unique_ptr<ScreenWin> screen_win_; 184 std::unique_ptr<ScreenWin> screen_win_;
188 std::vector<MONITORINFOEX> monitor_infos_; 185 std::vector<MONITORINFOEX> monitor_infos_;
189 std::vector<DisplayInfo> display_infos_; 186 std::vector<DisplayInfo> display_infos_;
190 std::unordered_map<HWND, gfx::Rect> hwnd_map_; 187 std::unordered_map<HWND, gfx::Rect> hwnd_map_;
191 188
192 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager); 189 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager);
193 }; 190 };
194 191
195 class ScreenWinTest : public testing::Test { 192 class ScreenWinTest : public testing::Test {
196 protected: 193 protected:
197 ScreenWinTest() = default; 194 ScreenWinTest() = default;
198 195
199 void SetUp() override { 196 void SetUp() override {
200 testing::Test::SetUp(); 197 testing::Test::SetUp();
201 display::win::SetDefaultDeviceScaleFactor(1.0); 198 SetDefaultDeviceScaleFactor(1.0);
202 screen_win_initializer_.reset(new TestScreenWinManager()); 199 screen_win_initializer_.reset(new TestScreenWinManager());
203 SetUpScreen(screen_win_initializer_.get()); 200 SetUpScreen(screen_win_initializer_.get());
204 screen_win_initializer_->InitializeScreenWin(); 201 screen_win_initializer_->InitializeScreenWin();
205 } 202 }
206 203
207 void TearDown() override { 204 void TearDown() override {
208 screen_win_initializer_.reset(); 205 screen_win_initializer_.reset();
209 display::win::SetDefaultDeviceScaleFactor(1.0); 206 SetDefaultDeviceScaleFactor(1.0);
210 testing::Test::TearDown(); 207 testing::Test::TearDown();
211 } 208 }
212 209
213 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0; 210 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0;
214 211
215 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const { 212 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const {
216 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin(); 213 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin();
217 return screen_win->GetNativeWindowFromHWND(hwnd);; 214 return screen_win->GetNativeWindowFromHWND(hwnd);;
218 } 215 }
219 216
(...skipping 20 matching lines...) Expand all
240 return fake_hwnd_; 237 return fake_hwnd_;
241 } 238 }
242 239
243 private: 240 private:
244 HWND fake_hwnd_ = nullptr; 241 HWND fake_hwnd_ = nullptr;
245 242
246 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x); 243 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x);
247 }; 244 };
248 245
249 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { 246 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) {
250 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 247 std::vector<Display> displays = GetScreen()->GetAllDisplays();
251 ASSERT_EQ(1u, displays.size()); 248 ASSERT_EQ(1u, displays.size());
252 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); 249 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds());
253 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); 250 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area());
254 } 251 }
255 252
256 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { 253 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) {
257 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); 254 EXPECT_EQ(1, GetScreen()->GetNumDisplays());
258 } 255 }
259 256
260 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindowPrimaryDisplay) { 257 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindowPrimaryDisplay) {
261 gfx::Screen* screen = GetScreen(); 258 Screen* screen = GetScreen();
262 EXPECT_EQ(screen->GetPrimaryDisplay(), 259 EXPECT_EQ(screen->GetPrimaryDisplay(),
263 screen->GetDisplayNearestWindow(nullptr)); 260 screen->GetDisplayNearestWindow(nullptr));
264 } 261 }
265 262
266 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindow) { 263 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindow) {
267 gfx::Screen* screen = GetScreen(); 264 Screen* screen = GetScreen();
268 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); 265 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd());
269 EXPECT_EQ(screen->GetAllDisplays()[0], 266 EXPECT_EQ(screen->GetAllDisplays()[0],
270 screen->GetDisplayNearestWindow(native_window)); 267 screen->GetDisplayNearestWindow(native_window));
271 } 268 }
272 269
273 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestPoint) { 270 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestPoint) {
274 gfx::Screen* screen = GetScreen(); 271 Screen* screen = GetScreen();
275 gfx::Display display = screen->GetAllDisplays()[0]; 272 Display display = screen->GetAllDisplays()[0];
276 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 273 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
277 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); 274 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952)));
278 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); 275 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199)));
279 } 276 }
280 277
281 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayMatching) { 278 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayMatching) {
282 gfx::Screen* screen = GetScreen(); 279 Screen* screen = GetScreen();
283 gfx::Display display = screen->GetAllDisplays()[0]; 280 Display display = screen->GetAllDisplays()[0];
284 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 281 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
285 EXPECT_EQ(display, 282 EXPECT_EQ(display,
286 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 283 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
287 } 284 }
288 285
289 TEST_F(ScreenWinTestSingleDisplay1x, GetPrimaryDisplay) { 286 TEST_F(ScreenWinTestSingleDisplay1x, GetPrimaryDisplay) {
290 gfx::Screen* screen = GetScreen(); 287 Screen* screen = GetScreen();
291 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 288 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
292 } 289 }
293 290
294 // Single Display of 1.25 Device Scale Factor. 291 // Single Display of 1.25 Device Scale Factor.
295 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { 292 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest {
296 public: 293 public:
297 ScreenWinTestSingleDisplay1_25x() = default; 294 ScreenWinTestSingleDisplay1_25x() = default;
298 295
299 void SetUpScreen(TestScreenWinInitializer* initializer) override { 296 void SetUpScreen(TestScreenWinInitializer* initializer) override {
300 display::win::SetDefaultDeviceScaleFactor(1.25); 297 SetDefaultDeviceScaleFactor(1.25);
301 // Add Monitor of Scale Factor 1.0 since display::GetDPIScale performs the 298 // Add Monitor of Scale Factor 1.0 since display::GetDPIScale performs the
302 // clamping and not ScreenWin. 299 // clamping and not ScreenWin.
303 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 300 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
304 gfx::Rect(0, 0, 1920, 1100), 301 gfx::Rect(0, 0, 1920, 1100),
305 L"primary", 302 L"primary",
306 1.0); 303 1.0);
307 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 304 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
308 } 305 }
309 306
310 HWND GetFakeHwnd() { 307 HWND GetFakeHwnd() {
311 return fake_hwnd_; 308 return fake_hwnd_;
312 } 309 }
313 310
314 private: 311 private:
315 HWND fake_hwnd_ = nullptr; 312 HWND fake_hwnd_ = nullptr;
316 313
317 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); 314 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x);
318 }; 315 };
319 316
320 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { 317 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) {
321 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 318 std::vector<Display> displays = GetScreen()->GetAllDisplays();
322 ASSERT_EQ(1u, displays.size()); 319 ASSERT_EQ(1u, displays.size());
323 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. 320 // On Windows, scale factors of 1.25 or lower are clamped to 1.0.
324 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); 321 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds());
325 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); 322 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area());
326 } 323 }
327 324
328 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { 325 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) {
329 gfx::Screen* screen = GetScreen(); 326 Screen* screen = GetScreen();
330 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); 327 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd());
331 EXPECT_EQ(screen->GetAllDisplays()[0], 328 EXPECT_EQ(screen->GetAllDisplays()[0],
332 screen->GetDisplayNearestWindow(native_window)); 329 screen->GetDisplayNearestWindow(native_window));
333 } 330 }
334 331
335 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { 332 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) {
336 gfx::Screen* screen = GetScreen(); 333 Screen* screen = GetScreen();
337 gfx::Display display = screen->GetAllDisplays()[0]; 334 Display display = screen->GetAllDisplays()[0];
338 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 335 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
339 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); 336 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952)));
340 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); 337 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199)));
341 } 338 }
342 339
343 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) { 340 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) {
344 gfx::Screen* screen = GetScreen(); 341 Screen* screen = GetScreen();
345 gfx::Display display = screen->GetAllDisplays()[0]; 342 Display display = screen->GetAllDisplays()[0];
346 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 343 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
347 EXPECT_EQ(display, 344 EXPECT_EQ(display,
348 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 345 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
349 } 346 }
350 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { 347 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) {
351 gfx::Screen* screen = GetScreen(); 348 Screen* screen = GetScreen();
352 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 349 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
353 } 350 }
354 351
355 // Single Display of 1.25 Device Scale Factor. 352 // Single Display of 1.25 Device Scale Factor.
356 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { 353 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest {
357 public: 354 public:
358 ScreenWinTestSingleDisplay1_5x() = default; 355 ScreenWinTestSingleDisplay1_5x() = default;
359 356
360 void SetUpScreen(TestScreenWinInitializer* initializer) override { 357 void SetUpScreen(TestScreenWinInitializer* initializer) override {
361 display::win::SetDefaultDeviceScaleFactor(1.5); 358 SetDefaultDeviceScaleFactor(1.5);
362 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 359 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
363 gfx::Rect(0, 0, 1920, 1100), 360 gfx::Rect(0, 0, 1920, 1100),
364 L"primary", 361 L"primary",
365 1.5); 362 1.5);
366 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 363 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
367 } 364 }
368 365
369 HWND GetFakeHwnd() { 366 HWND GetFakeHwnd() {
370 return fake_hwnd_; 367 return fake_hwnd_;
371 } 368 }
372 369
373 private: 370 private:
374 HWND fake_hwnd_ = nullptr; 371 HWND fake_hwnd_ = nullptr;
375 372
376 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x); 373 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x);
377 }; 374 };
378 375
379 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) { 376 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) {
380 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 377 std::vector<Display> displays = GetScreen()->GetAllDisplays();
381 ASSERT_EQ(1u, displays.size()); 378 ASSERT_EQ(1u, displays.size());
382 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds()); 379 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds());
383 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area()); 380 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area());
384 } 381 }
385 382
386 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) { 383 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) {
387 gfx::Screen* screen = GetScreen(); 384 Screen* screen = GetScreen();
388 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); 385 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd());
389 EXPECT_EQ(screen->GetAllDisplays()[0], 386 EXPECT_EQ(screen->GetAllDisplays()[0],
390 screen->GetDisplayNearestWindow(native_window)); 387 screen->GetDisplayNearestWindow(native_window));
391 } 388 }
392 389
393 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestPoint) { 390 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestPoint) {
394 gfx::Screen* screen = GetScreen(); 391 Screen* screen = GetScreen();
395 gfx::Display display = screen->GetAllDisplays()[0]; 392 Display display = screen->GetAllDisplays()[0];
396 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 393 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
397 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 524))); 394 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 524)));
398 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1279, 733))); 395 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1279, 733)));
399 } 396 }
400 397
401 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayMatching) { 398 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayMatching) {
402 gfx::Screen* screen = GetScreen(); 399 Screen* screen = GetScreen();
403 gfx::Display display = screen->GetAllDisplays()[0]; 400 Display display = screen->GetAllDisplays()[0];
404 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 401 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
405 EXPECT_EQ(display, 402 EXPECT_EQ(display,
406 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 403 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
407 } 404 }
408 TEST_F(ScreenWinTestSingleDisplay1_5x, GetPrimaryDisplay) { 405 TEST_F(ScreenWinTestSingleDisplay1_5x, GetPrimaryDisplay) {
409 gfx::Screen* screen = GetScreen(); 406 Screen* screen = GetScreen();
410 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 407 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
411 } 408 }
412 409
413 410
414 // Single Display of 2.0 Device Scale Factor. 411 // Single Display of 2.0 Device Scale Factor.
415 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { 412 class ScreenWinTestSingleDisplay2x : public ScreenWinTest {
416 public: 413 public:
417 ScreenWinTestSingleDisplay2x() = default; 414 ScreenWinTestSingleDisplay2x() = default;
418 415
419 void SetUpScreen(TestScreenWinInitializer* initializer) override { 416 void SetUpScreen(TestScreenWinInitializer* initializer) override {
420 display::win::SetDefaultDeviceScaleFactor(2.0); 417 SetDefaultDeviceScaleFactor(2.0);
421 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 418 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
422 gfx::Rect(0, 0, 1920, 1100), 419 gfx::Rect(0, 0, 1920, 1100),
423 L"primary", 420 L"primary",
424 2.0); 421 2.0);
425 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 422 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
426 } 423 }
427 424
428 HWND GetFakeHwnd() { 425 HWND GetFakeHwnd() {
429 return fake_hwnd_; 426 return fake_hwnd_;
430 } 427 }
431 428
432 private: 429 private:
433 HWND fake_hwnd_ = nullptr; 430 HWND fake_hwnd_ = nullptr;
434 431
435 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); 432 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x);
436 }; 433 };
437 434
438 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { 435 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) {
439 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 436 std::vector<Display> displays = GetScreen()->GetAllDisplays();
440 ASSERT_EQ(1u, displays.size()); 437 ASSERT_EQ(1u, displays.size());
441 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); 438 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds());
442 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); 439 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area());
443 } 440 }
444 441
445 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) { 442 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) {
446 gfx::Screen* screen = GetScreen(); 443 Screen* screen = GetScreen();
447 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); 444 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd());
448 EXPECT_EQ(screen->GetAllDisplays()[0], 445 EXPECT_EQ(screen->GetAllDisplays()[0],
449 screen->GetDisplayNearestWindow(native_window)); 446 screen->GetDisplayNearestWindow(native_window));
450 } 447 }
451 448
452 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { 449 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) {
453 gfx::Screen* screen = GetScreen(); 450 Screen* screen = GetScreen();
454 gfx::Display display = screen->GetAllDisplays()[0]; 451 Display display = screen->GetAllDisplays()[0];
455 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 452 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
456 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); 453 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(125, 476)));
457 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(959, 599))); 454 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(959, 599)));
458 } 455 }
459 456
460 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayMatching) { 457 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayMatching) {
461 gfx::Screen* screen = GetScreen(); 458 Screen* screen = GetScreen();
462 gfx::Display display = screen->GetAllDisplays()[0]; 459 Display display = screen->GetAllDisplays()[0];
463 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 460 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
464 EXPECT_EQ(display, 461 EXPECT_EQ(display,
465 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 462 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
466 } 463 }
467 464
468 // Two Displays of 1.0 Device Scale Factor. 465 // Two Displays of 1.0 Device Scale Factor.
469 class ScreenWinTestTwoDisplays1x : public ScreenWinTest { 466 class ScreenWinTestTwoDisplays1x : public ScreenWinTest {
470 public: 467 public:
471 ScreenWinTestTwoDisplays1x() = default; 468 ScreenWinTestTwoDisplays1x() = default;
472 469
(...skipping 20 matching lines...) Expand all
493 } 490 }
494 491
495 private: 492 private:
496 HWND fake_hwnd_left_ = nullptr; 493 HWND fake_hwnd_left_ = nullptr;
497 HWND fake_hwnd_right_ = nullptr; 494 HWND fake_hwnd_right_ = nullptr;
498 495
499 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); 496 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x);
500 }; 497 };
501 498
502 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { 499 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) {
503 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 500 std::vector<Display> displays = GetScreen()->GetAllDisplays();
504 ASSERT_EQ(2u, displays.size()); 501 ASSERT_EQ(2u, displays.size());
505 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); 502 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds());
506 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); 503 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area());
507 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); 504 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds());
508 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); 505 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area());
509 } 506 }
510 507
511 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { 508 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) {
512 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); 509 EXPECT_EQ(2, GetScreen()->GetNumDisplays());
513 } 510 }
514 511
515 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindowPrimaryDisplay) { 512 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindowPrimaryDisplay) {
516 gfx::Screen* screen = GetScreen(); 513 Screen* screen = GetScreen();
517 EXPECT_EQ(screen->GetPrimaryDisplay(), 514 EXPECT_EQ(screen->GetPrimaryDisplay(),
518 screen->GetDisplayNearestWindow(nullptr)); 515 screen->GetDisplayNearestWindow(nullptr));
519 } 516 }
520 517
521 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindow) { 518 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindow) {
522 gfx::Screen* screen = GetScreen(); 519 Screen* screen = GetScreen();
523 const gfx::Display left_display = screen->GetAllDisplays()[0]; 520 const Display left_display = screen->GetAllDisplays()[0];
524 const gfx::Display right_display = screen->GetAllDisplays()[1]; 521 const Display right_display = screen->GetAllDisplays()[1];
525 522
526 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); 523 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd());
527 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); 524 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window));
528 525
529 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); 526 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd());
530 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); 527 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window));
531 } 528 }
532 529
533 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestPoint) { 530 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestPoint) {
534 gfx::Screen* screen = GetScreen(); 531 Screen* screen = GetScreen();
535 const gfx::Display left_display = screen->GetAllDisplays()[0]; 532 const Display left_display = screen->GetAllDisplays()[0];
536 const gfx::Display right_display = screen->GetAllDisplays()[1]; 533 const Display right_display = screen->GetAllDisplays()[1];
537 534
538 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 535 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
539 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); 536 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952)));
540 EXPECT_EQ(left_display, 537 EXPECT_EQ(left_display,
541 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); 538 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199)));
542 539
543 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); 540 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0)));
544 EXPECT_EQ(right_display, 541 EXPECT_EQ(right_display,
545 screen->GetDisplayNearestPoint(gfx::Point(2000, 400))); 542 screen->GetDisplayNearestPoint(gfx::Point(2000, 400)));
546 EXPECT_EQ(right_display, 543 EXPECT_EQ(right_display,
547 screen->GetDisplayNearestPoint(gfx::Point(2719, 599))); 544 screen->GetDisplayNearestPoint(gfx::Point(2719, 599)));
548 } 545 }
549 546
550 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayMatching) { 547 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayMatching) {
551 gfx::Screen* screen = GetScreen(); 548 Screen* screen = GetScreen();
552 const gfx::Display left_display = screen->GetAllDisplays()[0]; 549 const Display left_display = screen->GetAllDisplays()[0];
553 const gfx::Display right_display = screen->GetAllDisplays()[1]; 550 const Display right_display = screen->GetAllDisplays()[1];
554 551
555 EXPECT_EQ(left_display, 552 EXPECT_EQ(left_display,
556 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 553 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
557 EXPECT_EQ(left_display, 554 EXPECT_EQ(left_display,
558 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 555 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
559 556
560 EXPECT_EQ(right_display, 557 EXPECT_EQ(right_display,
561 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); 558 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100)));
562 EXPECT_EQ(right_display, 559 EXPECT_EQ(right_display,
563 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); 560 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100)));
564 } 561 }
565 562
566 TEST_F(ScreenWinTestTwoDisplays1x, GetPrimaryDisplay) { 563 TEST_F(ScreenWinTestTwoDisplays1x, GetPrimaryDisplay) {
567 gfx::Screen* screen = GetScreen(); 564 Screen* screen = GetScreen();
568 gfx::Display primary = screen->GetPrimaryDisplay(); 565 Display primary = screen->GetPrimaryDisplay();
569 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); 566 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin());
570 } 567 }
571 568
572 // Two Displays of 2.0 Device Scale Factor. 569 // Two Displays of 2.0 Device Scale Factor.
573 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { 570 class ScreenWinTestTwoDisplays2x : public ScreenWinTest {
574 public: 571 public:
575 ScreenWinTestTwoDisplays2x() = default; 572 ScreenWinTestTwoDisplays2x() = default;
576 573
577 void SetUpScreen(TestScreenWinInitializer* initializer) override { 574 void SetUpScreen(TestScreenWinInitializer* initializer) override {
578 display::win::SetDefaultDeviceScaleFactor(2.0); 575 SetDefaultDeviceScaleFactor(2.0);
579 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 576 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
580 gfx::Rect(0, 0, 1920, 1100), 577 gfx::Rect(0, 0, 1920, 1100),
581 L"primary", 578 L"primary",
582 2.0); 579 2.0);
583 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), 580 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600),
584 gfx::Rect(1920, 0, 800, 600), 581 gfx::Rect(1920, 0, 800, 600),
585 L"secondary", 582 L"secondary",
586 2.0); 583 2.0);
587 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 584 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
588 fake_hwnd_right_ = 585 fake_hwnd_right_ =
589 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); 586 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600));
590 } 587 }
591 588
592 HWND GetLeftFakeHwnd() { 589 HWND GetLeftFakeHwnd() {
593 return fake_hwnd_left_; 590 return fake_hwnd_left_;
594 } 591 }
595 592
596 HWND GetRightFakeHwnd() { 593 HWND GetRightFakeHwnd() {
597 return fake_hwnd_right_; 594 return fake_hwnd_right_;
598 } 595 }
599 596
600 private: 597 private:
601 HWND fake_hwnd_left_ = nullptr; 598 HWND fake_hwnd_left_ = nullptr;
602 HWND fake_hwnd_right_ = nullptr; 599 HWND fake_hwnd_right_ = nullptr;
603 600
604 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); 601 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x);
605 }; 602 };
606 603
607 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { 604 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) {
608 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 605 std::vector<Display> displays = GetScreen()->GetAllDisplays();
609 ASSERT_EQ(2u, displays.size()); 606 ASSERT_EQ(2u, displays.size());
610 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); 607 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds());
611 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); 608 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area());
612 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); 609 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds());
613 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); 610 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area());
614 } 611 }
615 612
616 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { 613 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) {
617 gfx::Screen* screen = GetScreen(); 614 Screen* screen = GetScreen();
618 EXPECT_EQ(screen->GetPrimaryDisplay(), 615 EXPECT_EQ(screen->GetPrimaryDisplay(),
619 screen->GetDisplayNearestWindow(nullptr)); 616 screen->GetDisplayNearestWindow(nullptr));
620 } 617 }
621 618
622 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindow) { 619 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindow) {
623 gfx::Screen* screen = GetScreen(); 620 Screen* screen = GetScreen();
624 const gfx::Display left_display = screen->GetAllDisplays()[0]; 621 const Display left_display = screen->GetAllDisplays()[0];
625 const gfx::Display right_display = screen->GetAllDisplays()[1]; 622 const Display right_display = screen->GetAllDisplays()[1];
626 623
627 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); 624 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd());
628 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); 625 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window));
629 626
630 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); 627 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd());
631 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); 628 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window));
632 } 629 }
633 630
634 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestPoint) { 631 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestPoint) {
635 gfx::Screen* screen = GetScreen(); 632 Screen* screen = GetScreen();
636 const gfx::Display left_display = screen->GetAllDisplays()[0]; 633 const Display left_display = screen->GetAllDisplays()[0];
637 const gfx::Display right_display = screen->GetAllDisplays()[1]; 634 const Display right_display = screen->GetAllDisplays()[1];
638 635
639 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 636 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
640 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); 637 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476)));
641 EXPECT_EQ(left_display, 638 EXPECT_EQ(left_display,
642 screen->GetDisplayNearestPoint(gfx::Point(959, 599))); 639 screen->GetDisplayNearestPoint(gfx::Point(959, 599)));
643 640
644 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); 641 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0)));
645 EXPECT_EQ(right_display, 642 EXPECT_EQ(right_display,
646 screen->GetDisplayNearestPoint(gfx::Point(1000, 200))); 643 screen->GetDisplayNearestPoint(gfx::Point(1000, 200)));
647 EXPECT_EQ(right_display, 644 EXPECT_EQ(right_display,
648 screen->GetDisplayNearestPoint(gfx::Point(1359, 299))); 645 screen->GetDisplayNearestPoint(gfx::Point(1359, 299)));
649 } 646 }
650 647
651 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayMatching) { 648 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayMatching) {
652 gfx::Screen* screen = GetScreen(); 649 Screen* screen = GetScreen();
653 const gfx::Display left_display = screen->GetAllDisplays()[0]; 650 const Display left_display = screen->GetAllDisplays()[0];
654 const gfx::Display right_display = screen->GetAllDisplays()[1]; 651 const Display right_display = screen->GetAllDisplays()[1];
655 652
656 EXPECT_EQ(left_display, 653 EXPECT_EQ(left_display,
657 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 654 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
658 EXPECT_EQ(left_display, 655 EXPECT_EQ(left_display,
659 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 656 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
660 657
661 EXPECT_EQ(right_display, 658 EXPECT_EQ(right_display,
662 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); 659 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100)));
663 EXPECT_EQ(right_display, 660 EXPECT_EQ(right_display,
664 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); 661 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100)));
665 } 662 }
666 663
667 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { 664 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) {
668 gfx::Screen* screen = GetScreen(); 665 Screen* screen = GetScreen();
669 gfx::Display primary = screen->GetPrimaryDisplay(); 666 Display primary = screen->GetPrimaryDisplay();
670 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); 667 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin());
671 } 668 }
672 669
673 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under 670 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under
674 // Windows DPI Virtualization. Note that the displays do not form a euclidean 671 // Windows DPI Virtualization. Note that the displays do not form a euclidean
675 // space. 672 // space.
676 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { 673 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest {
677 public: 674 public:
678 ScreenWinTestTwoDisplays2x1xVirtualized() = default; 675 ScreenWinTestTwoDisplays2x1xVirtualized() = default;
679 676
680 void SetUpScreen(TestScreenWinInitializer* initializer) override { 677 void SetUpScreen(TestScreenWinInitializer* initializer) override {
681 display::win::SetDefaultDeviceScaleFactor(2.0); 678 SetDefaultDeviceScaleFactor(2.0);
682 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), 679 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600),
683 gfx::Rect(0, 0, 3200, 1500), 680 gfx::Rect(0, 0, 3200, 1500),
684 L"primary", 681 L"primary",
685 2.0); 682 2.0);
686 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), 683 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400),
687 gfx::Rect(6400, 0, 3840, 2400), 684 gfx::Rect(6400, 0, 3840, 2400),
688 L"secondary", 685 L"secondary",
689 2.0); 686 2.0);
690 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); 687 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500));
691 fake_hwnd_right_ = 688 fake_hwnd_right_ =
692 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); 689 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400));
693 } 690 }
694 691
695 HWND GetLeftFakeHwnd() { 692 HWND GetLeftFakeHwnd() {
696 return fake_hwnd_left_; 693 return fake_hwnd_left_;
697 } 694 }
698 695
699 HWND GetRightFakeHwnd() { 696 HWND GetRightFakeHwnd() {
700 return fake_hwnd_right_; 697 return fake_hwnd_right_;
701 } 698 }
702 699
703 private: 700 private:
704 HWND fake_hwnd_left_ = nullptr; 701 HWND fake_hwnd_left_ = nullptr;
705 HWND fake_hwnd_right_ = nullptr; 702 HWND fake_hwnd_right_ = nullptr;
706 703
707 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); 704 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized);
708 }; 705 };
709 706
710 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { 707 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) {
711 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); 708 std::vector<Display> displays = GetScreen()->GetAllDisplays();
712 ASSERT_EQ(2u, displays.size()); 709 ASSERT_EQ(2u, displays.size());
713 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); 710 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds());
714 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); 711 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area());
715 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); 712 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds());
716 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); 713 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area());
717 } 714 }
718 715
719 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { 716 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) {
720 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); 717 EXPECT_EQ(2, GetScreen()->GetNumDisplays());
721 } 718 }
722 719
723 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, 720 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized,
724 GetDisplayNearestWindowPrimaryDisplay) { 721 GetDisplayNearestWindowPrimaryDisplay) {
725 gfx::Screen* screen = GetScreen(); 722 Screen* screen = GetScreen();
726 EXPECT_EQ(screen->GetPrimaryDisplay(), 723 EXPECT_EQ(screen->GetPrimaryDisplay(),
727 screen->GetDisplayNearestWindow(nullptr)); 724 screen->GetDisplayNearestWindow(nullptr));
728 } 725 }
729 726
730 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestWindow) { 727 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestWindow) {
731 gfx::Screen* screen = GetScreen(); 728 Screen* screen = GetScreen();
732 const gfx::Display left_display = screen->GetAllDisplays()[0]; 729 const Display left_display = screen->GetAllDisplays()[0];
733 const gfx::Display right_display = screen->GetAllDisplays()[1]; 730 const Display right_display = screen->GetAllDisplays()[1];
734 731
735 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); 732 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd());
736 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); 733 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window));
737 734
738 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); 735 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd());
739 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); 736 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window));
740 } 737 }
741 738
742 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestPoint) { 739 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestPoint) {
743 gfx::Screen* screen = GetScreen(); 740 Screen* screen = GetScreen();
744 const gfx::Display left_display = screen->GetAllDisplays()[0]; 741 const Display left_display = screen->GetAllDisplays()[0];
745 const gfx::Display right_display = screen->GetAllDisplays()[1]; 742 const Display right_display = screen->GetAllDisplays()[1];
746 743
747 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); 744 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0)));
748 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); 745 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476)));
749 EXPECT_EQ(left_display, 746 EXPECT_EQ(left_display,
750 screen->GetDisplayNearestPoint(gfx::Point(1599, 799))); 747 screen->GetDisplayNearestPoint(gfx::Point(1599, 799)));
751 748
752 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(3200, 0))); 749 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(3200, 0)));
753 EXPECT_EQ(right_display, 750 EXPECT_EQ(right_display,
754 screen->GetDisplayNearestPoint(gfx::Point(4000, 400))); 751 screen->GetDisplayNearestPoint(gfx::Point(4000, 400)));
755 EXPECT_EQ(right_display, 752 EXPECT_EQ(right_display,
756 screen->GetDisplayNearestPoint(gfx::Point(5119, 1199))); 753 screen->GetDisplayNearestPoint(gfx::Point(5119, 1199)));
757 } 754 }
758 755
759 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayMatching) { 756 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayMatching) {
760 gfx::Screen* screen = GetScreen(); 757 Screen* screen = GetScreen();
761 const gfx::Display left_display = screen->GetAllDisplays()[0]; 758 const Display left_display = screen->GetAllDisplays()[0];
762 const gfx::Display right_display = screen->GetAllDisplays()[1]; 759 const Display right_display = screen->GetAllDisplays()[1];
763 760
764 EXPECT_EQ(left_display, 761 EXPECT_EQ(left_display,
765 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); 762 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100)));
766 EXPECT_EQ(left_display, 763 EXPECT_EQ(left_display,
767 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 764 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
768 765
769 EXPECT_EQ(right_display, 766 EXPECT_EQ(right_display,
770 screen->GetDisplayMatching(gfx::Rect(6400, 0, 100, 100))); 767 screen->GetDisplayMatching(gfx::Rect(6400, 0, 100, 100)));
771 EXPECT_EQ(right_display, 768 EXPECT_EQ(right_display,
772 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); 769 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100)));
773 } 770 }
774 771
775 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { 772 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) {
776 gfx::Screen* screen = GetScreen(); 773 Screen* screen = GetScreen();
777 gfx::Display primary = screen->GetPrimaryDisplay(); 774 Display primary = screen->GetPrimaryDisplay();
778 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); 775 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin());
779 } 776 }
780 777
781 } // namespace 778 } // namespace
782 779
783 } // namespace win 780 } // namespace win
784 } // namespace display 781 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/screen_win_display.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698