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/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 <unordered_map> | 11 #include <unordered_map> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
19 #include "ui/display/display_switches.h" | 19 #include "ui/display/display_switches.h" |
20 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
21 #include "ui/display/test/display_test_util.h" | 21 #include "ui/display/test/display_test_util.h" |
22 #include "ui/display/win/display_info.h" | 22 #include "ui/display/win/display_info.h" |
23 #include "ui/display/win/dpi.h" | |
24 #include "ui/display/win/screen_win_display.h" | 23 #include "ui/display/win/screen_win_display.h" |
25 #include "ui/display/win/test/screen_util_win.h" | 24 #include "ui/display/win/test/screen_util_win.h" |
| 25 #include "ui/gfx/geometry/point.h" |
26 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 27 #include "ui/gfx/geometry/size.h" |
27 | 28 |
28 namespace display { | 29 namespace display { |
29 namespace win { | 30 namespace win { |
30 namespace { | 31 namespace { |
31 | 32 |
32 class TestScreenWin : public ScreenWin { | 33 class TestScreenWin : public ScreenWin { |
33 public: | 34 public: |
34 TestScreenWin(const std::vector<DisplayInfo>& display_infos, | 35 TestScreenWin(const std::vector<DisplayInfo>& display_infos, |
35 const std::vector<MONITORINFOEX>& monitor_infos, | 36 const std::vector<MONITORINFOEX>& monitor_infos, |
36 const std::unordered_map<HWND, gfx::Rect>& hwnd_map) | 37 const std::unordered_map<HWND, gfx::Rect>& hwnd_map) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 188 |
188 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager); | 189 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager); |
189 }; | 190 }; |
190 | 191 |
191 class ScreenWinTest : public testing::Test { | 192 class ScreenWinTest : public testing::Test { |
192 protected: | 193 protected: |
193 ScreenWinTest() = default; | 194 ScreenWinTest() = default; |
194 | 195 |
195 void SetUp() override { | 196 void SetUp() override { |
196 testing::Test::SetUp(); | 197 testing::Test::SetUp(); |
197 SetDefaultDeviceScaleFactor(1.0); | |
198 screen_win_initializer_.reset(new TestScreenWinManager()); | 198 screen_win_initializer_.reset(new TestScreenWinManager()); |
199 SetUpScreen(screen_win_initializer_.get()); | 199 SetUpScreen(screen_win_initializer_.get()); |
200 screen_win_initializer_->InitializeScreenWin(); | 200 screen_win_initializer_->InitializeScreenWin(); |
201 } | 201 } |
202 | 202 |
203 void TearDown() override { | 203 void TearDown() override { |
204 screen_win_initializer_.reset(); | 204 screen_win_initializer_.reset(); |
205 SetDefaultDeviceScaleFactor(1.0); | |
206 testing::Test::TearDown(); | 205 testing::Test::TearDown(); |
207 } | 206 } |
208 | 207 |
209 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0; | 208 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0; |
210 | 209 |
211 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const { | 210 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const { |
212 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin(); | 211 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin(); |
213 return screen_win->GetNativeWindowFromHWND(hwnd); | 212 return screen_win->GetNativeWindowFromHWND(hwnd); |
214 } | 213 } |
215 | 214 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 371 } |
373 | 372 |
374 namespace { | 373 namespace { |
375 | 374 |
376 // Single Display of 1.25 Device Scale Factor. | 375 // Single Display of 1.25 Device Scale Factor. |
377 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { | 376 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { |
378 public: | 377 public: |
379 ScreenWinTestSingleDisplay1_25x() = default; | 378 ScreenWinTestSingleDisplay1_25x() = default; |
380 | 379 |
381 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 380 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
382 SetDefaultDeviceScaleFactor(1.25); | 381 // Add Monitor of Scale Factor 1.0 since 1.25 is clamped to 1.0. |
383 // Add Monitor of Scale Factor 1.0 since display::GetDPIScale performs the | |
384 // clamping and not ScreenWin. | |
385 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 382 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
386 gfx::Rect(0, 0, 1920, 1100), | 383 gfx::Rect(0, 0, 1920, 1100), |
387 L"primary", | 384 L"primary", |
388 1.0); | 385 1.0); |
389 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 386 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
390 } | 387 } |
391 | 388 |
392 HWND GetFakeHwnd() { | 389 HWND GetFakeHwnd() { |
393 return fake_hwnd_; | 390 return fake_hwnd_; |
394 } | 391 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 516 } |
520 | 517 |
521 namespace { | 518 namespace { |
522 | 519 |
523 // Single Display of 1.25 Device Scale Factor. | 520 // Single Display of 1.25 Device Scale Factor. |
524 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { | 521 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { |
525 public: | 522 public: |
526 ScreenWinTestSingleDisplay1_5x() = default; | 523 ScreenWinTestSingleDisplay1_5x() = default; |
527 | 524 |
528 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 525 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
529 SetDefaultDeviceScaleFactor(1.5); | |
530 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 526 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
531 gfx::Rect(0, 0, 1920, 1100), | 527 gfx::Rect(0, 0, 1920, 1100), |
532 L"primary", | 528 L"primary", |
533 1.5); | 529 1.5); |
534 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 530 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
535 } | 531 } |
536 | 532 |
537 HWND GetFakeHwnd() { | 533 HWND GetFakeHwnd() { |
538 return fake_hwnd_; | 534 return fake_hwnd_; |
539 } | 535 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 EXPECT_EQ(gfx::Point(364, 693), | 575 EXPECT_EQ(gfx::Point(364, 693), |
580 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(243, 462))); | 576 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(243, 462))); |
581 EXPECT_EQ(gfx::Point(1918, 1198), | 577 EXPECT_EQ(gfx::Point(1918, 1198), |
582 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(1279, 799))); | 578 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(1279, 799))); |
583 } | 579 } |
584 | 580 |
585 TEST_F(ScreenWinTestSingleDisplay1_5x, ScreenToDIPRects) { | 581 TEST_F(ScreenWinTestSingleDisplay1_5x, ScreenToDIPRects) { |
586 HWND hwnd = GetFakeHwnd(); | 582 HWND hwnd = GetFakeHwnd(); |
587 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), | 583 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
588 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); | 584 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
589 EXPECT_EQ(gfx::Rect(168, 330, 28, 35), | 585 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
590 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); | 586 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
591 } | 587 } |
592 | 588 |
593 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToScreenRects) { | 589 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToScreenRects) { |
594 HWND hwnd = GetFakeHwnd(); | 590 HWND hwnd = GetFakeHwnd(); |
595 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), | 591 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
596 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 34, 67))); | 592 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
597 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), | 593 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
598 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(168, 330, 28, 36))); | 594 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
599 } | 595 } |
600 | 596 |
601 TEST_F(ScreenWinTestSingleDisplay1_5x, ClientToDIPRects) { | 597 TEST_F(ScreenWinTestSingleDisplay1_5x, ClientToDIPRects) { |
602 HWND hwnd = GetFakeHwnd(); | 598 HWND hwnd = GetFakeHwnd(); |
603 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), | 599 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
604 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); | 600 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
605 EXPECT_EQ(gfx::Rect(168, 330, 28, 35), | 601 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
606 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); | 602 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
607 } | 603 } |
608 | 604 |
609 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToClientRects) { | 605 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToClientRects) { |
610 HWND hwnd = GetFakeHwnd(); | 606 HWND hwnd = GetFakeHwnd(); |
611 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), | 607 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
612 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 34, 67))); | 608 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
613 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), | 609 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
614 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(168, 330, 28, 36))); | 610 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
615 } | 611 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 } | 655 } |
660 | 656 |
661 namespace { | 657 namespace { |
662 | 658 |
663 // Single Display of 2.0 Device Scale Factor. | 659 // Single Display of 2.0 Device Scale Factor. |
664 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { | 660 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
665 public: | 661 public: |
666 ScreenWinTestSingleDisplay2x() = default; | 662 ScreenWinTestSingleDisplay2x() = default; |
667 | 663 |
668 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 664 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
669 SetDefaultDeviceScaleFactor(2.0); | |
670 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 665 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
671 gfx::Rect(0, 0, 1920, 1100), | 666 gfx::Rect(0, 0, 1920, 1100), |
672 L"primary", | 667 L"primary", |
673 2.0); | 668 2.0); |
674 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 669 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
675 } | 670 } |
676 | 671 |
677 HWND GetFakeHwnd() { | 672 HWND GetFakeHwnd() { |
678 return fake_hwnd_; | 673 return fake_hwnd_; |
679 } | 674 } |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 } | 1029 } |
1035 | 1030 |
1036 namespace { | 1031 namespace { |
1037 | 1032 |
1038 // Two Displays of 2.0 Device Scale Factor. | 1033 // Two Displays of 2.0 Device Scale Factor. |
1039 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { | 1034 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
1040 public: | 1035 public: |
1041 ScreenWinTestTwoDisplays2x() = default; | 1036 ScreenWinTestTwoDisplays2x() = default; |
1042 | 1037 |
1043 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 1038 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
1044 SetDefaultDeviceScaleFactor(2.0); | |
1045 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 1039 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
1046 gfx::Rect(0, 0, 1920, 1100), | 1040 gfx::Rect(0, 0, 1920, 1100), |
1047 L"primary", | 1041 L"primary", |
1048 2.0); | 1042 2.0); |
1049 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | 1043 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
1050 gfx::Rect(1920, 0, 800, 600), | 1044 gfx::Rect(1920, 0, 800, 600), |
1051 L"secondary", | 1045 L"secondary", |
1052 2.0); | 1046 2.0); |
1053 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 1047 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
1054 fake_hwnd_right_ = | 1048 fake_hwnd_right_ = |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 // | 3 | | 1671 // | 3 | |
1678 // | | | 1672 // | | |
1679 // +--+--+ | 1673 // +--+--+ |
1680 // |4 | | 1674 // |4 | |
1681 // +--+ | 1675 // +--+ |
1682 class ScreenWinTestManyDisplays2x : public ScreenWinTest { | 1676 class ScreenWinTestManyDisplays2x : public ScreenWinTest { |
1683 public: | 1677 public: |
1684 ScreenWinTestManyDisplays2x() = default; | 1678 ScreenWinTestManyDisplays2x() = default; |
1685 | 1679 |
1686 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 1680 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
1687 SetDefaultDeviceScaleFactor(2.0); | |
1688 initializer->AddMonitor(gfx::Rect(0, 0, 640, 480), | 1681 initializer->AddMonitor(gfx::Rect(0, 0, 640, 480), |
1689 gfx::Rect(0, 0, 640, 380), | 1682 gfx::Rect(0, 0, 640, 380), |
1690 L"primary0", | 1683 L"primary0", |
1691 2.0); | 1684 2.0); |
1692 fake_hwnds_.push_back( | 1685 fake_hwnds_.push_back( |
1693 initializer->CreateFakeHwnd(gfx::Rect(0, 0, 640, 380))); | 1686 initializer->CreateFakeHwnd(gfx::Rect(0, 0, 640, 380))); |
1694 initializer->AddMonitor(gfx::Rect(640, 0, 1024, 768), | 1687 initializer->AddMonitor(gfx::Rect(640, 0, 1024, 768), |
1695 gfx::Rect(640, 0, 1024, 768), | 1688 gfx::Rect(640, 0, 1024, 768), |
1696 L"monitor1", | 1689 L"monitor1", |
1697 2.0); | 1690 2.0); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 gfx::Rect(932, 584, 8, 10))); | 1924 gfx::Rect(932, 584, 8, 10))); |
1932 EXPECT_EQ(gfx::Rect(1954, 1224, 26, 30), | 1925 EXPECT_EQ(gfx::Rect(1954, 1224, 26, 30), |
1933 ScreenWin::DIPToScreenRect(GetFakeHwnd(4), | 1926 ScreenWin::DIPToScreenRect(GetFakeHwnd(4), |
1934 gfx::Rect(977, 612, 13, 15))); | 1927 gfx::Rect(977, 612, 13, 15))); |
1935 } | 1928 } |
1936 | 1929 |
1937 TEST_F(ScreenWinTestManyDisplays2x, ClientToDIPRects) { | 1930 TEST_F(ScreenWinTestManyDisplays2x, ClientToDIPRects) { |
1938 gfx::Rect client_screen_origin(0, 0, 50, 100); | 1931 gfx::Rect client_screen_origin(0, 0, 50, 100); |
1939 gfx::Rect client_dip_origin(0, 0, 25, 50); | 1932 gfx::Rect client_dip_origin(0, 0, 25, 50); |
1940 gfx::Rect client_screen_middle(253, 495, 41, 52); | 1933 gfx::Rect client_screen_middle(253, 495, 41, 52); |
1941 gfx::Rect client_dip_middle(126, 247, 21, 26); | 1934 gfx::Rect client_dip_middle(126, 247, 21, 27); |
1942 ASSERT_EQ(5, GetScreen()->GetNumDisplays()); | 1935 ASSERT_EQ(5, GetScreen()->GetNumDisplays()); |
1943 for (size_t i = 0; i < 5u; ++i) { | 1936 for (size_t i = 0; i < 5u; ++i) { |
1944 SCOPED_TRACE(base::StringPrintf("i=%zu", i)); | 1937 SCOPED_TRACE(base::StringPrintf("i=%zu", i)); |
1945 EXPECT_EQ(client_dip_origin, | 1938 EXPECT_EQ(client_dip_origin, |
1946 ScreenWin::ClientToDIPRect(GetFakeHwnd(i), client_screen_origin)); | 1939 ScreenWin::ClientToDIPRect(GetFakeHwnd(i), client_screen_origin)); |
1947 EXPECT_EQ(client_dip_middle, | 1940 EXPECT_EQ(client_dip_middle, |
1948 ScreenWin::ClientToDIPRect(GetFakeHwnd(i), client_screen_middle)); | 1941 ScreenWin::ClientToDIPRect(GetFakeHwnd(i), client_screen_middle)); |
1949 } | 1942 } |
1950 } | 1943 } |
1951 | 1944 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 screen->GetDisplayMatching(gfx::Rect(1963, 1267, 100, 100))); | 2068 screen->GetDisplayMatching(gfx::Rect(1963, 1267, 100, 100))); |
2076 } | 2069 } |
2077 | 2070 |
2078 TEST_F(ScreenWinTestManyDisplays2x, GetPrimaryDisplay) { | 2071 TEST_F(ScreenWinTestManyDisplays2x, GetPrimaryDisplay) { |
2079 Screen* screen = GetScreen(); | 2072 Screen* screen = GetScreen(); |
2080 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 2073 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
2081 } | 2074 } |
2082 | 2075 |
2083 namespace { | 2076 namespace { |
2084 | 2077 |
| 2078 // Two Displays of 1.0 (Left) and 2.0 (Right) Device Scale Factor. |
| 2079 class ScreenWinTestTwoDisplays1x2x : public ScreenWinTest { |
| 2080 public: |
| 2081 ScreenWinTestTwoDisplays1x2x() = default; |
| 2082 |
| 2083 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 2084 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 2085 gfx::Rect(0, 0, 1920, 1100), |
| 2086 L"primary", |
| 2087 1.0); |
| 2088 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 2089 gfx::Rect(1920, 0, 800, 600), |
| 2090 L"secondary", |
| 2091 2.0); |
| 2092 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 2093 fake_hwnd_right_ = |
| 2094 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 2095 } |
| 2096 |
| 2097 HWND GetLeftFakeHwnd() { |
| 2098 return fake_hwnd_left_; |
| 2099 } |
| 2100 |
| 2101 HWND GetRightFakeHwnd() { |
| 2102 return fake_hwnd_right_; |
| 2103 } |
| 2104 |
| 2105 private: |
| 2106 HWND fake_hwnd_left_ = nullptr; |
| 2107 HWND fake_hwnd_right_ = nullptr; |
| 2108 |
| 2109 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x2x); |
| 2110 }; |
| 2111 |
| 2112 } // namespace |
| 2113 |
| 2114 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPPoints) { |
| 2115 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 2116 EXPECT_EQ(gfx::Point(365, 694), |
| 2117 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 2118 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2119 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 2120 |
| 2121 EXPECT_EQ(gfx::Point(1920, 0), |
| 2122 ScreenWin::ScreenToDIPPoint(gfx::Point(1920, 0))); |
| 2123 EXPECT_EQ(gfx::Point(2152, 175), |
| 2124 ScreenWin::ScreenToDIPPoint(gfx::Point(2384, 351))); |
| 2125 EXPECT_EQ(gfx::Point(2319, 299), |
| 2126 ScreenWin::ScreenToDIPPoint(gfx::Point(2719, 599))); |
| 2127 } |
| 2128 |
| 2129 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenPoints) { |
| 2130 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 2131 EXPECT_EQ(gfx::Point(365, 694), |
| 2132 ScreenWin::DIPToScreenPoint(gfx::Point(365, 694))); |
| 2133 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2134 ScreenWin::DIPToScreenPoint(gfx::Point(1919, 1199))); |
| 2135 |
| 2136 EXPECT_EQ(gfx::Point(1920, 0), |
| 2137 ScreenWin::DIPToScreenPoint(gfx::Point(1920, 0))); |
| 2138 EXPECT_EQ(gfx::Point(2384, 350), |
| 2139 ScreenWin::DIPToScreenPoint(gfx::Point(2152, 175))); |
| 2140 EXPECT_EQ(gfx::Point(2718, 598), |
| 2141 ScreenWin::DIPToScreenPoint(gfx::Point(2319, 299))); |
| 2142 } |
| 2143 |
| 2144 TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPPoints) { |
| 2145 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2146 EXPECT_EQ(gfx::Point(0, 0), |
| 2147 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(0, 0))); |
| 2148 EXPECT_EQ(gfx::Point(365, 694), |
| 2149 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(365, 694))); |
| 2150 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2151 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(1919, 1199))); |
| 2152 |
| 2153 HWND right_hwnd = GetRightFakeHwnd(); |
| 2154 EXPECT_EQ(gfx::Point(0, 0), |
| 2155 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(0, 0))); |
| 2156 EXPECT_EQ(gfx::Point(182, 347), |
| 2157 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(365, 694))); |
| 2158 EXPECT_EQ(gfx::Point(959, 599), |
| 2159 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(1919, 1199))); |
| 2160 } |
| 2161 |
| 2162 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientPoints) { |
| 2163 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2164 EXPECT_EQ(gfx::Point(0, 0), |
| 2165 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(0, 0))); |
| 2166 EXPECT_EQ(gfx::Point(365, 694), |
| 2167 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(365, 694))); |
| 2168 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2169 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(1919, 1199))); |
| 2170 |
| 2171 HWND right_hwnd = GetRightFakeHwnd(); |
| 2172 EXPECT_EQ(gfx::Point(0, 0), |
| 2173 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(0, 0))); |
| 2174 EXPECT_EQ(gfx::Point(364, 694), |
| 2175 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(182, 347))); |
| 2176 EXPECT_EQ(gfx::Point(1918, 1198), |
| 2177 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(959, 599))); |
| 2178 } |
| 2179 |
| 2180 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPRects) { |
| 2181 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2182 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2183 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2184 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2185 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2186 |
| 2187 HWND right_hwnd = GetRightFakeHwnd(); |
| 2188 EXPECT_EQ(gfx::Rect(1920, 0, 100, 150), |
| 2189 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2190 gfx::Rect(1920, 0, 200, 300))); |
| 2191 EXPECT_EQ(gfx::Rect(1960, 248, 50, 100), |
| 2192 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2193 gfx::Rect(2000, 496, 100, 200))); |
| 2194 } |
| 2195 |
| 2196 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenRects) { |
| 2197 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2198 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2199 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2200 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 2201 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 2202 |
| 2203 HWND right_hwnd = GetRightFakeHwnd(); |
| 2204 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 2205 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2206 gfx::Rect(1920, 0, 100, 150))); |
| 2207 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 2208 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2209 gfx::Rect(1960, 248, 50, 100))); |
| 2210 } |
| 2211 |
| 2212 TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPRects) { |
| 2213 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2214 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2215 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2216 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2217 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2218 |
| 2219 HWND right_hwnd = GetRightFakeHwnd(); |
| 2220 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 2221 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2222 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 2223 ScreenWin::ClientToDIPRect(right_hwnd, |
| 2224 gfx::Rect(253, 496, 41, 52))); |
| 2225 } |
| 2226 |
| 2227 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientRects) { |
| 2228 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2229 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2230 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2231 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 2232 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 2233 |
| 2234 HWND right_hwnd = GetRightFakeHwnd(); |
| 2235 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2236 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 2237 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 2238 ScreenWin::DIPToClientRect(right_hwnd, |
| 2239 gfx::Rect(126, 248, 21, 26))); |
| 2240 } |
| 2241 |
| 2242 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPSize) { |
| 2243 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2244 EXPECT_EQ(gfx::Size(42, 131), |
| 2245 ScreenWin::ScreenToDIPSize(left_hwnd, gfx::Size(42, 131))); |
| 2246 |
| 2247 HWND right_hwnd = GetRightFakeHwnd(); |
| 2248 EXPECT_EQ(gfx::Size(21, 66), |
| 2249 ScreenWin::ScreenToDIPSize(right_hwnd, gfx::Size(42, 131))); |
| 2250 } |
| 2251 |
| 2252 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenSize) { |
| 2253 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2254 EXPECT_EQ(gfx::Size(21, 66), |
| 2255 ScreenWin::DIPToScreenSize(left_hwnd, gfx::Size(21, 66))); |
| 2256 |
| 2257 HWND right_hwnd = GetRightFakeHwnd(); |
| 2258 EXPECT_EQ(gfx::Size(42, 132), |
| 2259 ScreenWin::DIPToScreenSize(right_hwnd, gfx::Size(21, 66))); |
| 2260 } |
| 2261 |
| 2262 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplays) { |
| 2263 std::vector<Display> displays = GetScreen()->GetAllDisplays(); |
| 2264 ASSERT_EQ(2u, displays.size()); |
| 2265 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 2266 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 2267 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].bounds()); |
| 2268 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].work_area()); |
| 2269 } |
| 2270 |
| 2271 TEST_F(ScreenWinTestTwoDisplays1x2x, GetNumDisplays) { |
| 2272 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| 2273 } |
| 2274 |
| 2275 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindowPrimaryDisplay) { |
| 2276 Screen* screen = GetScreen(); |
| 2277 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 2278 screen->GetDisplayNearestWindow(nullptr)); |
| 2279 } |
| 2280 |
| 2281 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindow) { |
| 2282 Screen* screen = GetScreen(); |
| 2283 const Display left_display = screen->GetAllDisplays()[0]; |
| 2284 const Display right_display = screen->GetAllDisplays()[1]; |
| 2285 |
| 2286 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 2287 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 2288 |
| 2289 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 2290 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 2291 } |
| 2292 |
| 2293 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestPoint) { |
| 2294 Screen* screen = GetScreen(); |
| 2295 const Display left_display = screen->GetAllDisplays()[0]; |
| 2296 const Display right_display = screen->GetAllDisplays()[1]; |
| 2297 |
| 2298 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 2299 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); |
| 2300 EXPECT_EQ(left_display, |
| 2301 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); |
| 2302 |
| 2303 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); |
| 2304 EXPECT_EQ(right_display, |
| 2305 screen->GetDisplayNearestPoint(gfx::Point(2000, 200))); |
| 2306 EXPECT_EQ(right_display, |
| 2307 screen->GetDisplayNearestPoint(gfx::Point(2319, 299))); |
| 2308 } |
| 2309 |
| 2310 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayMatching) { |
| 2311 Screen* screen = GetScreen(); |
| 2312 const Display left_display = screen->GetAllDisplays()[0]; |
| 2313 const Display right_display = screen->GetAllDisplays()[1]; |
| 2314 |
| 2315 EXPECT_EQ(left_display, |
| 2316 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 2317 EXPECT_EQ(left_display, |
| 2318 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 2319 |
| 2320 EXPECT_EQ(right_display, |
| 2321 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| 2322 EXPECT_EQ(right_display, |
| 2323 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 2324 } |
| 2325 |
| 2326 TEST_F(ScreenWinTestTwoDisplays1x2x, GetPrimaryDisplay) { |
| 2327 Screen* screen = GetScreen(); |
| 2328 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 2329 } |
| 2330 |
| 2331 namespace { |
| 2332 |
| 2333 // Two Displays of 1.5 (Left) and 1.0 (Right) Device Scale Factor. |
| 2334 class ScreenWinTestTwoDisplays1_5x1x : public ScreenWinTest { |
| 2335 public: |
| 2336 ScreenWinTestTwoDisplays1_5x1x() = default; |
| 2337 |
| 2338 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 2339 initializer->AddMonitor(gfx::Rect(0, 0, 800, 600), |
| 2340 gfx::Rect(0, 0, 800, 550), |
| 2341 L"primary", |
| 2342 1.5); |
| 2343 initializer->AddMonitor(gfx::Rect(800, 120, 640, 480), |
| 2344 gfx::Rect(800, 120, 640, 480), |
| 2345 L"secondary", |
| 2346 1.0); |
| 2347 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 800, 550)); |
| 2348 fake_hwnd_right_ = |
| 2349 initializer->CreateFakeHwnd(gfx::Rect(800, 120, 640, 480)); |
| 2350 } |
| 2351 |
| 2352 HWND GetLeftFakeHwnd() { |
| 2353 return fake_hwnd_left_; |
| 2354 } |
| 2355 |
| 2356 HWND GetRightFakeHwnd() { |
| 2357 return fake_hwnd_right_; |
| 2358 } |
| 2359 |
| 2360 private: |
| 2361 HWND fake_hwnd_left_ = nullptr; |
| 2362 HWND fake_hwnd_right_ = nullptr; |
| 2363 |
| 2364 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1_5x1x); |
| 2365 }; |
| 2366 |
| 2367 } // namespace |
| 2368 |
| 2369 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ScreenToDIPPoints) { |
| 2370 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 2371 EXPECT_EQ(gfx::Point(243, 301), |
| 2372 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 452))); |
| 2373 EXPECT_EQ(gfx::Point(532, 399), |
| 2374 ScreenWin::ScreenToDIPPoint(gfx::Point(799, 599))); |
| 2375 |
| 2376 EXPECT_EQ(gfx::Point(534, -80), |
| 2377 ScreenWin::ScreenToDIPPoint(gfx::Point(800, 120))); |
| 2378 EXPECT_EQ(gfx::Point(860, 151), |
| 2379 ScreenWin::ScreenToDIPPoint(gfx::Point(1126, 351))); |
| 2380 EXPECT_EQ(gfx::Point(1173, 399), |
| 2381 ScreenWin::ScreenToDIPPoint(gfx::Point(1439, 599))); |
| 2382 } |
| 2383 |
| 2384 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToScreenPoints) { |
| 2385 EXPECT_EQ(gfx::Point(0, 0), |
| 2386 ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 2387 EXPECT_EQ(gfx::Point(364, 451), |
| 2388 ScreenWin::DIPToScreenPoint(gfx::Point(243, 301))); |
| 2389 EXPECT_EQ(gfx::Point(798, 598), |
| 2390 ScreenWin::DIPToScreenPoint(gfx::Point(532, 399))); |
| 2391 |
| 2392 EXPECT_EQ(gfx::Point(800, 120), |
| 2393 ScreenWin::DIPToScreenPoint(gfx::Point(534, -80))); |
| 2394 EXPECT_EQ(gfx::Point(1126, 351), |
| 2395 ScreenWin::DIPToScreenPoint(gfx::Point(860, 151))); |
| 2396 EXPECT_EQ(gfx::Point(1439, 599), |
| 2397 ScreenWin::DIPToScreenPoint(gfx::Point(1173, 399))); |
| 2398 } |
| 2399 |
| 2400 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ClientToDIPPoints) { |
| 2401 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2402 EXPECT_EQ(gfx::Point(0, 0), |
| 2403 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(0, 0))); |
| 2404 EXPECT_EQ(gfx::Point(243, 462), |
| 2405 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(365, 694))); |
| 2406 EXPECT_EQ(gfx::Point(1279, 799), |
| 2407 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(1919, 1199))); |
| 2408 |
| 2409 HWND right_hwnd = GetRightFakeHwnd(); |
| 2410 EXPECT_EQ(gfx::Point(0, 0), |
| 2411 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(0, 0))); |
| 2412 EXPECT_EQ(gfx::Point(365, 694), |
| 2413 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(365, 694))); |
| 2414 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2415 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(1919, 1199))); |
| 2416 } |
| 2417 |
| 2418 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToClientPoints) { |
| 2419 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2420 EXPECT_EQ(gfx::Point(0, 0), |
| 2421 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(0, 0))); |
| 2422 EXPECT_EQ(gfx::Point(364, 693), |
| 2423 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(243, 462))); |
| 2424 EXPECT_EQ(gfx::Point(1918, 1198), |
| 2425 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(1279, 799))); |
| 2426 |
| 2427 HWND right_hwnd = GetRightFakeHwnd(); |
| 2428 EXPECT_EQ(gfx::Point(0, 0), |
| 2429 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(0, 0))); |
| 2430 EXPECT_EQ(gfx::Point(365, 694), |
| 2431 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(365, 694))); |
| 2432 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2433 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(1919, 1199))); |
| 2434 } |
| 2435 |
| 2436 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ScreenToDIPRects) { |
| 2437 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2438 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 2439 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2440 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 2441 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2442 |
| 2443 HWND right_hwnd = GetRightFakeHwnd(); |
| 2444 EXPECT_EQ(gfx::Rect(534, -80, 200, 300), |
| 2445 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2446 gfx::Rect(800, 120, 200, 300))); |
| 2447 EXPECT_EQ(gfx::Rect(987, 296, 100, 200), |
| 2448 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2449 gfx::Rect(1253, 496, 100, 200))); |
| 2450 } |
| 2451 |
| 2452 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToScreenRects) { |
| 2453 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2454 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 2455 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 34, 67))); |
| 2456 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 2457 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(168, 330, 28, 36))); |
| 2458 |
| 2459 HWND right_hwnd = GetRightFakeHwnd(); |
| 2460 EXPECT_EQ(gfx::Rect(800, 120, 200, 300), |
| 2461 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2462 gfx::Rect(534, -80, 200, 300))); |
| 2463 EXPECT_EQ(gfx::Rect(1253, 496, 100, 200), |
| 2464 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2465 gfx::Rect(987, 296, 100, 200))); |
| 2466 } |
| 2467 |
| 2468 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ClientToDIPRects) { |
| 2469 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2470 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 2471 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2472 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 2473 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2474 |
| 2475 HWND right_hwnd = GetRightFakeHwnd(); |
| 2476 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2477 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2478 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2479 ScreenWin::ClientToDIPRect(right_hwnd, |
| 2480 gfx::Rect(253, 496, 41, 52))); |
| 2481 } |
| 2482 |
| 2483 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToClientRects) { |
| 2484 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2485 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 2486 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 34, 67))); |
| 2487 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 2488 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(168, 330, 28, 36))); |
| 2489 |
| 2490 HWND right_hwnd = GetRightFakeHwnd(); |
| 2491 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2492 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2493 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2494 ScreenWin::DIPToClientRect(right_hwnd, |
| 2495 gfx::Rect(253, 496, 41, 52))); |
| 2496 } |
| 2497 |
| 2498 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ScreenToDIPSize) { |
| 2499 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2500 EXPECT_EQ(gfx::Size(28, 88), |
| 2501 ScreenWin::ScreenToDIPSize(left_hwnd, gfx::Size(42, 131))); |
| 2502 |
| 2503 HWND right_hwnd = GetRightFakeHwnd(); |
| 2504 EXPECT_EQ(gfx::Size(42, 131), |
| 2505 ScreenWin::ScreenToDIPSize(right_hwnd, gfx::Size(42, 131))); |
| 2506 } |
| 2507 |
| 2508 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToScreenSize) { |
| 2509 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2510 EXPECT_EQ(gfx::Size(42, 131), |
| 2511 ScreenWin::DIPToScreenSize(left_hwnd, gfx::Size(28, 87))); |
| 2512 |
| 2513 HWND right_hwnd = GetRightFakeHwnd(); |
| 2514 EXPECT_EQ(gfx::Size(42, 131), |
| 2515 ScreenWin::DIPToScreenSize(right_hwnd, gfx::Size(42, 131))); |
| 2516 } |
| 2517 |
| 2518 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplays) { |
| 2519 std::vector<Display> displays = GetScreen()->GetAllDisplays(); |
| 2520 ASSERT_EQ(2u, displays.size()); |
| 2521 EXPECT_EQ(gfx::Rect(0, 0, 534, 400), displays[0].bounds()); |
| 2522 EXPECT_EQ(gfx::Rect(0, 0, 534, 367), displays[0].work_area()); |
| 2523 EXPECT_EQ(gfx::Rect(534, -80, 640, 480), displays[1].bounds()); |
| 2524 EXPECT_EQ(gfx::Rect(534, -80, 640, 480), displays[1].work_area()); |
| 2525 } |
| 2526 |
| 2527 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestWindowPrimaryDisplay) { |
| 2528 Screen* screen = GetScreen(); |
| 2529 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 2530 screen->GetDisplayNearestWindow(nullptr)); |
| 2531 } |
| 2532 |
| 2533 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestWindow) { |
| 2534 Screen* screen = GetScreen(); |
| 2535 const Display left_display = screen->GetAllDisplays()[0]; |
| 2536 const Display right_display = screen->GetAllDisplays()[1]; |
| 2537 |
| 2538 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 2539 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 2540 |
| 2541 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 2542 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 2543 } |
| 2544 |
| 2545 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestPoint) { |
| 2546 Screen* screen = GetScreen(); |
| 2547 const Display left_display = screen->GetAllDisplays()[0]; |
| 2548 const Display right_display = screen->GetAllDisplays()[1]; |
| 2549 |
| 2550 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 2551 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 253))); |
| 2552 EXPECT_EQ(left_display, |
| 2553 screen->GetDisplayNearestPoint(gfx::Point(533, 399))); |
| 2554 |
| 2555 EXPECT_EQ(right_display, |
| 2556 screen->GetDisplayNearestPoint(gfx::Point(534, -80))); |
| 2557 EXPECT_EQ(right_display, |
| 2558 screen->GetDisplayNearestPoint(gfx::Point(1000, 200))); |
| 2559 EXPECT_EQ(right_display, |
| 2560 screen->GetDisplayNearestPoint(gfx::Point(1173, 399))); |
| 2561 } |
| 2562 |
| 2563 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayMatching) { |
| 2564 Screen* screen = GetScreen(); |
| 2565 const Display left_display = screen->GetAllDisplays()[0]; |
| 2566 const Display right_display = screen->GetAllDisplays()[1]; |
| 2567 |
| 2568 EXPECT_EQ(left_display, |
| 2569 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 2570 EXPECT_EQ(left_display, |
| 2571 screen->GetDisplayMatching(gfx::Rect(699, 499, 100, 100))); |
| 2572 |
| 2573 EXPECT_EQ(right_display, |
| 2574 screen->GetDisplayMatching(gfx::Rect(800, 120, 100, 100))); |
| 2575 EXPECT_EQ(right_display, |
| 2576 screen->GetDisplayMatching(gfx::Rect(1339, 499, 100, 100))); |
| 2577 } |
| 2578 |
| 2579 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetPrimaryDisplay) { |
| 2580 Screen* screen = GetScreen(); |
| 2581 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 2582 } |
| 2583 |
| 2584 namespace { |
| 2585 |
| 2586 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor. |
| 2587 class ScreenWinTestTwoDisplays2x1x : public ScreenWinTest { |
| 2588 public: |
| 2589 ScreenWinTestTwoDisplays2x1x() = default; |
| 2590 |
| 2591 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 2592 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 2593 gfx::Rect(0, 0, 1920, 1100), |
| 2594 L"primary", |
| 2595 2.0); |
| 2596 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 2597 gfx::Rect(1920, 0, 800, 600), |
| 2598 L"secondary", |
| 2599 1.0); |
| 2600 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 2601 fake_hwnd_right_ = |
| 2602 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 2603 } |
| 2604 |
| 2605 HWND GetLeftFakeHwnd() { |
| 2606 return fake_hwnd_left_; |
| 2607 } |
| 2608 |
| 2609 HWND GetRightFakeHwnd() { |
| 2610 return fake_hwnd_right_; |
| 2611 } |
| 2612 |
| 2613 private: |
| 2614 HWND fake_hwnd_left_ = nullptr; |
| 2615 HWND fake_hwnd_right_ = nullptr; |
| 2616 |
| 2617 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1x); |
| 2618 }; |
| 2619 |
| 2620 } // namespace |
| 2621 |
| 2622 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPPoints) { |
| 2623 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 2624 EXPECT_EQ(gfx::Point(182, 347), |
| 2625 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 2626 EXPECT_EQ(gfx::Point(959, 599), |
| 2627 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 2628 |
| 2629 EXPECT_EQ(gfx::Point(960, 0), |
| 2630 ScreenWin::ScreenToDIPPoint(gfx::Point(1920, 0))); |
| 2631 EXPECT_EQ(gfx::Point(1424, 351), |
| 2632 ScreenWin::ScreenToDIPPoint(gfx::Point(2384, 351))); |
| 2633 EXPECT_EQ(gfx::Point(1759, 599), |
| 2634 ScreenWin::ScreenToDIPPoint(gfx::Point(2719, 599))); |
| 2635 } |
| 2636 |
| 2637 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenPoints) { |
| 2638 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 2639 EXPECT_EQ(gfx::Point(364, 694), |
| 2640 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| 2641 EXPECT_EQ(gfx::Point(1918, 1198), |
| 2642 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| 2643 |
| 2644 EXPECT_EQ(gfx::Point(1920, 0), |
| 2645 ScreenWin::DIPToScreenPoint(gfx::Point(960, 0))); |
| 2646 EXPECT_EQ(gfx::Point(2384, 351), |
| 2647 ScreenWin::DIPToScreenPoint(gfx::Point(1424, 351))); |
| 2648 EXPECT_EQ(gfx::Point(2719, 599), |
| 2649 ScreenWin::DIPToScreenPoint(gfx::Point(1759, 599))); |
| 2650 } |
| 2651 |
| 2652 TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPPoints) { |
| 2653 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2654 EXPECT_EQ(gfx::Point(0, 0), |
| 2655 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(0, 0))); |
| 2656 EXPECT_EQ(gfx::Point(182, 347), |
| 2657 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(365, 694))); |
| 2658 EXPECT_EQ(gfx::Point(959, 599), |
| 2659 ScreenWin::ClientToDIPPoint(left_hwnd, gfx::Point(1919, 1199))); |
| 2660 |
| 2661 HWND right_hwnd = GetRightFakeHwnd(); |
| 2662 EXPECT_EQ(gfx::Point(0, 0), |
| 2663 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(0, 0))); |
| 2664 EXPECT_EQ(gfx::Point(365, 694), |
| 2665 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(365, 694))); |
| 2666 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2667 ScreenWin::ClientToDIPPoint(right_hwnd, gfx::Point(1919, 1199))); |
| 2668 } |
| 2669 |
| 2670 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientPoints) { |
| 2671 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2672 EXPECT_EQ(gfx::Point(0, 0), |
| 2673 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(0, 0))); |
| 2674 EXPECT_EQ(gfx::Point(364, 694), |
| 2675 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(182, 347))); |
| 2676 EXPECT_EQ(gfx::Point(1918, 1198), |
| 2677 ScreenWin::DIPToClientPoint(left_hwnd, gfx::Point(959, 599))); |
| 2678 |
| 2679 HWND right_hwnd = GetRightFakeHwnd(); |
| 2680 EXPECT_EQ(gfx::Point(0, 0), |
| 2681 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(0, 0))); |
| 2682 EXPECT_EQ(gfx::Point(365, 694), |
| 2683 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(365, 694))); |
| 2684 EXPECT_EQ(gfx::Point(1919, 1199), |
| 2685 ScreenWin::DIPToClientPoint(right_hwnd, gfx::Point(1919, 1199))); |
| 2686 } |
| 2687 |
| 2688 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPRects) { |
| 2689 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2690 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 2691 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2692 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 2693 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2694 |
| 2695 HWND right_hwnd = GetRightFakeHwnd(); |
| 2696 EXPECT_EQ(gfx::Rect(960, 0, 200, 300), |
| 2697 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2698 gfx::Rect(1920, 0, 200, 300))); |
| 2699 EXPECT_EQ(gfx::Rect(1040, 496, 100, 200), |
| 2700 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 2701 gfx::Rect(2000, 496, 100, 200))); |
| 2702 } |
| 2703 |
| 2704 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenRects) { |
| 2705 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2706 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2707 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 2708 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 2709 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 2710 |
| 2711 HWND right_hwnd = GetRightFakeHwnd(); |
| 2712 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 2713 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2714 gfx::Rect(960, 0, 200, 300))); |
| 2715 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 2716 ScreenWin::DIPToScreenRect(right_hwnd, |
| 2717 gfx::Rect(1040, 496, 100, 200))); |
| 2718 } |
| 2719 |
| 2720 TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPRects) { |
| 2721 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2722 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 2723 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2724 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 2725 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 2726 |
| 2727 HWND right_hwnd = GetRightFakeHwnd(); |
| 2728 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2729 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2730 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2731 ScreenWin::ClientToDIPRect(right_hwnd, |
| 2732 gfx::Rect(253, 496, 41, 52))); |
| 2733 } |
| 2734 |
| 2735 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientRects) { |
| 2736 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2737 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2738 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 2739 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 2740 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 2741 |
| 2742 HWND right_hwnd = GetRightFakeHwnd(); |
| 2743 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 2744 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 2745 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 2746 ScreenWin::DIPToClientRect(right_hwnd, |
| 2747 gfx::Rect(253, 496, 41, 52))); |
| 2748 } |
| 2749 |
| 2750 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPSize) { |
| 2751 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2752 EXPECT_EQ(gfx::Size(21, 66), |
| 2753 ScreenWin::ScreenToDIPSize(left_hwnd, gfx::Size(42, 131))); |
| 2754 |
| 2755 HWND right_hwnd = GetRightFakeHwnd(); |
| 2756 EXPECT_EQ(gfx::Size(42, 131), |
| 2757 ScreenWin::ScreenToDIPSize(right_hwnd, gfx::Size(42, 131))); |
| 2758 } |
| 2759 |
| 2760 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenSize) { |
| 2761 HWND left_hwnd = GetLeftFakeHwnd(); |
| 2762 EXPECT_EQ(gfx::Size(42, 132), |
| 2763 ScreenWin::DIPToScreenSize(left_hwnd, gfx::Size(21, 66))); |
| 2764 |
| 2765 HWND right_hwnd = GetRightFakeHwnd(); |
| 2766 EXPECT_EQ(gfx::Size(42, 131), |
| 2767 ScreenWin::DIPToScreenSize(right_hwnd, gfx::Size(42, 131))); |
| 2768 } |
| 2769 |
| 2770 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplays) { |
| 2771 std::vector<Display> displays = GetScreen()->GetAllDisplays(); |
| 2772 ASSERT_EQ(2u, displays.size()); |
| 2773 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 2774 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 2775 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].bounds()); |
| 2776 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].work_area()); |
| 2777 } |
| 2778 |
| 2779 TEST_F(ScreenWinTestTwoDisplays2x1x, GetNumDisplays) { |
| 2780 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| 2781 } |
| 2782 |
| 2783 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindowPrimaryDisplay) { |
| 2784 Screen* screen = GetScreen(); |
| 2785 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 2786 screen->GetDisplayNearestWindow(nullptr)); |
| 2787 } |
| 2788 |
| 2789 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindow) { |
| 2790 Screen* screen = GetScreen(); |
| 2791 const Display left_display = screen->GetAllDisplays()[0]; |
| 2792 const Display right_display = screen->GetAllDisplays()[1]; |
| 2793 |
| 2794 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 2795 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 2796 |
| 2797 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 2798 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 2799 } |
| 2800 |
| 2801 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestPoint) { |
| 2802 Screen* screen = GetScreen(); |
| 2803 const Display left_display = screen->GetAllDisplays()[0]; |
| 2804 const Display right_display = screen->GetAllDisplays()[1]; |
| 2805 |
| 2806 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 2807 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 300))); |
| 2808 EXPECT_EQ(left_display, |
| 2809 screen->GetDisplayNearestPoint(gfx::Point(959, 599))); |
| 2810 |
| 2811 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); |
| 2812 EXPECT_EQ(right_display, |
| 2813 screen->GetDisplayNearestPoint(gfx::Point(1500, 400))); |
| 2814 EXPECT_EQ(right_display, |
| 2815 screen->GetDisplayNearestPoint(gfx::Point(1659, 599))); |
| 2816 } |
| 2817 |
| 2818 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayMatching) { |
| 2819 Screen* screen = GetScreen(); |
| 2820 const Display left_display = screen->GetAllDisplays()[0]; |
| 2821 const Display right_display = screen->GetAllDisplays()[1]; |
| 2822 |
| 2823 EXPECT_EQ(left_display, |
| 2824 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 2825 EXPECT_EQ(left_display, |
| 2826 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 2827 |
| 2828 EXPECT_EQ(right_display, |
| 2829 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| 2830 EXPECT_EQ(right_display, |
| 2831 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 2832 } |
| 2833 |
| 2834 TEST_F(ScreenWinTestTwoDisplays2x1x, GetPrimaryDisplay) { |
| 2835 Screen* screen = GetScreen(); |
| 2836 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 2837 } |
| 2838 |
| 2839 namespace { |
| 2840 |
2085 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under | 2841 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under |
2086 // Windows DPI Virtualization. Note that the displays do not form a euclidean | 2842 // Windows DPI Virtualization. Note that the displays do not form a euclidean |
2087 // space. | 2843 // space. |
2088 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { | 2844 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
2089 public: | 2845 public: |
2090 ScreenWinTestTwoDisplays2x1xVirtualized() = default; | 2846 ScreenWinTestTwoDisplays2x1xVirtualized() = default; |
2091 | 2847 |
2092 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 2848 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
2093 SetDefaultDeviceScaleFactor(2.0); | |
2094 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), | 2849 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), |
2095 gfx::Rect(0, 0, 3200, 1500), | 2850 gfx::Rect(0, 0, 3200, 1500), |
2096 L"primary", | 2851 L"primary", |
2097 2.0); | 2852 2.0); |
2098 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), | 2853 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), |
2099 gfx::Rect(6400, 0, 3840, 2400), | 2854 gfx::Rect(6400, 0, 3840, 2400), |
2100 L"secondary", | 2855 L"secondary", |
2101 2.0); | 2856 2.0); |
2102 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); | 2857 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); |
2103 fake_hwnd_right_ = | 2858 fake_hwnd_right_ = |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); | 3283 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); |
2529 } | 3284 } |
2530 | 3285 |
2531 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { | 3286 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { |
2532 EXPECT_EQ(gfx::Size(42, 132), | 3287 EXPECT_EQ(gfx::Size(42, 132), |
2533 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); | 3288 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); |
2534 } | 3289 } |
2535 | 3290 |
2536 } // namespace win | 3291 } // namespace win |
2537 } // namespace display | 3292 } // namespace display |
OLD | NEW |