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

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

Issue 2157243003: Allow Chrome on Windows to draw at 1.25 device scale factor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tiny edits Created 4 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
« no previous file with comments | « ui/display/win/dpi.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
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 383 }
384 384
385 namespace { 385 namespace {
386 386
387 // Single Display of 1.25 Device Scale Factor. 387 // Single Display of 1.25 Device Scale Factor.
388 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { 388 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest {
389 public: 389 public:
390 ScreenWinTestSingleDisplay1_25x() = default; 390 ScreenWinTestSingleDisplay1_25x() = default;
391 391
392 void SetUpScreen(TestScreenWinInitializer* initializer) override { 392 void SetUpScreen(TestScreenWinInitializer* initializer) override {
393 // Add Monitor of Scale Factor 1.0 since 1.25 is clamped to 1.0. 393 // Add Monitor of Scale Factor 1.0 since 1.25 is clamped to 1.0.
robliao 2016/07/19 19:12:33 Remove this comment as well.
Bret 2016/07/19 20:17:37 Done.
394 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 394 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
395 gfx::Rect(0, 0, 1920, 1100), 395 gfx::Rect(0, 0, 1920, 1100),
396 L"primary", 396 L"primary",
397 1.0); 397 1.25);
398 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 398 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
399 } 399 }
400 400
401 HWND GetFakeHwnd() { 401 HWND GetFakeHwnd() {
402 return fake_hwnd_; 402 return fake_hwnd_;
403 } 403 }
404 404
405 private: 405 private:
406 HWND fake_hwnd_ = nullptr; 406 HWND fake_hwnd_ = nullptr;
407 407
408 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); 408 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x);
409 }; 409 };
410 410
411 } // namespace 411 } // namespace
412 412
413 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPPoints) { 413 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPPoints) {
414 gfx::Point origin(0, 0); 414 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0)));
415 gfx::Point middle(365, 694); 415 EXPECT_EQ(gfx::Point(292, 555),
416 gfx::Point lower_right(1919, 1199); 416 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694)));
417 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); 417 EXPECT_EQ(gfx::Point(1535, 959),
418 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); 418 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199)));
419 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right));
420 } 419 }
421 420
422 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenPoints) { 421 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenPoints) {
423 gfx::Point origin(0, 0); 422 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0)));
424 gfx::Point middle(365, 694); 423 EXPECT_EQ(gfx::Point(303, 577),
425 gfx::Point lower_right(1919, 1199); 424 ScreenWin::DIPToScreenPoint(gfx::Point(243, 462)));
426 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); 425 EXPECT_EQ(gfx::Point(1598, 998),
427 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); 426 ScreenWin::DIPToScreenPoint(gfx::Point(1279, 799)));
428 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right));
429 } 427 }
430 428
431 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPPoints) { 429 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPPoints) {
432 HWND hwnd = GetFakeHwnd(); 430 HWND hwnd = GetFakeHwnd();
433 gfx::Point origin(0, 0); 431 EXPECT_EQ(gfx::Point(0, 0),
434 gfx::Point middle(365, 694); 432 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0)));
435 gfx::Point lower_right(1919, 1199); 433 EXPECT_EQ(gfx::Point(292, 555),
436 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); 434 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694)));
437 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); 435 EXPECT_EQ(gfx::Point(1535, 959),
438 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); 436 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199)));
439 } 437 }
440 438
441 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientPoints) { 439 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientPoints) {
442 HWND hwnd = GetFakeHwnd(); 440 HWND hwnd = GetFakeHwnd();
443 gfx::Point origin(0, 0); 441 EXPECT_EQ(gfx::Point(0, 0),
444 gfx::Point middle(365, 694); 442 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0)));
445 gfx::Point lower_right(1919, 1199); 443 EXPECT_EQ(gfx::Point(303, 577),
446 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); 444 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(243, 462)));
447 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); 445 EXPECT_EQ(gfx::Point(1598, 998),
448 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); 446 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(1279, 799)));
449 } 447 }
450 448
451 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPRects) { 449 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPRects) {
452 HWND hwnd = GetFakeHwnd(); 450 HWND hwnd = GetFakeHwnd();
453 gfx::Rect origin(0, 0, 50, 100); 451 EXPECT_EQ(gfx::Rect(0, 0, 40, 80),
454 gfx::Rect middle(253, 495, 41, 52); 452 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100)));
455 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); 453 EXPECT_EQ(gfx::Rect(202, 396, 34, 43),
456 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); 454 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52)));
457 } 455 }
458 456
459 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenRects) { 457 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenRects) {
460 HWND hwnd = GetFakeHwnd(); 458 HWND hwnd = GetFakeHwnd();
461 gfx::Rect origin(0, 0, 50, 100); 459 EXPECT_EQ(gfx::Rect(0, 0, 43, 84),
462 gfx::Rect middle(253, 495, 41, 52); 460 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 34, 67)));
463 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); 461 EXPECT_EQ(gfx::Rect(210, 412, 35, 46),
464 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); 462 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(168, 330, 28, 36)));
465 } 463 }
466 464
467 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPRects) { 465 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPRects) {
468 HWND hwnd = GetFakeHwnd(); 466 HWND hwnd = GetFakeHwnd();
469 gfx::Rect origin(0, 0, 50, 100); 467 EXPECT_EQ(gfx::Rect(0, 0, 40, 80),
470 gfx::Rect middle(253, 495, 41, 52); 468 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100)));
471 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); 469 EXPECT_EQ(gfx::Rect(202, 396, 34, 43),
472 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); 470 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52)));
473 } 471 }
474 472
475 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientRects) { 473 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientRects) {
476 HWND hwnd = GetFakeHwnd(); 474 HWND hwnd = GetFakeHwnd();
477 gfx::Rect origin(0, 0, 50, 100); 475 EXPECT_EQ(gfx::Rect(0, 0, 43, 84),
478 gfx::Rect middle(253, 495, 41, 52); 476 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 34, 67)));
479 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); 477 EXPECT_EQ(gfx::Rect(210, 412, 35, 46),
480 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); 478 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(168, 330, 28, 36)));
481 } 479 }
482 480
483 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPSize) { 481 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPSize) {
484 HWND hwnd = GetFakeHwnd(); 482 EXPECT_EQ(gfx::Size(34, 105),
485 gfx::Size size(42, 131); 483 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131)));
486 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size));
487 } 484 }
488 485
489 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenSize) { 486 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenSize) {
490 HWND hwnd = GetFakeHwnd(); 487 EXPECT_EQ(gfx::Size(35, 110),
491 gfx::Size size(42, 131); 488 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(28, 88)));
492 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size));
493 } 489 }
494 490
495 TEST_F(ScreenWinTestSingleDisplay1_25x, GetSystemMetricsForHwnd) { 491 TEST_F(ScreenWinTestSingleDisplay1_25x, GetSystemMetricsForHwnd) {
496 HWND hwnd = GetFakeHwnd(); 492 HWND hwnd = GetFakeHwnd();
497 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(hwnd, 31)); 493 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(hwnd, 31));
498 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(hwnd, 42)); 494 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(hwnd, 42));
499 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(nullptr, 31)); 495 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(nullptr, 31));
500 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(nullptr, 42)); 496 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(nullptr, 42));
501 } 497 }
502 498
503 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { 499 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) {
504 std::vector<Display> displays = GetScreen()->GetAllDisplays(); 500 std::vector<Display> displays = GetScreen()->GetAllDisplays();
505 ASSERT_EQ(1u, displays.size()); 501 ASSERT_EQ(1u, displays.size());
506 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. 502 EXPECT_EQ(gfx::Rect(0, 0, 1536, 960), displays[0].bounds());
507 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); 503 EXPECT_EQ(gfx::Rect(0, 0, 1536, 880), displays[0].work_area());
508 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area());
509 } 504 }
510 505
511 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { 506 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) {
512 Screen* screen = GetScreen(); 507 Screen* screen = GetScreen();
513 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); 508 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd());
514 EXPECT_EQ(screen->GetAllDisplays()[0], 509 EXPECT_EQ(screen->GetAllDisplays()[0],
515 screen->GetDisplayNearestWindow(native_window)); 510 screen->GetDisplayNearestWindow(native_window));
516 } 511 }
517 512
518 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { 513 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) {
(...skipping 11 matching lines...) Expand all
530 EXPECT_EQ(display, 525 EXPECT_EQ(display,
531 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); 526 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100)));
532 } 527 }
533 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { 528 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) {
534 Screen* screen = GetScreen(); 529 Screen* screen = GetScreen();
535 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 530 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
536 } 531 }
537 532
538 namespace { 533 namespace {
539 534
540 // Single Display of 1.25 Device Scale Factor. 535 // Single Display of 1.5 Device Scale Factor.
541 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { 536 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest {
542 public: 537 public:
543 ScreenWinTestSingleDisplay1_5x() = default; 538 ScreenWinTestSingleDisplay1_5x() = default;
544 539
545 void SetUpScreen(TestScreenWinInitializer* initializer) override { 540 void SetUpScreen(TestScreenWinInitializer* initializer) override {
546 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 541 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
547 gfx::Rect(0, 0, 1920, 1100), 542 gfx::Rect(0, 0, 1920, 1100),
548 L"primary", 543 L"primary",
549 1.5); 544 1.5);
550 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 545 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
(...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3417 } 3412 }
3418 3413
3419 TEST_F(ScreenWinUninitializedForced2x, GetSystemMetricsForHwnd) { 3414 TEST_F(ScreenWinUninitializedForced2x, GetSystemMetricsForHwnd) {
3420 // GetSystemMetricsForHwnd falls back to the system's GetSystemMetrics, so 3415 // GetSystemMetricsForHwnd falls back to the system's GetSystemMetrics, so
3421 // this test is to make sure we don't crash. 3416 // this test is to make sure we don't crash.
3422 ScreenWin::GetSystemMetricsForHwnd(nullptr, SM_CXSIZEFRAME); 3417 ScreenWin::GetSystemMetricsForHwnd(nullptr, SM_CXSIZEFRAME);
3423 } 3418 }
3424 3419
3425 } // namespace win 3420 } // namespace win
3426 } // namespace display 3421 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/dpi.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698