Chromium Code Reviews| Index: ui/gfx/screen_win_unittest.cc |
| diff --git a/ui/gfx/screen_win_unittest.cc b/ui/gfx/screen_win_unittest.cc |
| index e011c94155a1540f4676e021fe891d18b636e4c6..c705f54644cbea0a99517620954d349d2ede23c3 100644 |
| --- a/ui/gfx/screen_win_unittest.cc |
| +++ b/ui/gfx/screen_win_unittest.cc |
| @@ -14,11 +14,13 @@ |
| #include <unordered_map> |
| #include <vector> |
| +#include "base/command_line.h" |
| #include "base/macros.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/gfx/display.h" |
| #include "ui/gfx/geometry/rect.h" |
| #include "ui/gfx/screen.h" |
| +#include "ui/gfx/switches.h" |
| #include "ui/gfx/test/display_util.h" |
| #include "ui/gfx/win/display_info.h" |
| #include "ui/gfx/win/dpi.h" |
| @@ -245,6 +247,104 @@ class ScreenWinTestSingleDisplay1x : public ScreenWinTest { |
| HWND fake_hwnd_ = nullptr; |
| }; |
| +TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
| + EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPPoints) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientPoints) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPSize) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Size size(42, 131); |
| + EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenSize) { |
| + HWND hwnd = GetFakeHwnd(); |
| + |
| + gfx::Size size(42, 131); |
| + EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); |
| +} |
| + |
| TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { |
| std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| ASSERT_EQ(1u, displays.size()); |
| @@ -296,7 +396,6 @@ class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
| ScreenWinTestSingleDisplay2x() = default; |
| void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| - gfx::SetDefaultDeviceScaleFactor(2.0); |
| initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| gfx::Rect(0, 0, 1920, 1100), |
| L"primary", |
| @@ -314,6 +413,84 @@ class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
| DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); |
| }; |
| +TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(182, 347), |
| + ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| + EXPECT_EQ(gfx::Point(959, 599), |
| + ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(364, 694), |
| + ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| + EXPECT_EQ(gfx::Point(1918, 1198), |
| + ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPPoints) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Point(0, 0), |
| + ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(182, 347), |
| + ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); |
| + EXPECT_EQ(gfx::Point(959, 599), |
| + ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientPoints) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Point(0, 0), |
| + ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(364, 694), |
| + ScreenWin::DIPToClientPoint(hwnd, gfx::Point(182, 347))); |
| + EXPECT_EQ(gfx::Point(1918, 1198), |
| + ScreenWin::DIPToClientPoint(hwnd, gfx::Point(959, 599))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientRects) { |
| + HWND hwnd = GetFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPSize) { |
| + EXPECT_EQ(gfx::Size(21, 66), |
| + ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); |
| +} |
| + |
| +TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenSize) { |
| + EXPECT_EQ(gfx::Size(42, 132), |
| + ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(21, 66))); |
| +} |
| + |
| TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { |
| std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| ASSERT_EQ(1u, displays.size()); |
| @@ -371,6 +548,62 @@ class ScreenWinTestTwoDisplays1x : public ScreenWinTest { |
| DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); |
| }; |
| +TEST_F(ScreenWinTestTwoDisplays1x, ScreenToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + gfx::Rect left_origin(0, 0, 50, 100); |
| + gfx::Rect left_middle(253, 495, 41, 52); |
| + EXPECT_EQ(left_origin, ScreenWin::ScreenToDIPRect(left_hwnd, left_origin)); |
| + EXPECT_EQ(left_middle, ScreenWin::ScreenToDIPRect(left_hwnd, left_middle)); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + gfx::Rect right_origin(1920, 0, 200, 300); |
| + gfx::Rect right_middle(2000, 496, 100, 200); |
| + EXPECT_EQ(right_origin, ScreenWin::ScreenToDIPRect(right_hwnd, right_origin)); |
| + EXPECT_EQ(right_middle, ScreenWin::ScreenToDIPRect(right_hwnd, right_middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x, DIPToScreenRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + gfx::Rect left_origin(0, 0, 50, 100); |
| + gfx::Rect left_middle(253, 495, 41, 52); |
| + EXPECT_EQ(left_origin, ScreenWin::DIPToScreenRect(left_hwnd, left_origin)); |
| + EXPECT_EQ(left_middle, ScreenWin::DIPToScreenRect(left_hwnd, left_middle)); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + gfx::Rect right_origin(1920, 0, 200, 300); |
| + gfx::Rect right_middle(2000, 496, 100, 200); |
| + EXPECT_EQ(right_origin, ScreenWin::DIPToScreenRect(right_hwnd, right_origin)); |
| + EXPECT_EQ(right_middle, ScreenWin::DIPToScreenRect(right_hwnd, right_middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x, ClientToDIPRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(left_hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(left_hwnd, middle)); |
| + |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(right_hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(right_hwnd, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x, DIPToClientRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientRect(left_hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientRect(left_hwnd, middle)); |
| + |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientRect(right_hwnd, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientRect(right_hwnd, middle)); |
| +} |
| + |
| TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { |
| std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| ASSERT_EQ(2u, displays.size()); |
| @@ -447,7 +680,6 @@ class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
| ScreenWinTestTwoDisplays2x() = default; |
| void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| - gfx::SetDefaultDeviceScaleFactor(2.0); |
| initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| gfx::Rect(0, 0, 1920, 1100), |
| L"primary", |
| @@ -476,6 +708,61 @@ class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
| DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); |
| }; |
| +TEST_F(ScreenWinTestTwoDisplays2x, ScreenToDIPRects) { |
|
scottmg
2016/02/09 20:21:36
Maybe a couple fractional scale tests here to codi
robliao
2016/02/10 22:50:03
Done.
|
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(960, 0, 100, 150), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(1920, 0, 200, 300))); |
| + EXPECT_EQ(gfx::Rect(1000, 248, 50, 100), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(2000, 496, 100, 200))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x, DIPToScreenRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(960, 0, 100, 150))); |
| + EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(1000, 248, 50, 100))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x, ClientToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(right_hwnd, |
| + gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x, DIPToClientRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { |
| std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| ASSERT_EQ(2u, displays.size()); |
| @@ -542,6 +829,339 @@ TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { |
| EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| } |
| +// Two Displays of 1.0 (Left) and 2.0 (Right) Device Scale Factor. |
| +class ScreenWinTestTwoDisplays1x2x : public ScreenWinTest { |
| + public: |
| + ScreenWinTestTwoDisplays1x2x() = default; |
| + |
| + void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| + initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| + gfx::Rect(0, 0, 1920, 1100), |
| + L"primary", |
| + 1.0); |
| + initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| + gfx::Rect(1920, 0, 800, 600), |
| + L"secondary", |
| + 2.0); |
| + fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| + fake_hwnd_right_ = |
| + initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| + } |
| + |
| + HWND GetLeftFakeHwnd() { |
| + return fake_hwnd_left_; |
| + } |
| + |
| + HWND GetRightFakeHwnd() { |
| + return fake_hwnd_right_; |
| + } |
| + |
| + private: |
| + HWND fake_hwnd_left_ = nullptr; |
| + HWND fake_hwnd_right_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x2x); |
| +}; |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 100, 150), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(1920, 0, 200, 300))); |
| + EXPECT_EQ(gfx::Rect(1960, 248, 50, 100), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(2000, 496, 100, 200))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(1920, 0, 100, 150))); |
| + EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(1960, 248, 50, 100))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(right_hwnd, |
| + gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(right_hwnd, |
| + gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplays) { |
| + std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| + ASSERT_EQ(2u, displays.size()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].bounds()); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].work_area()); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetNumDisplays) { |
| + EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindowPrimaryDisplay) { |
| + gfx::Screen* screen = GetScreen(); |
| + EXPECT_EQ(screen->GetPrimaryDisplay(), |
| + screen->GetDisplayNearestWindow(nullptr)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindow) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| + |
| + gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| + EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestPoint) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); |
| + |
| + EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(2000, 200))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(2319, 299))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayMatching) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| + |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays1x2x, GetPrimaryDisplay) { |
| + gfx::Screen* screen = GetScreen(); |
| + gfx::Display primary = screen->GetPrimaryDisplay(); |
| + EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| +} |
| + |
| +// Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor. |
| +class ScreenWinTestTwoDisplays2x1x : public ScreenWinTest { |
| + public: |
| + ScreenWinTestTwoDisplays2x1x() = default; |
| + |
| + void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| + initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| + gfx::Rect(0, 0, 1920, 1100), |
| + L"primary", |
| + 2.0); |
| + initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| + gfx::Rect(1920, 0, 800, 600), |
| + L"secondary", |
| + 1.0); |
| + fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| + fake_hwnd_right_ = |
| + initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| + } |
| + |
| + HWND GetLeftFakeHwnd() { |
| + return fake_hwnd_left_; |
| + } |
| + |
| + HWND GetRightFakeHwnd() { |
| + return fake_hwnd_right_; |
| + } |
| + |
| + private: |
| + HWND fake_hwnd_left_ = nullptr; |
| + HWND fake_hwnd_right_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1x); |
| +}; |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(960, 0, 200, 300), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(1920, 0, 200, 300))); |
| + EXPECT_EQ(gfx::Rect(1040, 496, 100, 200), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(2000, 496, 100, 200))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(960, 0, 200, 300))); |
| + EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(1040, 496, 100, 200))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| + ScreenWin::ClientToDIPRect(right_hwnd, |
| + gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| + ScreenWin::DIPToClientRect(right_hwnd, |
| + gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplays) { |
| + std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| + ASSERT_EQ(2u, displays.size()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| + EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].bounds()); |
| + EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].work_area()); |
| +} |
| + |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetNumDisplays) { |
| + EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindowPrimaryDisplay) { |
| + gfx::Screen* screen = GetScreen(); |
| + EXPECT_EQ(screen->GetPrimaryDisplay(), |
| + screen->GetDisplayNearestWindow(nullptr)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindow) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| + |
| + gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| + EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestPoint) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 300))); |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(959, 599))); |
| + |
| + EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(1500, 400))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayNearestPoint(gfx::Point(1659, 599))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayMatching) { |
| + gfx::Screen* screen = GetScreen(); |
| + const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| + const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| + |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| + EXPECT_EQ(left_display, |
| + screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| + |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| + EXPECT_EQ(right_display, |
| + screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1x, GetPrimaryDisplay) { |
| + gfx::Screen* screen = GetScreen(); |
| + gfx::Display primary = screen->GetPrimaryDisplay(); |
| + EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| +} |
| + |
| // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under |
| // Windows DPI Virtualization. Note that the displays do not form a euclidean |
| // space. |
| @@ -550,7 +1170,6 @@ class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
| ScreenWinTestTwoDisplays2x1xVirtualized() = default; |
| void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| - gfx::SetDefaultDeviceScaleFactor(2.0); |
| initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), |
| gfx::Rect(0, 0, 3200, 1500), |
| L"primary", |
| @@ -579,6 +1198,68 @@ class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
| DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); |
| }; |
| +TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ScreenToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(3200, 0, 100, 150), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(6400, 0, 200, 300))); |
| + EXPECT_EQ(gfx::Rect(3500, 248, 50, 100), |
| + ScreenWin::ScreenToDIPRect(right_hwnd, |
| + gfx::Rect(7000, 496, 100, 200))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToScreenRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(6400, 0, 200, 300), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(3200, 0, 100, 150))); |
| + EXPECT_EQ(gfx::Rect(7000, 496, 100, 200), |
| + ScreenWin::DIPToScreenRect(right_hwnd, |
| + gfx::Rect(3500, 248, 50, 100))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ClientToDIPRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(right_hwnd, |
| + gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToClientRects) { |
| + HWND left_hwnd = GetLeftFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| + |
| + HWND right_hwnd = GetRightFakeHwnd(); |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(right_hwnd, |
| + gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { |
| std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| ASSERT_EQ(2u, displays.size()); |
| @@ -650,4 +1331,206 @@ TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { |
| EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| } |
| +// Forced 1x DPI for Other Tests without TestScreenWin. |
| +class ScreenWinUninitializedForced1x : public testing::Test { |
| + public: |
| + ScreenWinUninitializedForced1x() |
| + : old_command_line(*base::CommandLine::ForCurrentProcess()) {} |
| + |
| + void SetUp() override { |
| + testing::Test::SetUp(); |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1"); |
| + } |
| + |
| + void TearDown() override { |
| + *base::CommandLine::ForCurrentProcess() = old_command_line; |
| + Display::ResetForceDeviceScaleFactorForTesting(); |
| + testing::Test::TearDown(); |
| + } |
| + |
| + private: |
| + base::CommandLine old_command_line; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced1x); |
| +}; |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
| + EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, DIPToScreenPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, ClientToDIPPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(nullptr, middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(nullptr, lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, DIPToClientPoints) { |
| + gfx::Point origin(0, 0); |
| + gfx::Point middle(365, 694); |
| + gfx::Point lower_right(1919, 1199); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(nullptr, middle)); |
| + EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(nullptr, lower_right)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(nullptr, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, DIPToScreenRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(nullptr, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, ClientToDIPRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(nullptr, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, DIPToClientRects) { |
| + gfx::Rect origin(0, 0, 50, 100); |
| + gfx::Rect middle(253, 495, 41, 52); |
| + |
| + EXPECT_EQ(origin, ScreenWin::DIPToClientRect(nullptr, origin)); |
| + EXPECT_EQ(middle, ScreenWin::DIPToClientRect(nullptr, middle)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPSize) { |
| + gfx::Size size(42, 131); |
| + EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(nullptr, size)); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced1x, DIPToScreenSize) { |
| + gfx::Size size(42, 131); |
| + EXPECT_EQ(size, ScreenWin::DIPToScreenSize(nullptr, size)); |
| +} |
| + |
| +// Forced 2x DPI for Other Tests without TestScreenWin. |
| +class ScreenWinUninitializedForced2x : public testing::Test { |
| + public: |
| + ScreenWinUninitializedForced2x() |
| + : old_command_line(*base::CommandLine::ForCurrentProcess()) {} |
| + |
| + void SetUp() override { |
| + testing::Test::SetUp(); |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); |
| + } |
| + |
| + void TearDown() override { |
| + *base::CommandLine::ForCurrentProcess() = old_command_line; |
| + Display::ResetForceDeviceScaleFactorForTesting(); |
| + testing::Test::TearDown(); |
| + } |
| + |
| + private: |
| + base::CommandLine old_command_line; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced2x); |
| +}; |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(182, 347), |
| + ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| + EXPECT_EQ(gfx::Point(959, 599), |
| + ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, DIPToScreenPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(364, 694), |
| + ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| + EXPECT_EQ(gfx::Point(1918, 1198), |
| + ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, ClientToDIPPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), |
| + ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(182, 347), |
| + ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(365, 694))); |
| + EXPECT_EQ(gfx::Point(959, 599), |
| + ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(1919, 1199))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, DIPToClientPoints) { |
| + EXPECT_EQ(gfx::Point(0, 0), |
| + ScreenWin::DIPToClientPoint(nullptr, gfx::Point(0, 0))); |
| + EXPECT_EQ(gfx::Point(364, 694), |
| + ScreenWin::DIPToClientPoint(nullptr, gfx::Point(182, 347))); |
| + EXPECT_EQ(gfx::Point(1918, 1198), |
| + ScreenWin::DIPToClientPoint(nullptr, gfx::Point(959, 599))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPRects) { |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, DIPToScreenRects) { |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, ClientToDIPRects) { |
| + EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| + ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); |
| + EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| + ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, DIPToClientRects) { |
| + EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| + ScreenWin::DIPToClientRect(nullptr, gfx::Rect(0, 0, 25, 50))); |
| + EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| + ScreenWin::DIPToClientRect(nullptr, gfx::Rect(126, 248, 21, 26))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPSize) { |
| + EXPECT_EQ(gfx::Size(21, 66), |
| + ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); |
| +} |
| + |
| +TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { |
| + EXPECT_EQ(gfx::Size(42, 132), |
| + ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); |
| +} |
| + |
| } // namespace gfx |