OLD | NEW |
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/gfx/screen_win.h" | 5 #include "ui/gfx/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 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 1.0); | 236 1.0); |
237 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 237 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
238 } | 238 } |
239 | 239 |
240 HWND GetFakeHwnd() { | 240 HWND GetFakeHwnd() { |
241 return fake_hwnd_; | 241 return fake_hwnd_; |
242 } | 242 } |
243 | 243 |
244 private: | 244 private: |
245 HWND fake_hwnd_ = nullptr; | 245 HWND fake_hwnd_ = nullptr; |
| 246 |
| 247 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x); |
246 }; | 248 }; |
247 | 249 |
248 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { | 250 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { |
249 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 251 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
250 ASSERT_EQ(1u, displays.size()); | 252 ASSERT_EQ(1u, displays.size()); |
251 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 253 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
252 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 254 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
253 } | 255 } |
254 | 256 |
255 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { | 257 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { |
(...skipping 27 matching lines...) Expand all Loading... |
283 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | 285 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
284 EXPECT_EQ(display, | 286 EXPECT_EQ(display, |
285 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | 287 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
286 } | 288 } |
287 | 289 |
288 TEST_F(ScreenWinTestSingleDisplay1x, GetPrimaryDisplay) { | 290 TEST_F(ScreenWinTestSingleDisplay1x, GetPrimaryDisplay) { |
289 gfx::Screen* screen = GetScreen(); | 291 gfx::Screen* screen = GetScreen(); |
290 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 292 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
291 } | 293 } |
292 | 294 |
| 295 // Single Display of 1.25 Device Scale Factor. |
| 296 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { |
| 297 public: |
| 298 ScreenWinTestSingleDisplay1_25x() = default; |
| 299 |
| 300 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 301 gfx::SetDefaultDeviceScaleFactor(1.25); |
| 302 // Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the |
| 303 // clamping and not ScreenWin. |
| 304 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 305 gfx::Rect(0, 0, 1920, 1100), |
| 306 L"primary", |
| 307 1.0); |
| 308 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 309 } |
| 310 |
| 311 HWND GetFakeHwnd() { |
| 312 return fake_hwnd_; |
| 313 } |
| 314 |
| 315 private: |
| 316 HWND fake_hwnd_ = nullptr; |
| 317 |
| 318 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); |
| 319 }; |
| 320 |
| 321 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { |
| 322 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 323 ASSERT_EQ(1u, displays.size()); |
| 324 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. |
| 325 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 326 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 327 } |
| 328 |
| 329 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { |
| 330 gfx::Screen* screen = GetScreen(); |
| 331 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| 332 EXPECT_EQ(screen->GetAllDisplays()[0], |
| 333 screen->GetDisplayNearestWindow(native_window)); |
| 334 } |
| 335 |
| 336 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { |
| 337 gfx::Screen* screen = GetScreen(); |
| 338 gfx::Display display = screen->GetAllDisplays()[0]; |
| 339 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 340 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); |
| 341 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); |
| 342 } |
| 343 |
| 344 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) { |
| 345 gfx::Screen* screen = GetScreen(); |
| 346 gfx::Display display = screen->GetAllDisplays()[0]; |
| 347 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 348 EXPECT_EQ(display, |
| 349 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 350 } |
| 351 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { |
| 352 gfx::Screen* screen = GetScreen(); |
| 353 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 354 } |
| 355 |
| 356 // Single Display of 1.25 Device Scale Factor. |
| 357 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { |
| 358 public: |
| 359 ScreenWinTestSingleDisplay1_5x() = default; |
| 360 |
| 361 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 362 gfx::SetDefaultDeviceScaleFactor(1.5); |
| 363 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 364 gfx::Rect(0, 0, 1920, 1100), |
| 365 L"primary", |
| 366 1.5); |
| 367 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 368 } |
| 369 |
| 370 HWND GetFakeHwnd() { |
| 371 return fake_hwnd_; |
| 372 } |
| 373 |
| 374 private: |
| 375 HWND fake_hwnd_ = nullptr; |
| 376 |
| 377 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x); |
| 378 }; |
| 379 |
| 380 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) { |
| 381 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 382 ASSERT_EQ(1u, displays.size()); |
| 383 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds()); |
| 384 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area()); |
| 385 } |
| 386 |
| 387 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) { |
| 388 gfx::Screen* screen = GetScreen(); |
| 389 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| 390 EXPECT_EQ(screen->GetAllDisplays()[0], |
| 391 screen->GetDisplayNearestWindow(native_window)); |
| 392 } |
| 393 |
| 394 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestPoint) { |
| 395 gfx::Screen* screen = GetScreen(); |
| 396 gfx::Display display = screen->GetAllDisplays()[0]; |
| 397 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 398 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 524))); |
| 399 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1279, 733))); |
| 400 } |
| 401 |
| 402 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayMatching) { |
| 403 gfx::Screen* screen = GetScreen(); |
| 404 gfx::Display display = screen->GetAllDisplays()[0]; |
| 405 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 406 EXPECT_EQ(display, |
| 407 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 408 } |
| 409 TEST_F(ScreenWinTestSingleDisplay1_5x, GetPrimaryDisplay) { |
| 410 gfx::Screen* screen = GetScreen(); |
| 411 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 412 } |
| 413 |
| 414 |
293 // Single Display of 2.0 Device Scale Factor. | 415 // Single Display of 2.0 Device Scale Factor. |
294 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { | 416 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
295 public: | 417 public: |
296 ScreenWinTestSingleDisplay2x() = default; | 418 ScreenWinTestSingleDisplay2x() = default; |
297 | 419 |
298 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 420 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
299 gfx::SetDefaultDeviceScaleFactor(2.0); | 421 gfx::SetDefaultDeviceScaleFactor(2.0); |
300 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 422 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
301 gfx::Rect(0, 0, 1920, 1100), | 423 gfx::Rect(0, 0, 1920, 1100), |
302 L"primary", | 424 L"primary", |
(...skipping 11 matching lines...) Expand all Loading... |
314 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); | 436 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); |
315 }; | 437 }; |
316 | 438 |
317 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { | 439 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { |
318 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 440 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
319 ASSERT_EQ(1u, displays.size()); | 441 ASSERT_EQ(1u, displays.size()); |
320 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 442 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
321 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 443 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
322 } | 444 } |
323 | 445 |
| 446 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) { |
| 447 gfx::Screen* screen = GetScreen(); |
| 448 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| 449 EXPECT_EQ(screen->GetAllDisplays()[0], |
| 450 screen->GetDisplayNearestWindow(native_window)); |
| 451 } |
| 452 |
324 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { | 453 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { |
325 gfx::Screen* screen = GetScreen(); | 454 gfx::Screen* screen = GetScreen(); |
326 gfx::Display display = screen->GetAllDisplays()[0]; | 455 gfx::Display display = screen->GetAllDisplays()[0]; |
327 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | 456 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
328 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); | 457 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); |
329 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(959, 599))); | 458 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(959, 599))); |
330 } | 459 } |
331 | 460 |
332 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayMatching) { | 461 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayMatching) { |
333 gfx::Screen* screen = GetScreen(); | 462 gfx::Screen* screen = GetScreen(); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); | 773 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); |
645 } | 774 } |
646 | 775 |
647 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { | 776 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { |
648 gfx::Screen* screen = GetScreen(); | 777 gfx::Screen* screen = GetScreen(); |
649 gfx::Display primary = screen->GetPrimaryDisplay(); | 778 gfx::Display primary = screen->GetPrimaryDisplay(); |
650 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 779 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
651 } | 780 } |
652 | 781 |
653 } // namespace gfx | 782 } // namespace gfx |
OLD | NEW |