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