| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/display/win/screen_win.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 #include <inttypes.h> | |
| 9 #include <stddef.h> | |
| 10 | |
| 11 #include <cwchar> | |
| 12 #include <memory> | |
| 13 #include <string> | |
| 14 #include <unordered_map> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "base/macros.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 #include "ui/display/win/display_info.h" | |
| 20 #include "ui/display/win/screen_win_display.h" | |
| 21 #include "ui/gfx/display.h" | |
| 22 #include "ui/gfx/geometry/rect.h" | |
| 23 #include "ui/gfx/screen.h" | |
| 24 #include "ui/gfx/test/display_util.h" | |
| 25 #include "ui/gfx/win/dpi.h" | |
| 26 | |
| 27 namespace display { | |
| 28 namespace win { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, | |
| 33 gfx::Rect work, | |
| 34 std::wstring device_name) { | |
| 35 MONITORINFOEX monitor_info; | |
| 36 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); | |
| 37 monitor_info.cbSize = sizeof(monitor_info); | |
| 38 monitor_info.rcMonitor = monitor.ToRECT(); | |
| 39 monitor_info.rcWork = work.ToRECT(); | |
| 40 size_t device_char_count = ARRAYSIZE(monitor_info.szDevice); | |
| 41 wcsncpy(monitor_info.szDevice, device_name.c_str(), device_char_count); | |
| 42 monitor_info.szDevice[device_char_count-1] = L'\0'; | |
| 43 return monitor_info; | |
| 44 } | |
| 45 | |
| 46 class TestScreenWin : public ScreenWin { | |
| 47 public: | |
| 48 TestScreenWin(const std::vector<DisplayInfo>& display_infos, | |
| 49 const std::vector<MONITORINFOEX>& monitor_infos, | |
| 50 const std::unordered_map<HWND, gfx::Rect>& hwnd_map) | |
| 51 : monitor_infos_(monitor_infos), | |
| 52 hwnd_map_(hwnd_map) { | |
| 53 UpdateFromDisplayInfos(display_infos); | |
| 54 } | |
| 55 | |
| 56 ~TestScreenWin() override = default; | |
| 57 | |
| 58 protected: | |
| 59 // display::win::ScreenWin: | |
| 60 HWND GetHWNDFromNativeView(gfx::NativeView window) const override { | |
| 61 // NativeView is only used as an identifier in this tests, so interchange | |
| 62 // NativeView with an HWND for convenience. | |
| 63 return reinterpret_cast<HWND>(window); | |
| 64 } | |
| 65 | |
| 66 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const override { | |
| 67 // NativeWindow is only used as an identifier in this tests, so interchange | |
| 68 // an HWND for a NativeWindow for convenience. | |
| 69 return reinterpret_cast<gfx::NativeWindow>(hwnd); | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 void Initialize() override {} | |
| 74 | |
| 75 MONITORINFOEX MonitorInfoFromScreenPoint(const gfx::Point& screen_point) const | |
| 76 override { | |
| 77 for (const MONITORINFOEX& monitor_info : monitor_infos_) { | |
| 78 if (gfx::Rect(monitor_info.rcMonitor).Contains(screen_point)) | |
| 79 return monitor_info; | |
| 80 } | |
| 81 NOTREACHED(); | |
| 82 return monitor_infos_[0]; | |
| 83 } | |
| 84 | |
| 85 MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) const | |
| 86 override { | |
| 87 MONITORINFOEX candidate = monitor_infos_[0]; | |
| 88 int largest_area = 0; | |
| 89 for (const MONITORINFOEX& monitor_info : monitor_infos_) { | |
| 90 gfx::Rect bounds(monitor_info.rcMonitor); | |
| 91 if (bounds.Intersects(screen_rect)) { | |
| 92 bounds.Intersect(screen_rect); | |
| 93 int area = bounds.height() * bounds.width(); | |
| 94 if (largest_area < area) { | |
| 95 candidate = monitor_info; | |
| 96 largest_area = area; | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 EXPECT_NE(largest_area, 0); | |
| 101 return candidate; | |
| 102 } | |
| 103 | |
| 104 MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options) | |
| 105 const override { | |
| 106 auto search = hwnd_map_.find(hwnd); | |
| 107 if (search != hwnd_map_.end()) | |
| 108 return MonitorInfoFromScreenRect(search->second); | |
| 109 | |
| 110 EXPECT_EQ(default_options, static_cast<DWORD>(MONITOR_DEFAULTTOPRIMARY)); | |
| 111 for (const auto& monitor_info : monitor_infos_) { | |
| 112 if (monitor_info.rcMonitor.left == 0 && | |
| 113 monitor_info.rcMonitor.top == 0) { | |
| 114 return monitor_info; | |
| 115 } | |
| 116 } | |
| 117 NOTREACHED(); | |
| 118 return monitor_infos_[0]; | |
| 119 } | |
| 120 | |
| 121 HWND GetRootWindow(HWND hwnd) const override { | |
| 122 return hwnd; | |
| 123 } | |
| 124 | |
| 125 std::vector<MONITORINFOEX> monitor_infos_; | |
| 126 std::unordered_map<HWND, gfx::Rect> hwnd_map_; | |
| 127 | |
| 128 DISALLOW_COPY_AND_ASSIGN(TestScreenWin); | |
| 129 }; | |
| 130 | |
| 131 gfx::Screen* GetScreen() { | |
| 132 return gfx::Screen::GetScreen(); | |
| 133 } | |
| 134 | |
| 135 // Allows tests to specify the screen and associated state. | |
| 136 class TestScreenWinInitializer { | |
| 137 public: | |
| 138 virtual void AddMonitor(const gfx::Rect& pixel_bounds, | |
| 139 const gfx::Rect& pixel_work, | |
| 140 const wchar_t* device_name, | |
| 141 float device_scale_factor) = 0; | |
| 142 | |
| 143 virtual HWND CreateFakeHwnd(const gfx::Rect& bounds) = 0; | |
| 144 }; | |
| 145 | |
| 146 class TestScreenWinManager : public TestScreenWinInitializer { | |
| 147 public: | |
| 148 TestScreenWinManager() = default; | |
| 149 | |
| 150 ~TestScreenWinManager() { | |
| 151 gfx::Screen::SetScreenInstance(nullptr); | |
| 152 } | |
| 153 | |
| 154 void AddMonitor(const gfx::Rect& pixel_bounds, | |
| 155 const gfx::Rect& pixel_work, | |
| 156 const wchar_t* device_name, | |
| 157 float device_scale_factor) override { | |
| 158 MONITORINFOEX monitor_info = CreateMonitorInfo(pixel_bounds, | |
| 159 pixel_work, | |
| 160 device_name); | |
| 161 monitor_infos_.push_back(monitor_info); | |
| 162 display_infos_.push_back(DisplayInfo(monitor_info, | |
| 163 device_scale_factor, | |
| 164 gfx::Display::ROTATE_0)); | |
| 165 } | |
| 166 | |
| 167 HWND CreateFakeHwnd(const gfx::Rect& bounds) override { | |
| 168 EXPECT_EQ(screen_win_, nullptr); | |
| 169 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds)); | |
| 170 return hwndLast_; | |
| 171 } | |
| 172 | |
| 173 void InitializeScreenWin() { | |
| 174 ASSERT_EQ(screen_win_, nullptr); | |
| 175 screen_win_.reset(new TestScreenWin(display_infos_, | |
| 176 monitor_infos_, | |
| 177 hwnd_map_)); | |
| 178 gfx::Screen::SetScreenInstance(screen_win_.get()); | |
| 179 } | |
| 180 | |
| 181 ScreenWin* GetScreenWin() { | |
| 182 return screen_win_.get(); | |
| 183 } | |
| 184 | |
| 185 private: | |
| 186 HWND hwndLast_ = nullptr; | |
| 187 scoped_ptr<ScreenWin> screen_win_; | |
| 188 std::vector<MONITORINFOEX> monitor_infos_; | |
| 189 std::vector<DisplayInfo> display_infos_; | |
| 190 std::unordered_map<HWND, gfx::Rect> hwnd_map_; | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager); | |
| 193 }; | |
| 194 | |
| 195 class ScreenWinTest : public testing::Test { | |
| 196 protected: | |
| 197 ScreenWinTest() = default; | |
| 198 | |
| 199 void SetUp() override { | |
| 200 testing::Test::SetUp(); | |
| 201 gfx::SetDefaultDeviceScaleFactor(1.0); | |
| 202 screen_win_initializer_.reset(new TestScreenWinManager()); | |
| 203 SetUpScreen(screen_win_initializer_.get()); | |
| 204 screen_win_initializer_->InitializeScreenWin(); | |
| 205 } | |
| 206 | |
| 207 void TearDown() override { | |
| 208 screen_win_initializer_.reset(); | |
| 209 gfx::SetDefaultDeviceScaleFactor(1.0); | |
| 210 testing::Test::TearDown(); | |
| 211 } | |
| 212 | |
| 213 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0; | |
| 214 | |
| 215 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const { | |
| 216 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin(); | |
| 217 return screen_win->GetNativeWindowFromHWND(hwnd);; | |
| 218 } | |
| 219 | |
| 220 private: | |
| 221 scoped_ptr<TestScreenWinManager> screen_win_initializer_; | |
| 222 | |
| 223 DISALLOW_COPY_AND_ASSIGN(ScreenWinTest); | |
| 224 }; | |
| 225 | |
| 226 // Single Display of 1.0 Device Scale Factor. | |
| 227 class ScreenWinTestSingleDisplay1x : public ScreenWinTest { | |
| 228 public: | |
| 229 ScreenWinTestSingleDisplay1x() = default; | |
| 230 | |
| 231 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 232 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 233 gfx::Rect(0, 0, 1920, 1100), | |
| 234 L"primary", | |
| 235 1.0); | |
| 236 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 237 } | |
| 238 | |
| 239 HWND GetFakeHwnd() { | |
| 240 return fake_hwnd_; | |
| 241 } | |
| 242 | |
| 243 private: | |
| 244 HWND fake_hwnd_ = nullptr; | |
| 245 | |
| 246 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x); | |
| 247 }; | |
| 248 | |
| 249 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { | |
| 250 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 251 ASSERT_EQ(1u, displays.size()); | |
| 252 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | |
| 253 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | |
| 254 } | |
| 255 | |
| 256 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { | |
| 257 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); | |
| 258 } | |
| 259 | |
| 260 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindowPrimaryDisplay) { | |
| 261 gfx::Screen* screen = GetScreen(); | |
| 262 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 263 screen->GetDisplayNearestWindow(nullptr)); | |
| 264 } | |
| 265 | |
| 266 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestWindow) { | |
| 267 gfx::Screen* screen = GetScreen(); | |
| 268 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | |
| 269 EXPECT_EQ(screen->GetAllDisplays()[0], | |
| 270 screen->GetDisplayNearestWindow(native_window)); | |
| 271 } | |
| 272 | |
| 273 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayNearestPoint) { | |
| 274 gfx::Screen* screen = GetScreen(); | |
| 275 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 276 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 277 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); | |
| 278 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); | |
| 279 } | |
| 280 | |
| 281 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplayMatching) { | |
| 282 gfx::Screen* screen = GetScreen(); | |
| 283 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 284 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 285 EXPECT_EQ(display, | |
| 286 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 287 } | |
| 288 | |
| 289 TEST_F(ScreenWinTestSingleDisplay1x, GetPrimaryDisplay) { | |
| 290 gfx::Screen* screen = GetScreen(); | |
| 291 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | |
| 292 } | |
| 293 | |
| 294 // Single Display of 1.25 Device Scale Factor. | |
| 295 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { | |
| 296 public: | |
| 297 ScreenWinTestSingleDisplay1_25x() = default; | |
| 298 | |
| 299 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 300 gfx::SetDefaultDeviceScaleFactor(1.25); | |
| 301 // Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the | |
| 302 // clamping and not ScreenWin. | |
| 303 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 304 gfx::Rect(0, 0, 1920, 1100), | |
| 305 L"primary", | |
| 306 1.0); | |
| 307 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 308 } | |
| 309 | |
| 310 HWND GetFakeHwnd() { | |
| 311 return fake_hwnd_; | |
| 312 } | |
| 313 | |
| 314 private: | |
| 315 HWND fake_hwnd_ = nullptr; | |
| 316 | |
| 317 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); | |
| 318 }; | |
| 319 | |
| 320 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { | |
| 321 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 322 ASSERT_EQ(1u, displays.size()); | |
| 323 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. | |
| 324 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | |
| 325 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | |
| 326 } | |
| 327 | |
| 328 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { | |
| 329 gfx::Screen* screen = GetScreen(); | |
| 330 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | |
| 331 EXPECT_EQ(screen->GetAllDisplays()[0], | |
| 332 screen->GetDisplayNearestWindow(native_window)); | |
| 333 } | |
| 334 | |
| 335 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { | |
| 336 gfx::Screen* screen = GetScreen(); | |
| 337 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 338 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 339 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); | |
| 340 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); | |
| 341 } | |
| 342 | |
| 343 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) { | |
| 344 gfx::Screen* screen = GetScreen(); | |
| 345 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 346 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 347 EXPECT_EQ(display, | |
| 348 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 349 } | |
| 350 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { | |
| 351 gfx::Screen* screen = GetScreen(); | |
| 352 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | |
| 353 } | |
| 354 | |
| 355 // Single Display of 1.25 Device Scale Factor. | |
| 356 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { | |
| 357 public: | |
| 358 ScreenWinTestSingleDisplay1_5x() = default; | |
| 359 | |
| 360 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 361 gfx::SetDefaultDeviceScaleFactor(1.5); | |
| 362 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 363 gfx::Rect(0, 0, 1920, 1100), | |
| 364 L"primary", | |
| 365 1.5); | |
| 366 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 367 } | |
| 368 | |
| 369 HWND GetFakeHwnd() { | |
| 370 return fake_hwnd_; | |
| 371 } | |
| 372 | |
| 373 private: | |
| 374 HWND fake_hwnd_ = nullptr; | |
| 375 | |
| 376 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x); | |
| 377 }; | |
| 378 | |
| 379 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) { | |
| 380 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 381 ASSERT_EQ(1u, displays.size()); | |
| 382 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds()); | |
| 383 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area()); | |
| 384 } | |
| 385 | |
| 386 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) { | |
| 387 gfx::Screen* screen = GetScreen(); | |
| 388 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | |
| 389 EXPECT_EQ(screen->GetAllDisplays()[0], | |
| 390 screen->GetDisplayNearestWindow(native_window)); | |
| 391 } | |
| 392 | |
| 393 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestPoint) { | |
| 394 gfx::Screen* screen = GetScreen(); | |
| 395 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 396 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 397 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 524))); | |
| 398 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1279, 733))); | |
| 399 } | |
| 400 | |
| 401 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayMatching) { | |
| 402 gfx::Screen* screen = GetScreen(); | |
| 403 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 404 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 405 EXPECT_EQ(display, | |
| 406 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 407 } | |
| 408 TEST_F(ScreenWinTestSingleDisplay1_5x, GetPrimaryDisplay) { | |
| 409 gfx::Screen* screen = GetScreen(); | |
| 410 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | |
| 411 } | |
| 412 | |
| 413 | |
| 414 // Single Display of 2.0 Device Scale Factor. | |
| 415 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { | |
| 416 public: | |
| 417 ScreenWinTestSingleDisplay2x() = default; | |
| 418 | |
| 419 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 420 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 421 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 422 gfx::Rect(0, 0, 1920, 1100), | |
| 423 L"primary", | |
| 424 2.0); | |
| 425 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 426 } | |
| 427 | |
| 428 HWND GetFakeHwnd() { | |
| 429 return fake_hwnd_; | |
| 430 } | |
| 431 | |
| 432 private: | |
| 433 HWND fake_hwnd_ = nullptr; | |
| 434 | |
| 435 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); | |
| 436 }; | |
| 437 | |
| 438 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { | |
| 439 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 440 ASSERT_EQ(1u, displays.size()); | |
| 441 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | |
| 442 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | |
| 443 } | |
| 444 | |
| 445 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) { | |
| 446 gfx::Screen* screen = GetScreen(); | |
| 447 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | |
| 448 EXPECT_EQ(screen->GetAllDisplays()[0], | |
| 449 screen->GetDisplayNearestWindow(native_window)); | |
| 450 } | |
| 451 | |
| 452 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { | |
| 453 gfx::Screen* screen = GetScreen(); | |
| 454 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 455 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 456 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); | |
| 457 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(959, 599))); | |
| 458 } | |
| 459 | |
| 460 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayMatching) { | |
| 461 gfx::Screen* screen = GetScreen(); | |
| 462 gfx::Display display = screen->GetAllDisplays()[0]; | |
| 463 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 464 EXPECT_EQ(display, | |
| 465 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 466 } | |
| 467 | |
| 468 // Two Displays of 1.0 Device Scale Factor. | |
| 469 class ScreenWinTestTwoDisplays1x : public ScreenWinTest { | |
| 470 public: | |
| 471 ScreenWinTestTwoDisplays1x() = default; | |
| 472 | |
| 473 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 474 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 475 gfx::Rect(0, 0, 1920, 1100), | |
| 476 L"primary", | |
| 477 1.0); | |
| 478 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | |
| 479 gfx::Rect(1920, 0, 800, 600), | |
| 480 L"secondary", | |
| 481 1.0); | |
| 482 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 483 fake_hwnd_right_ = | |
| 484 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | |
| 485 } | |
| 486 | |
| 487 HWND GetLeftFakeHwnd() { | |
| 488 return fake_hwnd_left_; | |
| 489 } | |
| 490 | |
| 491 HWND GetRightFakeHwnd() { | |
| 492 return fake_hwnd_right_; | |
| 493 } | |
| 494 | |
| 495 private: | |
| 496 HWND fake_hwnd_left_ = nullptr; | |
| 497 HWND fake_hwnd_right_ = nullptr; | |
| 498 | |
| 499 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); | |
| 500 }; | |
| 501 | |
| 502 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { | |
| 503 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 504 ASSERT_EQ(2u, displays.size()); | |
| 505 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | |
| 506 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | |
| 507 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); | |
| 508 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); | |
| 509 } | |
| 510 | |
| 511 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { | |
| 512 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); | |
| 513 } | |
| 514 | |
| 515 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindowPrimaryDisplay) { | |
| 516 gfx::Screen* screen = GetScreen(); | |
| 517 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 518 screen->GetDisplayNearestWindow(nullptr)); | |
| 519 } | |
| 520 | |
| 521 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestWindow) { | |
| 522 gfx::Screen* screen = GetScreen(); | |
| 523 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 524 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 525 | |
| 526 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); | |
| 527 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); | |
| 528 | |
| 529 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); | |
| 530 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); | |
| 531 } | |
| 532 | |
| 533 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayNearestPoint) { | |
| 534 gfx::Screen* screen = GetScreen(); | |
| 535 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 536 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 537 | |
| 538 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 539 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); | |
| 540 EXPECT_EQ(left_display, | |
| 541 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); | |
| 542 | |
| 543 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); | |
| 544 EXPECT_EQ(right_display, | |
| 545 screen->GetDisplayNearestPoint(gfx::Point(2000, 400))); | |
| 546 EXPECT_EQ(right_display, | |
| 547 screen->GetDisplayNearestPoint(gfx::Point(2719, 599))); | |
| 548 } | |
| 549 | |
| 550 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplayMatching) { | |
| 551 gfx::Screen* screen = GetScreen(); | |
| 552 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 553 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 554 | |
| 555 EXPECT_EQ(left_display, | |
| 556 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 557 EXPECT_EQ(left_display, | |
| 558 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 559 | |
| 560 EXPECT_EQ(right_display, | |
| 561 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); | |
| 562 EXPECT_EQ(right_display, | |
| 563 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | |
| 564 } | |
| 565 | |
| 566 TEST_F(ScreenWinTestTwoDisplays1x, GetPrimaryDisplay) { | |
| 567 gfx::Screen* screen = GetScreen(); | |
| 568 gfx::Display primary = screen->GetPrimaryDisplay(); | |
| 569 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | |
| 570 } | |
| 571 | |
| 572 // Two Displays of 2.0 Device Scale Factor. | |
| 573 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { | |
| 574 public: | |
| 575 ScreenWinTestTwoDisplays2x() = default; | |
| 576 | |
| 577 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 578 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 579 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 580 gfx::Rect(0, 0, 1920, 1100), | |
| 581 L"primary", | |
| 582 2.0); | |
| 583 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | |
| 584 gfx::Rect(1920, 0, 800, 600), | |
| 585 L"secondary", | |
| 586 2.0); | |
| 587 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 588 fake_hwnd_right_ = | |
| 589 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | |
| 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 HWND fake_hwnd_left_ = nullptr; | |
| 602 HWND fake_hwnd_right_ = nullptr; | |
| 603 | |
| 604 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); | |
| 605 }; | |
| 606 | |
| 607 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { | |
| 608 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 609 ASSERT_EQ(2u, displays.size()); | |
| 610 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | |
| 611 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | |
| 612 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); | |
| 613 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); | |
| 614 } | |
| 615 | |
| 616 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { | |
| 617 gfx::Screen* screen = GetScreen(); | |
| 618 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 619 screen->GetDisplayNearestWindow(nullptr)); | |
| 620 } | |
| 621 | |
| 622 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindow) { | |
| 623 gfx::Screen* screen = GetScreen(); | |
| 624 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 625 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 626 | |
| 627 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); | |
| 628 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); | |
| 629 | |
| 630 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); | |
| 631 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); | |
| 632 } | |
| 633 | |
| 634 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestPoint) { | |
| 635 gfx::Screen* screen = GetScreen(); | |
| 636 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 637 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 638 | |
| 639 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 640 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); | |
| 641 EXPECT_EQ(left_display, | |
| 642 screen->GetDisplayNearestPoint(gfx::Point(959, 599))); | |
| 643 | |
| 644 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); | |
| 645 EXPECT_EQ(right_display, | |
| 646 screen->GetDisplayNearestPoint(gfx::Point(1000, 200))); | |
| 647 EXPECT_EQ(right_display, | |
| 648 screen->GetDisplayNearestPoint(gfx::Point(1359, 299))); | |
| 649 } | |
| 650 | |
| 651 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayMatching) { | |
| 652 gfx::Screen* screen = GetScreen(); | |
| 653 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 654 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 655 | |
| 656 EXPECT_EQ(left_display, | |
| 657 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 658 EXPECT_EQ(left_display, | |
| 659 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 660 | |
| 661 EXPECT_EQ(right_display, | |
| 662 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); | |
| 663 EXPECT_EQ(right_display, | |
| 664 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | |
| 665 } | |
| 666 | |
| 667 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { | |
| 668 gfx::Screen* screen = GetScreen(); | |
| 669 gfx::Display primary = screen->GetPrimaryDisplay(); | |
| 670 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | |
| 671 } | |
| 672 | |
| 673 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under | |
| 674 // Windows DPI Virtualization. Note that the displays do not form a euclidean | |
| 675 // space. | |
| 676 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { | |
| 677 public: | |
| 678 ScreenWinTestTwoDisplays2x1xVirtualized() = default; | |
| 679 | |
| 680 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 681 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 682 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), | |
| 683 gfx::Rect(0, 0, 3200, 1500), | |
| 684 L"primary", | |
| 685 2.0); | |
| 686 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), | |
| 687 gfx::Rect(6400, 0, 3840, 2400), | |
| 688 L"secondary", | |
| 689 2.0); | |
| 690 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); | |
| 691 fake_hwnd_right_ = | |
| 692 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); | |
| 693 } | |
| 694 | |
| 695 HWND GetLeftFakeHwnd() { | |
| 696 return fake_hwnd_left_; | |
| 697 } | |
| 698 | |
| 699 HWND GetRightFakeHwnd() { | |
| 700 return fake_hwnd_right_; | |
| 701 } | |
| 702 | |
| 703 private: | |
| 704 HWND fake_hwnd_left_ = nullptr; | |
| 705 HWND fake_hwnd_right_ = nullptr; | |
| 706 | |
| 707 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); | |
| 708 }; | |
| 709 | |
| 710 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { | |
| 711 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 712 ASSERT_EQ(2u, displays.size()); | |
| 713 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); | |
| 714 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); | |
| 715 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); | |
| 716 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); | |
| 717 } | |
| 718 | |
| 719 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { | |
| 720 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); | |
| 721 } | |
| 722 | |
| 723 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, | |
| 724 GetDisplayNearestWindowPrimaryDisplay) { | |
| 725 gfx::Screen* screen = GetScreen(); | |
| 726 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 727 screen->GetDisplayNearestWindow(nullptr)); | |
| 728 } | |
| 729 | |
| 730 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestWindow) { | |
| 731 gfx::Screen* screen = GetScreen(); | |
| 732 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 733 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 734 | |
| 735 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); | |
| 736 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); | |
| 737 | |
| 738 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); | |
| 739 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); | |
| 740 } | |
| 741 | |
| 742 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayNearestPoint) { | |
| 743 gfx::Screen* screen = GetScreen(); | |
| 744 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 745 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 746 | |
| 747 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 748 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 476))); | |
| 749 EXPECT_EQ(left_display, | |
| 750 screen->GetDisplayNearestPoint(gfx::Point(1599, 799))); | |
| 751 | |
| 752 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(3200, 0))); | |
| 753 EXPECT_EQ(right_display, | |
| 754 screen->GetDisplayNearestPoint(gfx::Point(4000, 400))); | |
| 755 EXPECT_EQ(right_display, | |
| 756 screen->GetDisplayNearestPoint(gfx::Point(5119, 1199))); | |
| 757 } | |
| 758 | |
| 759 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplayMatching) { | |
| 760 gfx::Screen* screen = GetScreen(); | |
| 761 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 762 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 763 | |
| 764 EXPECT_EQ(left_display, | |
| 765 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 766 EXPECT_EQ(left_display, | |
| 767 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 768 | |
| 769 EXPECT_EQ(right_display, | |
| 770 screen->GetDisplayMatching(gfx::Rect(6400, 0, 100, 100))); | |
| 771 EXPECT_EQ(right_display, | |
| 772 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); | |
| 773 } | |
| 774 | |
| 775 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { | |
| 776 gfx::Screen* screen = GetScreen(); | |
| 777 gfx::Display primary = screen->GetPrimaryDisplay(); | |
| 778 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | |
| 779 } | |
| 780 | |
| 781 } // namespace | |
| 782 | |
| 783 } // namespace win | |
| 784 } // namespace display | |
| OLD | NEW |