OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/screen_win.h" | 5 #include "ui/gfx/screen_win.h" |
6 | 6 |
7 #include <cwchar> | 7 #include <cwchar> |
8 #include <string> | 8 #include <string> |
| 9 #include <unordered_map> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include <windows.h> | 12 #include <windows.h> |
12 #include <stddef.h> | 13 #include <stddef.h> |
13 | 14 |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/win/dpi.h" | 18 #include "ui/gfx/win/dpi.h" |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, | 24 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, |
24 gfx::Rect work, | 25 gfx::Rect work, |
25 std::wstring device_name) { | 26 std::wstring device_name) { |
26 MONITORINFOEX monitor_info; | 27 MONITORINFOEX monitor_info; |
27 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); | 28 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); |
28 monitor_info.cbSize = sizeof(monitor_info); | 29 monitor_info.cbSize = sizeof(monitor_info); |
29 monitor_info.rcMonitor = monitor.ToRECT(); | 30 monitor_info.rcMonitor = monitor.ToRECT(); |
30 monitor_info.rcWork = work.ToRECT(); | 31 monitor_info.rcWork = work.ToRECT(); |
31 size_t device_char_count = ARRAYSIZE(monitor_info.szDevice); | 32 size_t device_char_count = ARRAYSIZE(monitor_info.szDevice); |
32 wcsncpy(monitor_info.szDevice, device_name.c_str(), device_char_count); | 33 wcsncpy(monitor_info.szDevice, device_name.c_str(), device_char_count); |
33 monitor_info.szDevice[device_char_count-1] = L'\0'; | 34 monitor_info.szDevice[device_char_count-1] = L'\0'; |
34 return monitor_info; | 35 return monitor_info; |
35 } | 36 } |
36 | 37 |
| 38 class TestScreenWin : public gfx::ScreenWin { |
| 39 public: |
| 40 explicit TestScreenWin(const std::vector<DisplayInfo>& display_infos, |
| 41 const std::vector<MONITORINFOEX>& monitor_infos, |
| 42 const std::unordered_map<HWND, gfx::Rect>& hwnd_map) |
| 43 : gfx::ScreenWin(display_infos), |
| 44 monitor_infos_(monitor_infos), |
| 45 hwnd_map_(hwnd_map) {} |
| 46 |
| 47 private: |
| 48 MONITORINFOEX MonitorInfoFromScreenPoint(const gfx::Point& screen_point) const |
| 49 override { |
| 50 for (const MONITORINFOEX& monitor_info : monitor_infos_) { |
| 51 if (gfx::Rect(monitor_info.rcMonitor).Contains(screen_point)) { |
| 52 return monitor_info; |
| 53 } |
| 54 } |
| 55 NOTREACHED(); |
| 56 return monitor_infos_[0]; |
| 57 } |
| 58 |
| 59 MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) const |
| 60 override { |
| 61 MONITORINFOEX candidate = monitor_infos_[0]; |
| 62 int largest_area = 0; |
| 63 for (const MONITORINFOEX& monitor_info : monitor_infos_) { |
| 64 gfx::Rect bounds(monitor_info.rcMonitor); |
| 65 if (bounds.Intersects(screen_rect)) { |
| 66 bounds.Intersect(screen_rect); |
| 67 int area = bounds.height() * bounds.width(); |
| 68 if (largest_area < area) { |
| 69 candidate = monitor_info; |
| 70 largest_area = area; |
| 71 } |
| 72 } |
| 73 } |
| 74 EXPECT_NE(largest_area, 0); |
| 75 return candidate; |
| 76 } |
| 77 |
| 78 MONITORINFOEX MonitorInfoFromWindow(HWND hwnd) const override { |
| 79 auto search = hwnd_map_.find(hwnd); |
| 80 EXPECT_NE(search, hwnd_map_.end()); |
| 81 return MonitorInfoFromScreenRect(search->second); |
| 82 } |
| 83 |
| 84 HWND GetRootWindow(HWND hwnd) const override { |
| 85 return hwnd; |
| 86 } |
| 87 |
| 88 private: |
| 89 std::vector<MONITORINFOEX> monitor_infos_; |
| 90 std::unordered_map<HWND, gfx::Rect> hwnd_map_; |
| 91 }; |
| 92 |
37 } // namespace | 93 } // namespace |
38 | 94 |
| 95 // Manages setting up the ScreenWin global state. |
| 96 class TestScreenWinInitializer { |
| 97 public: |
| 98 TestScreenWinInitializer() : hwndLast_(0) {} |
| 99 ~TestScreenWinInitializer() { |
| 100 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr); |
| 101 } |
| 102 |
| 103 void AddMonitor(const gfx::Rect& pixel_bounds, |
| 104 const gfx::Rect& pixel_work, |
| 105 const wchar_t* device_name, |
| 106 float device_scale_factor) { |
| 107 MONITORINFOEX monitor_info = CreateMonitorInfo(pixel_bounds, |
| 108 pixel_work, |
| 109 device_name); |
| 110 monitor_infos_.push_back(monitor_info); |
| 111 display_infos_.push_back(ScreenWin::DisplayInfo(monitor_info, |
| 112 gfx::Display::ROTATE_0, |
| 113 device_scale_factor)); |
| 114 } |
| 115 |
| 116 void InitializeScreenWin() { |
| 117 ASSERT_EQ(screen_win_, nullptr); |
| 118 screen_win_.reset(new TestScreenWin(display_infos_, |
| 119 monitor_infos_, |
| 120 hwnd_map_)); |
| 121 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_win_.get()); |
| 122 } |
| 123 |
| 124 HWND CreateFakeHwnd(const gfx::Rect& bounds) { |
| 125 EXPECT_EQ(screen_win_, nullptr); |
| 126 ++hwndLast_; |
| 127 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(hwndLast_, bounds)); |
| 128 return hwndLast_; |
| 129 } |
| 130 |
| 131 Screen* GetScreen() { |
| 132 if (!screen_win_) { |
| 133 InitializeScreenWin(); |
| 134 } |
| 135 return screen_win_.get(); |
| 136 } |
| 137 |
| 138 private: |
| 139 HWND hwndLast_; |
| 140 scoped_ptr<ScreenWin> screen_win_; |
| 141 std::vector<MONITORINFOEX> monitor_infos_; |
| 142 std::vector<gfx::ScreenWin::DisplayInfo> display_infos_; |
| 143 std::unordered_map<HWND, gfx::Rect> hwnd_map_; |
| 144 }; |
| 145 |
39 class ScreenWinTest : public testing::Test { | 146 class ScreenWinTest : public testing::Test { |
40 private: | 147 private: |
41 void SetUp() override { | 148 void SetUp() override { |
42 testing::Test::SetUp(); | 149 testing::Test::SetUp(); |
43 gfx::SetDefaultDeviceScaleFactor(1.0); | 150 gfx::SetDefaultDeviceScaleFactor(1.0); |
44 } | 151 } |
45 | 152 |
46 void TearDown() override { | 153 void TearDown() override { |
47 gfx::SetDefaultDeviceScaleFactor(1.0); | 154 gfx::SetDefaultDeviceScaleFactor(1.0); |
48 testing::Test::TearDown(); | 155 testing::Test::TearDown(); |
49 } | 156 } |
50 }; | 157 }; |
51 | 158 |
52 TEST_F(ScreenWinTest, SingleDisplay1x) { | 159 // Single Display of 1.0 Device Scale Factor. |
53 std::vector<MONITORINFOEX> monitor_infos; | 160 class ScreenWinTestSingleDisplay1x : public ScreenWinTest { |
54 monitor_infos.push_back(CreateMonitorInfo(gfx::Rect(0, 0, 1920, 1200), | 161 public: |
55 gfx::Rect(0, 0, 1920, 1100), | 162 static void SetUpTestCase() { |
56 L"primary")); | 163 ScreenWinTest::SetUpTestCase(); |
57 std::vector<gfx::Display> displays = | 164 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
58 ScreenWin::GetDisplaysForMonitorInfos(monitor_infos); | 165 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
59 | 166 gfx::Rect(0, 0, 1920, 1100), |
| 167 L"primary", |
| 168 1.0); |
| 169 fake_hwnd_ = |
| 170 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 171 screen_win_initializer_->InitializeScreenWin(); |
| 172 } |
| 173 |
| 174 static void TearDownTestCase() { |
| 175 screen_win_initializer_.reset(); |
| 176 ScreenWinTest::TearDownTestCase(); |
| 177 } |
| 178 |
| 179 Screen* GetScreen() { |
| 180 return screen_win_initializer_->GetScreen(); |
| 181 } |
| 182 |
| 183 HWND GetFakeHwnd() { |
| 184 return fake_hwnd_; |
| 185 } |
| 186 |
| 187 private: |
| 188 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 189 static HWND fake_hwnd_; |
| 190 }; |
| 191 |
| 192 scoped_ptr<TestScreenWinInitializer> |
| 193 ScreenWinTestSingleDisplay1x::screen_win_initializer_; |
| 194 |
| 195 HWND ScreenWinTestSingleDisplay1x::fake_hwnd_ = NULL; |
| 196 |
| 197 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { |
| 198 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
60 ASSERT_EQ(1u, displays.size()); | 199 ASSERT_EQ(1u, displays.size()); |
61 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 200 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
62 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 201 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
63 } | 202 } |
64 | 203 |
65 TEST_F(ScreenWinTest, SingleDisplay2x) { | 204 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPPoints) { |
66 gfx::SetDefaultDeviceScaleFactor(2.0); | 205 gfx::Point origin(0, 0); |
67 | 206 gfx::Point middle(365, 694); |
68 std::vector<MONITORINFOEX> monitor_infos; | 207 gfx::Point lower_right(1919, 1199); |
69 monitor_infos.push_back(CreateMonitorInfo(gfx::Rect(0, 0, 1920, 1200), | 208 |
70 gfx::Rect(0, 0, 1920, 1100), | 209 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
71 L"primary")); | 210 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
72 std::vector<gfx::Display> displays = | 211 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
73 ScreenWin::GetDisplaysForMonitorInfos(monitor_infos); | 212 } |
74 | 213 |
| 214 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenPoints) { |
| 215 gfx::Point origin(0, 0); |
| 216 gfx::Point middle(365, 694); |
| 217 gfx::Point lower_right(1919, 1199); |
| 218 |
| 219 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| 220 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| 221 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| 222 } |
| 223 |
| 224 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPPoints) { |
| 225 HWND hwnd = GetFakeHwnd(); |
| 226 |
| 227 gfx::Point origin(0, 0); |
| 228 gfx::Point middle(365, 694); |
| 229 gfx::Point lower_right(1919, 1199); |
| 230 |
| 231 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); |
| 232 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); |
| 233 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); |
| 234 } |
| 235 |
| 236 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientPoints) { |
| 237 HWND hwnd = GetFakeHwnd(); |
| 238 |
| 239 gfx::Point origin(0, 0); |
| 240 gfx::Point middle(365, 694); |
| 241 gfx::Point lower_right(1919, 1199); |
| 242 |
| 243 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); |
| 244 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); |
| 245 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); |
| 246 } |
| 247 |
| 248 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPRects) { |
| 249 HWND hwnd = GetFakeHwnd(); |
| 250 |
| 251 gfx::Rect origin(0, 0, 50, 100); |
| 252 gfx::Rect middle(253, 495, 41, 52); |
| 253 |
| 254 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); |
| 255 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); |
| 256 } |
| 257 |
| 258 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenRects) { |
| 259 HWND hwnd = GetFakeHwnd(); |
| 260 |
| 261 gfx::Rect origin(0, 0, 50, 100); |
| 262 gfx::Rect middle(253, 495, 41, 52); |
| 263 |
| 264 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); |
| 265 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); |
| 266 } |
| 267 |
| 268 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPRects) { |
| 269 HWND hwnd = GetFakeHwnd(); |
| 270 |
| 271 gfx::Rect origin(0, 0, 50, 100); |
| 272 gfx::Rect middle(253, 495, 41, 52); |
| 273 |
| 274 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); |
| 275 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); |
| 276 } |
| 277 |
| 278 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientRects) { |
| 279 HWND hwnd = GetFakeHwnd(); |
| 280 |
| 281 gfx::Rect origin(0, 0, 50, 100); |
| 282 gfx::Rect middle(253, 495, 41, 52); |
| 283 |
| 284 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); |
| 285 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); |
| 286 } |
| 287 |
| 288 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPSize) { |
| 289 HWND hwnd = GetFakeHwnd(); |
| 290 |
| 291 gfx::Size size(42, 131); |
| 292 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); |
| 293 } |
| 294 |
| 295 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenSize) { |
| 296 HWND hwnd = GetFakeHwnd(); |
| 297 |
| 298 gfx::Size size(42, 131); |
| 299 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); |
| 300 } |
| 301 |
| 302 // Single Display of 2.0 Device Scale Factor. |
| 303 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
| 304 public: |
| 305 static void SetUpTestCase() { |
| 306 ScreenWinTest::SetUpTestCase(); |
| 307 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 308 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 309 gfx::Rect(0, 0, 1920, 1100), |
| 310 L"primary", |
| 311 2.0); |
| 312 fake_hwnd_ = |
| 313 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 314 screen_win_initializer_->InitializeScreenWin(); |
| 315 } |
| 316 |
| 317 static void TearDownTestCase() { |
| 318 screen_win_initializer_.reset(); |
| 319 ScreenWinTest::TearDownTestCase(); |
| 320 } |
| 321 |
| 322 Screen* GetScreen() { |
| 323 return screen_win_initializer_->GetScreen(); |
| 324 } |
| 325 |
| 326 HWND GetFakeHwnd() { |
| 327 return fake_hwnd_; |
| 328 } |
| 329 |
| 330 private: |
| 331 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 332 static HWND fake_hwnd_; |
| 333 }; |
| 334 |
| 335 scoped_ptr<TestScreenWinInitializer> |
| 336 ScreenWinTestSingleDisplay2x::screen_win_initializer_; |
| 337 |
| 338 HWND ScreenWinTestSingleDisplay2x::fake_hwnd_ = NULL; |
| 339 |
| 340 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { |
| 341 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
75 ASSERT_EQ(1u, displays.size()); | 342 ASSERT_EQ(1u, displays.size()); |
76 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 343 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
77 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 344 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
78 } | 345 } |
79 | 346 |
| 347 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPPoints) { |
| 348 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 349 EXPECT_EQ(gfx::Point(182, 347), |
| 350 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 351 EXPECT_EQ(gfx::Point(959, 599), |
| 352 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 353 } |
| 354 |
| 355 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenPoints) { |
| 356 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 357 EXPECT_EQ(gfx::Point(364, 694), |
| 358 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| 359 EXPECT_EQ(gfx::Point(1918, 1198), |
| 360 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| 361 } |
| 362 |
| 363 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPPoints) { |
| 364 HWND hwnd = GetFakeHwnd(); |
| 365 EXPECT_EQ(gfx::Point(0, 0), |
| 366 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); |
| 367 EXPECT_EQ(gfx::Point(182, 347), |
| 368 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); |
| 369 EXPECT_EQ(gfx::Point(959, 599), |
| 370 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); |
| 371 } |
| 372 |
| 373 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientPoints) { |
| 374 HWND hwnd = GetFakeHwnd(); |
| 375 EXPECT_EQ(gfx::Point(0, 0), |
| 376 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); |
| 377 EXPECT_EQ(gfx::Point(364, 694), |
| 378 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(182, 347))); |
| 379 EXPECT_EQ(gfx::Point(1918, 1198), |
| 380 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(959, 599))); |
| 381 } |
| 382 |
| 383 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPRects) { |
| 384 HWND hwnd = GetFakeHwnd(); |
| 385 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 386 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 387 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 388 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 389 } |
| 390 |
| 391 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenRects) { |
| 392 HWND hwnd = GetFakeHwnd(); |
| 393 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 394 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| 395 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 396 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| 397 } |
| 398 |
| 399 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPRects) { |
| 400 HWND hwnd = GetFakeHwnd(); |
| 401 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 402 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 403 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 404 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 405 } |
| 406 |
| 407 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientRects) { |
| 408 HWND hwnd = GetFakeHwnd(); |
| 409 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 410 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| 411 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 412 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| 413 } |
| 414 |
| 415 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPSize) { |
| 416 EXPECT_EQ(gfx::Size(21, 66), |
| 417 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); |
| 418 } |
| 419 |
| 420 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenSize) { |
| 421 EXPECT_EQ(gfx::Size(42, 132), |
| 422 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(21, 66))); |
| 423 } |
| 424 |
| 425 // Two Displays of 1.0 Device Scale Factor. |
| 426 class ScreenWinTestTwoDisplays1x : public ScreenWinTest { |
| 427 public: |
| 428 static void SetUpTestCase() { |
| 429 ScreenWinTest::SetUpTestCase(); |
| 430 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 431 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 432 gfx::Rect(0, 0, 1920, 1100), |
| 433 L"primary", |
| 434 1.0); |
| 435 screen_win_initializer_->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 436 gfx::Rect(1920, 0, 800, 600), |
| 437 L"secondary", |
| 438 1.0); |
| 439 fake_hwnd_left_ = |
| 440 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 441 fake_hwnd_right_ = |
| 442 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 443 screen_win_initializer_->InitializeScreenWin(); |
| 444 } |
| 445 |
| 446 static void TearDownTestCase() { |
| 447 screen_win_initializer_.reset(); |
| 448 ScreenWinTest::TearDownTestCase(); |
| 449 } |
| 450 |
| 451 Screen* GetScreen() { |
| 452 return screen_win_initializer_->GetScreen(); |
| 453 } |
| 454 |
| 455 HWND GetLeftFakeHwnd() { |
| 456 return fake_hwnd_left_; |
| 457 } |
| 458 |
| 459 HWND GetRightFakeHwnd() { |
| 460 return fake_hwnd_right_; |
| 461 } |
| 462 |
| 463 private: |
| 464 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 465 static HWND fake_hwnd_left_; |
| 466 static HWND fake_hwnd_right_; |
| 467 }; |
| 468 |
| 469 scoped_ptr<TestScreenWinInitializer> |
| 470 ScreenWinTestTwoDisplays1x::screen_win_initializer_; |
| 471 |
| 472 HWND ScreenWinTestTwoDisplays1x::fake_hwnd_left_ = NULL; |
| 473 |
| 474 HWND ScreenWinTestTwoDisplays1x::fake_hwnd_right_ = NULL; |
| 475 |
| 476 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { |
| 477 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 478 ASSERT_EQ(2u, displays.size()); |
| 479 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 480 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 481 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); |
| 482 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); |
| 483 } |
| 484 |
| 485 TEST_F(ScreenWinTestTwoDisplays1x, ScreenToDIPRects) { |
| 486 HWND left_hwnd = GetLeftFakeHwnd(); |
| 487 gfx::Rect left_origin(0, 0, 50, 100); |
| 488 gfx::Rect left_middle(253, 495, 41, 52); |
| 489 EXPECT_EQ(left_origin, ScreenWin::ScreenToDIPRect(left_hwnd, left_origin)); |
| 490 EXPECT_EQ(left_middle, ScreenWin::ScreenToDIPRect(left_hwnd, left_middle)); |
| 491 |
| 492 HWND right_hwnd = GetRightFakeHwnd(); |
| 493 gfx::Rect right_origin(1920, 0, 200, 300); |
| 494 gfx::Rect right_middle(2000, 496, 100, 200); |
| 495 EXPECT_EQ(right_origin, ScreenWin::ScreenToDIPRect(right_hwnd, right_origin)); |
| 496 EXPECT_EQ(right_middle, ScreenWin::ScreenToDIPRect(right_hwnd, right_middle)); |
| 497 } |
| 498 |
| 499 TEST_F(ScreenWinTestTwoDisplays1x, DIPToScreenRects) { |
| 500 HWND left_hwnd = GetLeftFakeHwnd(); |
| 501 gfx::Rect left_origin(0, 0, 50, 100); |
| 502 gfx::Rect left_middle(253, 495, 41, 52); |
| 503 EXPECT_EQ(left_origin, ScreenWin::DIPToScreenRect(left_hwnd, left_origin)); |
| 504 EXPECT_EQ(left_middle, ScreenWin::DIPToScreenRect(left_hwnd, left_middle)); |
| 505 |
| 506 HWND right_hwnd = GetRightFakeHwnd(); |
| 507 gfx::Rect right_origin(1920, 0, 200, 300); |
| 508 gfx::Rect right_middle(2000, 496, 100, 200); |
| 509 EXPECT_EQ(right_origin, ScreenWin::DIPToScreenRect(right_hwnd, right_origin)); |
| 510 EXPECT_EQ(right_middle, ScreenWin::DIPToScreenRect(right_hwnd, right_middle)); |
| 511 } |
| 512 |
| 513 TEST_F(ScreenWinTestTwoDisplays1x, ClientToDIPRects) { |
| 514 gfx::Rect origin(0, 0, 50, 100); |
| 515 gfx::Rect middle(253, 495, 41, 52); |
| 516 |
| 517 HWND left_hwnd = GetLeftFakeHwnd(); |
| 518 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(left_hwnd, origin)); |
| 519 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(left_hwnd, middle)); |
| 520 |
| 521 |
| 522 HWND right_hwnd = GetRightFakeHwnd(); |
| 523 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(right_hwnd, origin)); |
| 524 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(right_hwnd, middle)); |
| 525 } |
| 526 |
| 527 TEST_F(ScreenWinTestTwoDisplays1x, DIPToClientRects) { |
| 528 gfx::Rect origin(0, 0, 50, 100); |
| 529 gfx::Rect middle(253, 495, 41, 52); |
| 530 |
| 531 HWND left_hwnd = GetLeftFakeHwnd(); |
| 532 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(left_hwnd, origin)); |
| 533 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(left_hwnd, middle)); |
| 534 |
| 535 |
| 536 HWND right_hwnd = GetRightFakeHwnd(); |
| 537 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(right_hwnd, origin)); |
| 538 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(right_hwnd, middle)); |
| 539 } |
| 540 |
| 541 // Two Displays of 2.0 Device Scale Factor. |
| 542 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
| 543 public: |
| 544 static void SetUpTestCase() { |
| 545 ScreenWinTest::SetUpTestCase(); |
| 546 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 547 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 548 gfx::Rect(0, 0, 1920, 1100), |
| 549 L"primary", |
| 550 2.0); |
| 551 screen_win_initializer_->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 552 gfx::Rect(1920, 0, 800, 600), |
| 553 L"secondary", |
| 554 2.0); |
| 555 fake_hwnd_left_ = |
| 556 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 557 fake_hwnd_right_ = |
| 558 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 559 screen_win_initializer_->InitializeScreenWin(); |
| 560 } |
| 561 |
| 562 static void TearDownTestCase() { |
| 563 screen_win_initializer_.reset(); |
| 564 ScreenWinTest::TearDownTestCase(); |
| 565 } |
| 566 |
| 567 Screen* GetScreen() { |
| 568 return screen_win_initializer_->GetScreen(); |
| 569 } |
| 570 |
| 571 HWND GetLeftFakeHwnd() { |
| 572 return fake_hwnd_left_; |
| 573 } |
| 574 |
| 575 HWND GetRightFakeHwnd() { |
| 576 return fake_hwnd_right_; |
| 577 } |
| 578 |
| 579 private: |
| 580 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 581 static HWND fake_hwnd_left_; |
| 582 static HWND fake_hwnd_right_; |
| 583 }; |
| 584 |
| 585 scoped_ptr<TestScreenWinInitializer> |
| 586 ScreenWinTestTwoDisplays2x::screen_win_initializer_; |
| 587 |
| 588 HWND ScreenWinTestTwoDisplays2x::fake_hwnd_left_ = NULL; |
| 589 |
| 590 HWND ScreenWinTestTwoDisplays2x::fake_hwnd_right_ = NULL; |
| 591 |
| 592 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { |
| 593 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 594 ASSERT_EQ(2u, displays.size()); |
| 595 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 596 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 597 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); |
| 598 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); |
| 599 } |
| 600 |
| 601 TEST_F(ScreenWinTestTwoDisplays2x, ScreenToDIPRects) { |
| 602 HWND left_hwnd = GetLeftFakeHwnd(); |
| 603 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 604 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 605 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 606 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 607 |
| 608 HWND right_hwnd = GetRightFakeHwnd(); |
| 609 EXPECT_EQ(gfx::Rect(960, 0, 100, 150), |
| 610 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 611 gfx::Rect(1920, 0, 200, 300))); |
| 612 EXPECT_EQ(gfx::Rect(1000, 248, 50, 100), |
| 613 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 614 gfx::Rect(2000, 496, 100, 200))); |
| 615 } |
| 616 |
| 617 TEST_F(ScreenWinTestTwoDisplays2x, DIPToScreenRects) { |
| 618 HWND left_hwnd = GetLeftFakeHwnd(); |
| 619 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 620 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 621 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 622 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 623 |
| 624 HWND right_hwnd = GetRightFakeHwnd(); |
| 625 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 626 ScreenWin::DIPToScreenRect(right_hwnd, |
| 627 gfx::Rect(960, 0, 100, 150))); |
| 628 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 629 ScreenWin::DIPToScreenRect(right_hwnd, |
| 630 gfx::Rect(1000, 248, 50, 100))); |
| 631 } |
| 632 |
| 633 TEST_F(ScreenWinTestTwoDisplays2x, ClientToDIPRects) { |
| 634 HWND left_hwnd = GetLeftFakeHwnd(); |
| 635 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 636 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 637 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 638 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 639 |
| 640 HWND right_hwnd = GetRightFakeHwnd(); |
| 641 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 642 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 643 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 644 ScreenWin::ClientToDIPRect(right_hwnd, |
| 645 gfx::Rect(253, 496, 41, 52))); |
| 646 } |
| 647 |
| 648 TEST_F(ScreenWinTestTwoDisplays2x, DIPToClientRects) { |
| 649 HWND left_hwnd = GetLeftFakeHwnd(); |
| 650 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 651 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 652 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 653 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 654 } |
| 655 |
| 656 // Two Displays of 1.0 (Left) and 2.0 (Right) Device Scale Factor. |
| 657 class ScreenWinTestTwoDisplays1x2x : public ScreenWinTest { |
| 658 public: |
| 659 static void SetUpTestCase() { |
| 660 ScreenWinTest::SetUpTestCase(); |
| 661 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 662 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 663 gfx::Rect(0, 0, 1920, 1100), |
| 664 L"primary", |
| 665 1.0); |
| 666 screen_win_initializer_->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 667 gfx::Rect(1920, 0, 800, 600), |
| 668 L"secondary", |
| 669 2.0); |
| 670 fake_hwnd_left_ = |
| 671 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 672 fake_hwnd_right_ = |
| 673 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 674 screen_win_initializer_->InitializeScreenWin(); |
| 675 } |
| 676 |
| 677 static void TearDownTestCase() { |
| 678 screen_win_initializer_.reset(); |
| 679 ScreenWinTest::TearDownTestCase(); |
| 680 } |
| 681 |
| 682 Screen* GetScreen() { |
| 683 return screen_win_initializer_->GetScreen(); |
| 684 } |
| 685 |
| 686 HWND GetLeftFakeHwnd() { |
| 687 return fake_hwnd_left_; |
| 688 } |
| 689 |
| 690 HWND GetRightFakeHwnd() { |
| 691 return fake_hwnd_right_; |
| 692 } |
| 693 |
| 694 private: |
| 695 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 696 static HWND fake_hwnd_left_; |
| 697 static HWND fake_hwnd_right_; |
| 698 }; |
| 699 |
| 700 scoped_ptr<TestScreenWinInitializer> |
| 701 ScreenWinTestTwoDisplays1x2x::screen_win_initializer_; |
| 702 |
| 703 HWND ScreenWinTestTwoDisplays1x2x::fake_hwnd_left_ = NULL; |
| 704 |
| 705 HWND ScreenWinTestTwoDisplays1x2x::fake_hwnd_right_ = NULL; |
| 706 |
| 707 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplays) { |
| 708 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 709 ASSERT_EQ(2u, displays.size()); |
| 710 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 711 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 712 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].bounds()); |
| 713 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].work_area()); |
| 714 } |
| 715 |
| 716 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPRects) { |
| 717 HWND left_hwnd = GetLeftFakeHwnd(); |
| 718 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 719 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 720 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 721 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 722 |
| 723 HWND right_hwnd = GetRightFakeHwnd(); |
| 724 EXPECT_EQ(gfx::Rect(1920, 0, 100, 150), |
| 725 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 726 gfx::Rect(1920, 0, 200, 300))); |
| 727 EXPECT_EQ(gfx::Rect(1960, 248, 50, 100), |
| 728 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 729 gfx::Rect(2000, 496, 100, 200))); |
| 730 } |
| 731 |
| 732 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenRects) { |
| 733 HWND left_hwnd = GetLeftFakeHwnd(); |
| 734 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 735 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 736 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 737 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 738 |
| 739 HWND right_hwnd = GetRightFakeHwnd(); |
| 740 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 741 ScreenWin::DIPToScreenRect(right_hwnd, |
| 742 gfx::Rect(1920, 0, 100, 150))); |
| 743 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 744 ScreenWin::DIPToScreenRect(right_hwnd, |
| 745 gfx::Rect(1960, 248, 50, 100))); |
| 746 } |
| 747 |
| 748 TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPRects) { |
| 749 HWND left_hwnd = GetLeftFakeHwnd(); |
| 750 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 751 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 752 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 753 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 754 |
| 755 HWND right_hwnd = GetRightFakeHwnd(); |
| 756 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 757 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 758 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 759 ScreenWin::ClientToDIPRect(right_hwnd, |
| 760 gfx::Rect(253, 496, 41, 52))); |
| 761 } |
| 762 |
| 763 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientRects) { |
| 764 HWND left_hwnd = GetLeftFakeHwnd(); |
| 765 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 766 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 767 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 768 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 769 |
| 770 HWND right_hwnd = GetRightFakeHwnd(); |
| 771 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 772 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 773 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 774 ScreenWin::DIPToClientRect(right_hwnd, |
| 775 gfx::Rect(126, 248, 21, 26))); |
| 776 } |
| 777 |
| 778 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor. |
| 779 class ScreenWinTestTwoDisplays2x1x : public ScreenWinTest { |
| 780 public: |
| 781 static void SetUpTestCase() { |
| 782 ScreenWinTest::SetUpTestCase(); |
| 783 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 784 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 785 gfx::Rect(0, 0, 1920, 1100), |
| 786 L"primary", |
| 787 2.0); |
| 788 screen_win_initializer_->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 789 gfx::Rect(1920, 0, 800, 600), |
| 790 L"secondary", |
| 791 1.0); |
| 792 fake_hwnd_left_ = |
| 793 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 794 fake_hwnd_right_ = |
| 795 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 796 screen_win_initializer_->InitializeScreenWin(); |
| 797 } |
| 798 |
| 799 static void TearDownTestCase() { |
| 800 screen_win_initializer_.reset(); |
| 801 ScreenWinTest::TearDownTestCase(); |
| 802 } |
| 803 |
| 804 Screen* GetScreen() { |
| 805 return screen_win_initializer_->GetScreen(); |
| 806 } |
| 807 |
| 808 HWND GetLeftFakeHwnd() { |
| 809 return fake_hwnd_left_; |
| 810 } |
| 811 |
| 812 HWND GetRightFakeHwnd() { |
| 813 return fake_hwnd_right_; |
| 814 } |
| 815 |
| 816 private: |
| 817 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 818 static HWND fake_hwnd_left_; |
| 819 static HWND fake_hwnd_right_; |
| 820 }; |
| 821 |
| 822 scoped_ptr<TestScreenWinInitializer> |
| 823 ScreenWinTestTwoDisplays2x1x::screen_win_initializer_; |
| 824 |
| 825 HWND ScreenWinTestTwoDisplays2x1x::fake_hwnd_left_ = NULL; |
| 826 |
| 827 HWND ScreenWinTestTwoDisplays2x1x::fake_hwnd_right_ = NULL; |
| 828 |
| 829 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplays) { |
| 830 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 831 ASSERT_EQ(2u, displays.size()); |
| 832 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 833 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 834 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].bounds()); |
| 835 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].work_area()); |
| 836 } |
| 837 |
| 838 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPRects) { |
| 839 HWND left_hwnd = GetLeftFakeHwnd(); |
| 840 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 841 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 842 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 843 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 844 |
| 845 HWND right_hwnd = GetRightFakeHwnd(); |
| 846 EXPECT_EQ(gfx::Rect(960, 0, 200, 300), |
| 847 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 848 gfx::Rect(1920, 0, 200, 300))); |
| 849 EXPECT_EQ(gfx::Rect(1040, 496, 100, 200), |
| 850 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 851 gfx::Rect(2000, 496, 100, 200))); |
| 852 } |
| 853 |
| 854 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenRects) { |
| 855 HWND left_hwnd = GetLeftFakeHwnd(); |
| 856 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 857 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 858 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 859 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 860 |
| 861 HWND right_hwnd = GetRightFakeHwnd(); |
| 862 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 863 ScreenWin::DIPToScreenRect(right_hwnd, |
| 864 gfx::Rect(960, 0, 200, 300))); |
| 865 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 866 ScreenWin::DIPToScreenRect(right_hwnd, |
| 867 gfx::Rect(1040, 496, 100, 200))); |
| 868 } |
| 869 |
| 870 TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPRects) { |
| 871 HWND left_hwnd = GetLeftFakeHwnd(); |
| 872 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 873 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 874 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 875 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 876 |
| 877 HWND right_hwnd = GetRightFakeHwnd(); |
| 878 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 879 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 880 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 881 ScreenWin::ClientToDIPRect(right_hwnd, |
| 882 gfx::Rect(253, 496, 41, 52))); |
| 883 } |
| 884 |
| 885 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientRects) { |
| 886 HWND left_hwnd = GetLeftFakeHwnd(); |
| 887 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 888 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 889 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 890 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 891 |
| 892 HWND right_hwnd = GetRightFakeHwnd(); |
| 893 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 894 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 895 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 896 ScreenWin::DIPToClientRect(right_hwnd, |
| 897 gfx::Rect(253, 496, 41, 52))); |
| 898 } |
| 899 |
| 900 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under |
| 901 // Windows DPI Virtualization. Note that the displays do not form a euclidean |
| 902 // space. |
| 903 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
| 904 public: |
| 905 static void SetUpTestCase() { |
| 906 ScreenWinTest::SetUpTestCase(); |
| 907 screen_win_initializer_.reset(new TestScreenWinInitializer()); |
| 908 screen_win_initializer_->AddMonitor(gfx::Rect(0, 0, 3200, 1600), |
| 909 gfx::Rect(0, 0, 3200, 1500), |
| 910 L"primary", |
| 911 2.0); |
| 912 screen_win_initializer_->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), |
| 913 gfx::Rect(6400, 0, 3840, 2400), |
| 914 L"secondary", |
| 915 2.0); |
| 916 fake_hwnd_left_ = |
| 917 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); |
| 918 fake_hwnd_right_ = |
| 919 screen_win_initializer_->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); |
| 920 screen_win_initializer_->InitializeScreenWin(); |
| 921 } |
| 922 |
| 923 static void TearDownTestCase() { |
| 924 screen_win_initializer_.reset(); |
| 925 ScreenWinTest::TearDownTestCase(); |
| 926 } |
| 927 |
| 928 Screen* GetScreen() { |
| 929 return screen_win_initializer_->GetScreen(); |
| 930 } |
| 931 |
| 932 HWND GetLeftFakeHwnd() { |
| 933 return fake_hwnd_left_; |
| 934 } |
| 935 |
| 936 HWND GetRightFakeHwnd() { |
| 937 return fake_hwnd_right_; |
| 938 } |
| 939 |
| 940 private: |
| 941 static scoped_ptr<TestScreenWinInitializer> screen_win_initializer_; |
| 942 static HWND fake_hwnd_left_; |
| 943 static HWND fake_hwnd_right_; |
| 944 }; |
| 945 |
| 946 scoped_ptr<TestScreenWinInitializer> |
| 947 ScreenWinTestTwoDisplays2x1xVirtualized::screen_win_initializer_; |
| 948 |
| 949 HWND ScreenWinTestTwoDisplays2x1xVirtualized::fake_hwnd_left_ = NULL; |
| 950 |
| 951 HWND ScreenWinTestTwoDisplays2x1xVirtualized::fake_hwnd_right_ = NULL; |
| 952 |
| 953 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { |
| 954 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 955 ASSERT_EQ(2u, displays.size()); |
| 956 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); |
| 957 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); |
| 958 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); |
| 959 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); |
| 960 } |
| 961 |
| 962 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ScreenToDIPRects) { |
| 963 HWND left_hwnd = GetLeftFakeHwnd(); |
| 964 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 965 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 966 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 967 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 968 |
| 969 HWND right_hwnd = GetRightFakeHwnd(); |
| 970 EXPECT_EQ(gfx::Rect(3200, 0, 100, 150), |
| 971 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 972 gfx::Rect(6400, 0, 200, 300))); |
| 973 EXPECT_EQ(gfx::Rect(3500, 248, 50, 100), |
| 974 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 975 gfx::Rect(7000, 496, 100, 200))); |
| 976 } |
| 977 |
| 978 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToScreenRects) { |
| 979 HWND left_hwnd = GetLeftFakeHwnd(); |
| 980 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 981 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 982 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 983 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 984 |
| 985 HWND right_hwnd = GetRightFakeHwnd(); |
| 986 EXPECT_EQ(gfx::Rect(6400, 0, 200, 300), |
| 987 ScreenWin::DIPToScreenRect(right_hwnd, |
| 988 gfx::Rect(3200, 0, 100, 150))); |
| 989 EXPECT_EQ(gfx::Rect(7000, 496, 100, 200), |
| 990 ScreenWin::DIPToScreenRect(right_hwnd, |
| 991 gfx::Rect(3500, 248, 50, 100))); |
| 992 } |
| 993 |
| 994 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ClientToDIPRects) { |
| 995 HWND left_hwnd = GetLeftFakeHwnd(); |
| 996 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 997 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 998 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 999 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1000 |
| 1001 HWND right_hwnd = GetRightFakeHwnd(); |
| 1002 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1003 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1004 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1005 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1006 gfx::Rect(253, 496, 41, 52))); |
| 1007 } |
| 1008 |
| 1009 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToClientRects) { |
| 1010 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1011 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1012 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1013 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1014 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1015 |
| 1016 HWND right_hwnd = GetRightFakeHwnd(); |
| 1017 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1018 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1019 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1020 ScreenWin::DIPToClientRect(right_hwnd, |
| 1021 gfx::Rect(126, 248, 21, 26))); |
| 1022 } |
| 1023 |
80 } // namespace gfx | 1024 } // namespace gfx |
OLD | NEW |