| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <inttypes.h> | 8 #include <inttypes.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <cwchar> | 11 #include <cwchar> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | 14 #include <unordered_map> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/command_line.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 23 #include "ui/gfx/switches.h" |
| 22 #include "ui/gfx/test/display_util.h" | 24 #include "ui/gfx/test/display_util.h" |
| 23 #include "ui/gfx/win/display_info.h" | 25 #include "ui/gfx/win/display_info.h" |
| 24 #include "ui/gfx/win/dpi.h" | 26 #include "ui/gfx/win/dpi.h" |
| 25 #include "ui/gfx/win/screen_win_display.h" | 27 #include "ui/gfx/win/screen_win_display.h" |
| 26 | 28 |
| 27 namespace gfx { | 29 namespace gfx { |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, | 33 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 HWND GetFakeHwnd() { | 242 HWND GetFakeHwnd() { |
| 241 return fake_hwnd_; | 243 return fake_hwnd_; |
| 242 } | 244 } |
| 243 | 245 |
| 244 private: | 246 private: |
| 245 HWND fake_hwnd_ = nullptr; | 247 HWND fake_hwnd_ = nullptr; |
| 246 | 248 |
| 247 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x); | 249 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1x); |
| 248 }; | 250 }; |
| 249 | 251 |
| 252 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPPoints) { |
| 253 gfx::Point origin(0, 0); |
| 254 gfx::Point middle(365, 694); |
| 255 gfx::Point lower_right(1919, 1199); |
| 256 |
| 257 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
| 258 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
| 259 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
| 260 } |
| 261 |
| 262 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenPoints) { |
| 263 gfx::Point origin(0, 0); |
| 264 gfx::Point middle(365, 694); |
| 265 gfx::Point lower_right(1919, 1199); |
| 266 |
| 267 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| 268 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| 269 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| 270 } |
| 271 |
| 272 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPPoints) { |
| 273 HWND hwnd = GetFakeHwnd(); |
| 274 |
| 275 gfx::Point origin(0, 0); |
| 276 gfx::Point middle(365, 694); |
| 277 gfx::Point lower_right(1919, 1199); |
| 278 |
| 279 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); |
| 280 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); |
| 281 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); |
| 282 } |
| 283 |
| 284 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientPoints) { |
| 285 HWND hwnd = GetFakeHwnd(); |
| 286 |
| 287 gfx::Point origin(0, 0); |
| 288 gfx::Point middle(365, 694); |
| 289 gfx::Point lower_right(1919, 1199); |
| 290 |
| 291 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); |
| 292 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); |
| 293 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); |
| 294 } |
| 295 |
| 296 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPRects) { |
| 297 HWND hwnd = GetFakeHwnd(); |
| 298 |
| 299 gfx::Rect origin(0, 0, 50, 100); |
| 300 gfx::Rect middle(253, 495, 41, 52); |
| 301 |
| 302 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); |
| 303 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); |
| 304 } |
| 305 |
| 306 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenRects) { |
| 307 HWND hwnd = GetFakeHwnd(); |
| 308 |
| 309 gfx::Rect origin(0, 0, 50, 100); |
| 310 gfx::Rect middle(253, 495, 41, 52); |
| 311 |
| 312 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); |
| 313 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); |
| 314 } |
| 315 |
| 316 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPRects) { |
| 317 HWND hwnd = GetFakeHwnd(); |
| 318 |
| 319 gfx::Rect origin(0, 0, 50, 100); |
| 320 gfx::Rect middle(253, 495, 41, 52); |
| 321 |
| 322 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); |
| 323 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); |
| 324 } |
| 325 |
| 326 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientRects) { |
| 327 HWND hwnd = GetFakeHwnd(); |
| 328 |
| 329 gfx::Rect origin(0, 0, 50, 100); |
| 330 gfx::Rect middle(253, 495, 41, 52); |
| 331 |
| 332 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); |
| 333 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); |
| 334 } |
| 335 |
| 336 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPSize) { |
| 337 HWND hwnd = GetFakeHwnd(); |
| 338 |
| 339 gfx::Size size(42, 131); |
| 340 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); |
| 341 } |
| 342 |
| 343 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenSize) { |
| 344 HWND hwnd = GetFakeHwnd(); |
| 345 |
| 346 gfx::Size size(42, 131); |
| 347 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); |
| 348 } |
| 349 |
| 250 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { | 350 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { |
| 251 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 351 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 252 ASSERT_EQ(1u, displays.size()); | 352 ASSERT_EQ(1u, displays.size()); |
| 253 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 353 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 254 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 354 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 255 } | 355 } |
| 256 | 356 |
| 257 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { | 357 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { |
| 258 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); | 358 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); |
| 259 } | 359 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 gfx::Screen* screen = GetScreen(); | 391 gfx::Screen* screen = GetScreen(); |
| 292 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 392 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 293 } | 393 } |
| 294 | 394 |
| 295 // Single Display of 1.25 Device Scale Factor. | 395 // Single Display of 1.25 Device Scale Factor. |
| 296 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { | 396 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { |
| 297 public: | 397 public: |
| 298 ScreenWinTestSingleDisplay1_25x() = default; | 398 ScreenWinTestSingleDisplay1_25x() = default; |
| 299 | 399 |
| 300 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 400 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 301 gfx::SetDefaultDeviceScaleFactor(1.25); | |
| 302 // Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the | 401 // Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the |
| 303 // clamping and not ScreenWin. | 402 // clamping and not ScreenWin. |
| 304 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 403 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 305 gfx::Rect(0, 0, 1920, 1100), | 404 gfx::Rect(0, 0, 1920, 1100), |
| 306 L"primary", | 405 L"primary", |
| 307 1.0); | 406 1.0); |
| 308 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 407 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 309 } | 408 } |
| 310 | 409 |
| 311 HWND GetFakeHwnd() { | 410 HWND GetFakeHwnd() { |
| 312 return fake_hwnd_; | 411 return fake_hwnd_; |
| 313 } | 412 } |
| 314 | 413 |
| 315 private: | 414 private: |
| 316 HWND fake_hwnd_ = nullptr; | 415 HWND fake_hwnd_ = nullptr; |
| 317 | 416 |
| 318 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); | 417 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); |
| 319 }; | 418 }; |
| 320 | 419 |
| 420 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPPoints) { |
| 421 gfx::Point origin(0, 0); |
| 422 gfx::Point middle(365, 694); |
| 423 gfx::Point lower_right(1919, 1199); |
| 424 |
| 425 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
| 426 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
| 427 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
| 428 } |
| 429 |
| 430 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenPoints) { |
| 431 gfx::Point origin(0, 0); |
| 432 gfx::Point middle(365, 694); |
| 433 gfx::Point lower_right(1919, 1199); |
| 434 |
| 435 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| 436 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| 437 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| 438 } |
| 439 |
| 440 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPPoints) { |
| 441 HWND hwnd = GetFakeHwnd(); |
| 442 |
| 443 gfx::Point origin(0, 0); |
| 444 gfx::Point middle(365, 694); |
| 445 gfx::Point lower_right(1919, 1199); |
| 446 |
| 447 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); |
| 448 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); |
| 449 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); |
| 450 } |
| 451 |
| 452 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientPoints) { |
| 453 HWND hwnd = GetFakeHwnd(); |
| 454 |
| 455 gfx::Point origin(0, 0); |
| 456 gfx::Point middle(365, 694); |
| 457 gfx::Point lower_right(1919, 1199); |
| 458 |
| 459 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); |
| 460 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); |
| 461 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); |
| 462 } |
| 463 |
| 464 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPRects) { |
| 465 HWND hwnd = GetFakeHwnd(); |
| 466 |
| 467 gfx::Rect origin(0, 0, 50, 100); |
| 468 gfx::Rect middle(253, 495, 41, 52); |
| 469 |
| 470 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); |
| 471 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); |
| 472 } |
| 473 |
| 474 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenRects) { |
| 475 HWND hwnd = GetFakeHwnd(); |
| 476 |
| 477 gfx::Rect origin(0, 0, 50, 100); |
| 478 gfx::Rect middle(253, 495, 41, 52); |
| 479 |
| 480 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); |
| 481 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); |
| 482 } |
| 483 |
| 484 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPRects) { |
| 485 HWND hwnd = GetFakeHwnd(); |
| 486 |
| 487 gfx::Rect origin(0, 0, 50, 100); |
| 488 gfx::Rect middle(253, 495, 41, 52); |
| 489 |
| 490 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); |
| 491 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); |
| 492 } |
| 493 |
| 494 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientRects) { |
| 495 HWND hwnd = GetFakeHwnd(); |
| 496 |
| 497 gfx::Rect origin(0, 0, 50, 100); |
| 498 gfx::Rect middle(253, 495, 41, 52); |
| 499 |
| 500 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); |
| 501 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); |
| 502 } |
| 503 |
| 504 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPSize) { |
| 505 HWND hwnd = GetFakeHwnd(); |
| 506 |
| 507 gfx::Size size(42, 131); |
| 508 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); |
| 509 } |
| 510 |
| 511 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenSize) { |
| 512 HWND hwnd = GetFakeHwnd(); |
| 513 |
| 514 gfx::Size size(42, 131); |
| 515 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); |
| 516 } |
| 517 |
| 321 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { | 518 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { |
| 322 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 519 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 323 ASSERT_EQ(1u, displays.size()); | 520 ASSERT_EQ(1u, displays.size()); |
| 324 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. | 521 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. |
| 325 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 522 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 326 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 523 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 327 } | 524 } |
| 328 | 525 |
| 329 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { | 526 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { |
| 330 gfx::Screen* screen = GetScreen(); | 527 gfx::Screen* screen = GetScreen(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 HWND GetFakeHwnd() { | 567 HWND GetFakeHwnd() { |
| 371 return fake_hwnd_; | 568 return fake_hwnd_; |
| 372 } | 569 } |
| 373 | 570 |
| 374 private: | 571 private: |
| 375 HWND fake_hwnd_ = nullptr; | 572 HWND fake_hwnd_ = nullptr; |
| 376 | 573 |
| 377 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x); | 574 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_5x); |
| 378 }; | 575 }; |
| 379 | 576 |
| 577 TEST_F(ScreenWinTestSingleDisplay1_5x, ScreenToDIPPoints) { |
| 578 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 579 EXPECT_EQ(gfx::Point(243, 462), |
| 580 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 581 EXPECT_EQ(gfx::Point(1279, 799), |
| 582 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 583 } |
| 584 |
| 585 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToScreenPoints) { |
| 586 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 587 EXPECT_EQ(gfx::Point(364, 693), |
| 588 ScreenWin::DIPToScreenPoint(gfx::Point(243, 462))); |
| 589 EXPECT_EQ(gfx::Point(1918, 1198), |
| 590 ScreenWin::DIPToScreenPoint(gfx::Point(1279, 799))); |
| 591 } |
| 592 |
| 593 TEST_F(ScreenWinTestSingleDisplay1_5x, ClientToDIPPoints) { |
| 594 HWND hwnd = GetFakeHwnd(); |
| 595 EXPECT_EQ(gfx::Point(0, 0), |
| 596 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); |
| 597 EXPECT_EQ(gfx::Point(243, 462), |
| 598 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); |
| 599 EXPECT_EQ(gfx::Point(1279, 799), |
| 600 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); |
| 601 } |
| 602 |
| 603 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToClientPoints) { |
| 604 HWND hwnd = GetFakeHwnd(); |
| 605 EXPECT_EQ(gfx::Point(0, 0), |
| 606 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); |
| 607 EXPECT_EQ(gfx::Point(364, 693), |
| 608 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(243, 462))); |
| 609 EXPECT_EQ(gfx::Point(1918, 1198), |
| 610 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(1279, 799))); |
| 611 } |
| 612 |
| 613 TEST_F(ScreenWinTestSingleDisplay1_5x, ScreenToDIPRects) { |
| 614 HWND hwnd = GetFakeHwnd(); |
| 615 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 616 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 617 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 618 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 619 } |
| 620 |
| 621 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToScreenRects) { |
| 622 HWND hwnd = GetFakeHwnd(); |
| 623 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 624 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
| 625 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 626 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
| 627 } |
| 628 |
| 629 TEST_F(ScreenWinTestSingleDisplay1_5x, ClientToDIPRects) { |
| 630 HWND hwnd = GetFakeHwnd(); |
| 631 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 632 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 633 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 634 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 635 } |
| 636 |
| 637 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToClientRects) { |
| 638 HWND hwnd = GetFakeHwnd(); |
| 639 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 640 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
| 641 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 642 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
| 643 } |
| 644 |
| 645 TEST_F(ScreenWinTestSingleDisplay1_5x, ScreenToDIPSize) { |
| 646 EXPECT_EQ(gfx::Size(28, 88), |
| 647 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); |
| 648 } |
| 649 |
| 650 TEST_F(ScreenWinTestSingleDisplay1_5x, DIPToScreenSize) { |
| 651 EXPECT_EQ(gfx::Size(42, 132), |
| 652 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(28, 88))); |
| 653 } |
| 654 |
| 380 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) { | 655 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplays) { |
| 381 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 656 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 382 ASSERT_EQ(1u, displays.size()); | 657 ASSERT_EQ(1u, displays.size()); |
| 383 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds()); | 658 EXPECT_EQ(gfx::Rect(0, 0, 1280, 800), displays[0].bounds()); |
| 384 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area()); | 659 EXPECT_EQ(gfx::Rect(0, 0, 1280, 734), displays[0].work_area()); |
| 385 } | 660 } |
| 386 | 661 |
| 387 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) { | 662 TEST_F(ScreenWinTestSingleDisplay1_5x, GetDisplayNearestWindow) { |
| 388 gfx::Screen* screen = GetScreen(); | 663 gfx::Screen* screen = GetScreen(); |
| 389 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | 664 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 411 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 686 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 412 } | 687 } |
| 413 | 688 |
| 414 | 689 |
| 415 // Single Display of 2.0 Device Scale Factor. | 690 // Single Display of 2.0 Device Scale Factor. |
| 416 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { | 691 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
| 417 public: | 692 public: |
| 418 ScreenWinTestSingleDisplay2x() = default; | 693 ScreenWinTestSingleDisplay2x() = default; |
| 419 | 694 |
| 420 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 695 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 421 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 422 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 696 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 423 gfx::Rect(0, 0, 1920, 1100), | 697 gfx::Rect(0, 0, 1920, 1100), |
| 424 L"primary", | 698 L"primary", |
| 425 2.0); | 699 2.0); |
| 426 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 700 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 427 } | 701 } |
| 428 | 702 |
| 429 HWND GetFakeHwnd() { | 703 HWND GetFakeHwnd() { |
| 430 return fake_hwnd_; | 704 return fake_hwnd_; |
| 431 } | 705 } |
| 432 | 706 |
| 433 private: | 707 private: |
| 434 HWND fake_hwnd_ = nullptr; | 708 HWND fake_hwnd_ = nullptr; |
| 435 | 709 |
| 436 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); | 710 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); |
| 437 }; | 711 }; |
| 438 | 712 |
| 713 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPPoints) { |
| 714 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 715 EXPECT_EQ(gfx::Point(182, 347), |
| 716 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 717 EXPECT_EQ(gfx::Point(959, 599), |
| 718 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 719 } |
| 720 |
| 721 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenPoints) { |
| 722 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 723 EXPECT_EQ(gfx::Point(364, 694), |
| 724 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| 725 EXPECT_EQ(gfx::Point(1918, 1198), |
| 726 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| 727 } |
| 728 |
| 729 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPPoints) { |
| 730 HWND hwnd = GetFakeHwnd(); |
| 731 EXPECT_EQ(gfx::Point(0, 0), |
| 732 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); |
| 733 EXPECT_EQ(gfx::Point(182, 347), |
| 734 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); |
| 735 EXPECT_EQ(gfx::Point(959, 599), |
| 736 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); |
| 737 } |
| 738 |
| 739 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientPoints) { |
| 740 HWND hwnd = GetFakeHwnd(); |
| 741 EXPECT_EQ(gfx::Point(0, 0), |
| 742 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); |
| 743 EXPECT_EQ(gfx::Point(364, 694), |
| 744 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(182, 347))); |
| 745 EXPECT_EQ(gfx::Point(1918, 1198), |
| 746 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(959, 599))); |
| 747 } |
| 748 |
| 749 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPRects) { |
| 750 HWND hwnd = GetFakeHwnd(); |
| 751 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 752 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 753 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 754 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 755 } |
| 756 |
| 757 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenRects) { |
| 758 HWND hwnd = GetFakeHwnd(); |
| 759 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 760 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| 761 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 762 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| 763 } |
| 764 |
| 765 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPRects) { |
| 766 HWND hwnd = GetFakeHwnd(); |
| 767 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 768 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 769 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 770 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 771 } |
| 772 |
| 773 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientRects) { |
| 774 HWND hwnd = GetFakeHwnd(); |
| 775 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 776 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 25, 50))); |
| 777 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 778 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(126, 248, 21, 26))); |
| 779 } |
| 780 |
| 781 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPSize) { |
| 782 EXPECT_EQ(gfx::Size(21, 66), |
| 783 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); |
| 784 } |
| 785 |
| 786 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenSize) { |
| 787 EXPECT_EQ(gfx::Size(42, 132), |
| 788 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(21, 66))); |
| 789 } |
| 790 |
| 439 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { | 791 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { |
| 440 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 792 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 441 ASSERT_EQ(1u, displays.size()); | 793 ASSERT_EQ(1u, displays.size()); |
| 442 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 794 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 443 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 795 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 444 } | 796 } |
| 445 | 797 |
| 446 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) { | 798 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestWindow) { |
| 447 gfx::Screen* screen = GetScreen(); | 799 gfx::Screen* screen = GetScreen(); |
| 448 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | 800 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return fake_hwnd_right_; | 845 return fake_hwnd_right_; |
| 494 } | 846 } |
| 495 | 847 |
| 496 private: | 848 private: |
| 497 HWND fake_hwnd_left_ = nullptr; | 849 HWND fake_hwnd_left_ = nullptr; |
| 498 HWND fake_hwnd_right_ = nullptr; | 850 HWND fake_hwnd_right_ = nullptr; |
| 499 | 851 |
| 500 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); | 852 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); |
| 501 }; | 853 }; |
| 502 | 854 |
| 855 TEST_F(ScreenWinTestTwoDisplays1x, ScreenToDIPRects) { |
| 856 HWND left_hwnd = GetLeftFakeHwnd(); |
| 857 gfx::Rect left_origin(0, 0, 50, 100); |
| 858 gfx::Rect left_middle(253, 495, 41, 52); |
| 859 EXPECT_EQ(left_origin, ScreenWin::ScreenToDIPRect(left_hwnd, left_origin)); |
| 860 EXPECT_EQ(left_middle, ScreenWin::ScreenToDIPRect(left_hwnd, left_middle)); |
| 861 |
| 862 HWND right_hwnd = GetRightFakeHwnd(); |
| 863 gfx::Rect right_origin(1920, 0, 200, 300); |
| 864 gfx::Rect right_middle(2000, 496, 100, 200); |
| 865 EXPECT_EQ(right_origin, ScreenWin::ScreenToDIPRect(right_hwnd, right_origin)); |
| 866 EXPECT_EQ(right_middle, ScreenWin::ScreenToDIPRect(right_hwnd, right_middle)); |
| 867 } |
| 868 |
| 869 TEST_F(ScreenWinTestTwoDisplays1x, DIPToScreenRects) { |
| 870 HWND left_hwnd = GetLeftFakeHwnd(); |
| 871 gfx::Rect left_origin(0, 0, 50, 100); |
| 872 gfx::Rect left_middle(253, 495, 41, 52); |
| 873 EXPECT_EQ(left_origin, ScreenWin::DIPToScreenRect(left_hwnd, left_origin)); |
| 874 EXPECT_EQ(left_middle, ScreenWin::DIPToScreenRect(left_hwnd, left_middle)); |
| 875 |
| 876 HWND right_hwnd = GetRightFakeHwnd(); |
| 877 gfx::Rect right_origin(1920, 0, 200, 300); |
| 878 gfx::Rect right_middle(2000, 496, 100, 200); |
| 879 EXPECT_EQ(right_origin, ScreenWin::DIPToScreenRect(right_hwnd, right_origin)); |
| 880 EXPECT_EQ(right_middle, ScreenWin::DIPToScreenRect(right_hwnd, right_middle)); |
| 881 } |
| 882 |
| 883 TEST_F(ScreenWinTestTwoDisplays1x, ClientToDIPRects) { |
| 884 gfx::Rect origin(0, 0, 50, 100); |
| 885 gfx::Rect middle(253, 495, 41, 52); |
| 886 |
| 887 HWND left_hwnd = GetLeftFakeHwnd(); |
| 888 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(left_hwnd, origin)); |
| 889 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(left_hwnd, middle)); |
| 890 |
| 891 |
| 892 HWND right_hwnd = GetRightFakeHwnd(); |
| 893 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(right_hwnd, origin)); |
| 894 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(right_hwnd, middle)); |
| 895 } |
| 896 |
| 897 TEST_F(ScreenWinTestTwoDisplays1x, DIPToClientRects) { |
| 898 gfx::Rect origin(0, 0, 50, 100); |
| 899 gfx::Rect middle(253, 495, 41, 52); |
| 900 |
| 901 HWND left_hwnd = GetLeftFakeHwnd(); |
| 902 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(left_hwnd, origin)); |
| 903 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(left_hwnd, middle)); |
| 904 |
| 905 |
| 906 HWND right_hwnd = GetRightFakeHwnd(); |
| 907 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(right_hwnd, origin)); |
| 908 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(right_hwnd, middle)); |
| 909 } |
| 910 |
| 503 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { | 911 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { |
| 504 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 912 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 505 ASSERT_EQ(2u, displays.size()); | 913 ASSERT_EQ(2u, displays.size()); |
| 506 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 914 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 507 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 915 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 508 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); | 916 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); |
| 509 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); | 917 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); |
| 510 } | 918 } |
| 511 | 919 |
| 512 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { | 920 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 gfx::Display primary = screen->GetPrimaryDisplay(); | 977 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 570 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 978 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 571 } | 979 } |
| 572 | 980 |
| 573 // Two Displays of 2.0 Device Scale Factor. | 981 // Two Displays of 2.0 Device Scale Factor. |
| 574 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { | 982 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
| 575 public: | 983 public: |
| 576 ScreenWinTestTwoDisplays2x() = default; | 984 ScreenWinTestTwoDisplays2x() = default; |
| 577 | 985 |
| 578 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 986 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 579 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 580 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 987 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 581 gfx::Rect(0, 0, 1920, 1100), | 988 gfx::Rect(0, 0, 1920, 1100), |
| 582 L"primary", | 989 L"primary", |
| 583 2.0); | 990 2.0); |
| 584 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | 991 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 585 gfx::Rect(1920, 0, 800, 600), | 992 gfx::Rect(1920, 0, 800, 600), |
| 586 L"secondary", | 993 L"secondary", |
| 587 2.0); | 994 2.0); |
| 588 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 995 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 589 fake_hwnd_right_ = | 996 fake_hwnd_right_ = |
| 590 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | 997 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 591 } | 998 } |
| 592 | 999 |
| 593 HWND GetLeftFakeHwnd() { | 1000 HWND GetLeftFakeHwnd() { |
| 594 return fake_hwnd_left_; | 1001 return fake_hwnd_left_; |
| 595 } | 1002 } |
| 596 | 1003 |
| 597 HWND GetRightFakeHwnd() { | 1004 HWND GetRightFakeHwnd() { |
| 598 return fake_hwnd_right_; | 1005 return fake_hwnd_right_; |
| 599 } | 1006 } |
| 600 | 1007 |
| 601 private: | 1008 private: |
| 602 HWND fake_hwnd_left_ = nullptr; | 1009 HWND fake_hwnd_left_ = nullptr; |
| 603 HWND fake_hwnd_right_ = nullptr; | 1010 HWND fake_hwnd_right_ = nullptr; |
| 604 | 1011 |
| 605 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); | 1012 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); |
| 606 }; | 1013 }; |
| 607 | 1014 |
| 1015 TEST_F(ScreenWinTestTwoDisplays2x, ScreenToDIPRects) { |
| 1016 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1017 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1018 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1019 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1020 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1021 |
| 1022 HWND right_hwnd = GetRightFakeHwnd(); |
| 1023 EXPECT_EQ(gfx::Rect(960, 0, 100, 150), |
| 1024 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1025 gfx::Rect(1920, 0, 200, 300))); |
| 1026 EXPECT_EQ(gfx::Rect(1000, 248, 50, 100), |
| 1027 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1028 gfx::Rect(2000, 496, 100, 200))); |
| 1029 } |
| 1030 |
| 1031 TEST_F(ScreenWinTestTwoDisplays2x, DIPToScreenRects) { |
| 1032 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1033 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1034 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1035 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1036 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1037 |
| 1038 HWND right_hwnd = GetRightFakeHwnd(); |
| 1039 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 1040 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1041 gfx::Rect(960, 0, 100, 150))); |
| 1042 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 1043 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1044 gfx::Rect(1000, 248, 50, 100))); |
| 1045 } |
| 1046 |
| 1047 TEST_F(ScreenWinTestTwoDisplays2x, ClientToDIPRects) { |
| 1048 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1049 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1050 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1051 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1052 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1053 |
| 1054 HWND right_hwnd = GetRightFakeHwnd(); |
| 1055 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1056 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1057 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1058 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1059 gfx::Rect(253, 496, 41, 52))); |
| 1060 } |
| 1061 |
| 1062 TEST_F(ScreenWinTestTwoDisplays2x, DIPToClientRects) { |
| 1063 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1064 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1065 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1066 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1067 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1068 } |
| 1069 |
| 608 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { | 1070 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { |
| 609 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 1071 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 610 ASSERT_EQ(2u, displays.size()); | 1072 ASSERT_EQ(2u, displays.size()); |
| 611 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 1073 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 612 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 1074 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 613 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); | 1075 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); |
| 614 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); | 1076 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); |
| 615 } | 1077 } |
| 616 | 1078 |
| 617 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { | 1079 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 EXPECT_EQ(right_display, | 1126 EXPECT_EQ(right_display, |
| 665 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | 1127 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 666 } | 1128 } |
| 667 | 1129 |
| 668 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { | 1130 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { |
| 669 gfx::Screen* screen = GetScreen(); | 1131 gfx::Screen* screen = GetScreen(); |
| 670 gfx::Display primary = screen->GetPrimaryDisplay(); | 1132 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 671 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 1133 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 672 } | 1134 } |
| 673 | 1135 |
| 1136 // Two Displays of 1.0 (Left) and 2.0 (Right) Device Scale Factor. |
| 1137 class ScreenWinTestTwoDisplays1x2x : public ScreenWinTest { |
| 1138 public: |
| 1139 ScreenWinTestTwoDisplays1x2x() = default; |
| 1140 |
| 1141 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 1142 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 1143 gfx::Rect(0, 0, 1920, 1100), |
| 1144 L"primary", |
| 1145 1.0); |
| 1146 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 1147 gfx::Rect(1920, 0, 800, 600), |
| 1148 L"secondary", |
| 1149 2.0); |
| 1150 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 1151 fake_hwnd_right_ = |
| 1152 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 1153 } |
| 1154 |
| 1155 HWND GetLeftFakeHwnd() { |
| 1156 return fake_hwnd_left_; |
| 1157 } |
| 1158 |
| 1159 HWND GetRightFakeHwnd() { |
| 1160 return fake_hwnd_right_; |
| 1161 } |
| 1162 |
| 1163 private: |
| 1164 HWND fake_hwnd_left_ = nullptr; |
| 1165 HWND fake_hwnd_right_ = nullptr; |
| 1166 |
| 1167 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x2x); |
| 1168 }; |
| 1169 |
| 1170 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPRects) { |
| 1171 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1172 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1173 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1174 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1175 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1176 |
| 1177 HWND right_hwnd = GetRightFakeHwnd(); |
| 1178 EXPECT_EQ(gfx::Rect(1920, 0, 100, 150), |
| 1179 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1180 gfx::Rect(1920, 0, 200, 300))); |
| 1181 EXPECT_EQ(gfx::Rect(1960, 248, 50, 100), |
| 1182 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1183 gfx::Rect(2000, 496, 100, 200))); |
| 1184 } |
| 1185 |
| 1186 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenRects) { |
| 1187 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1188 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1189 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1190 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1191 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 1192 |
| 1193 HWND right_hwnd = GetRightFakeHwnd(); |
| 1194 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 1195 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1196 gfx::Rect(1920, 0, 100, 150))); |
| 1197 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 1198 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1199 gfx::Rect(1960, 248, 50, 100))); |
| 1200 } |
| 1201 |
| 1202 TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPRects) { |
| 1203 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1204 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1205 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1206 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1207 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1208 |
| 1209 HWND right_hwnd = GetRightFakeHwnd(); |
| 1210 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1211 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1212 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1213 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1214 gfx::Rect(253, 496, 41, 52))); |
| 1215 } |
| 1216 |
| 1217 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientRects) { |
| 1218 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1219 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1220 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1221 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1222 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); |
| 1223 |
| 1224 HWND right_hwnd = GetRightFakeHwnd(); |
| 1225 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1226 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1227 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1228 ScreenWin::DIPToClientRect(right_hwnd, |
| 1229 gfx::Rect(126, 248, 21, 26))); |
| 1230 } |
| 1231 |
| 1232 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplays) { |
| 1233 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 1234 ASSERT_EQ(2u, displays.size()); |
| 1235 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 1236 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 1237 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].bounds()); |
| 1238 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].work_area()); |
| 1239 } |
| 1240 |
| 1241 TEST_F(ScreenWinTestTwoDisplays1x2x, GetNumDisplays) { |
| 1242 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| 1243 } |
| 1244 |
| 1245 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindowPrimaryDisplay) { |
| 1246 gfx::Screen* screen = GetScreen(); |
| 1247 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 1248 screen->GetDisplayNearestWindow(nullptr)); |
| 1249 } |
| 1250 |
| 1251 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindow) { |
| 1252 gfx::Screen* screen = GetScreen(); |
| 1253 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1254 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1255 |
| 1256 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 1257 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 1258 |
| 1259 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 1260 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 1261 } |
| 1262 |
| 1263 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestPoint) { |
| 1264 gfx::Screen* screen = GetScreen(); |
| 1265 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1266 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1267 |
| 1268 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 1269 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); |
| 1270 EXPECT_EQ(left_display, |
| 1271 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); |
| 1272 |
| 1273 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); |
| 1274 EXPECT_EQ(right_display, |
| 1275 screen->GetDisplayNearestPoint(gfx::Point(2000, 200))); |
| 1276 EXPECT_EQ(right_display, |
| 1277 screen->GetDisplayNearestPoint(gfx::Point(2319, 299))); |
| 1278 } |
| 1279 |
| 1280 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayMatching) { |
| 1281 gfx::Screen* screen = GetScreen(); |
| 1282 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1283 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1284 |
| 1285 EXPECT_EQ(left_display, |
| 1286 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 1287 EXPECT_EQ(left_display, |
| 1288 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 1289 |
| 1290 EXPECT_EQ(right_display, |
| 1291 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| 1292 EXPECT_EQ(right_display, |
| 1293 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 1294 } |
| 1295 |
| 1296 TEST_F(ScreenWinTestTwoDisplays1x2x, GetPrimaryDisplay) { |
| 1297 gfx::Screen* screen = GetScreen(); |
| 1298 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 1299 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 1300 } |
| 1301 |
| 1302 // Two Displays of 1.5 (Left) and 1.0 (Right) Device Scale Factor. |
| 1303 class ScreenWinTestTwoDisplays1_5x1x : public ScreenWinTest { |
| 1304 public: |
| 1305 ScreenWinTestTwoDisplays1_5x1x() = default; |
| 1306 |
| 1307 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 1308 initializer->AddMonitor(gfx::Rect(0, 0, 800, 600), |
| 1309 gfx::Rect(0, 0, 800, 550), |
| 1310 L"primary", |
| 1311 1.5); |
| 1312 initializer->AddMonitor(gfx::Rect(800, 120, 640, 480), |
| 1313 gfx::Rect(800, 120, 640, 480), |
| 1314 L"secondary", |
| 1315 1.0); |
| 1316 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 800, 550)); |
| 1317 fake_hwnd_right_ = |
| 1318 initializer->CreateFakeHwnd(gfx::Rect(800, 120, 640, 480)); |
| 1319 } |
| 1320 |
| 1321 HWND GetLeftFakeHwnd() { |
| 1322 return fake_hwnd_left_; |
| 1323 } |
| 1324 |
| 1325 HWND GetRightFakeHwnd() { |
| 1326 return fake_hwnd_right_; |
| 1327 } |
| 1328 |
| 1329 private: |
| 1330 HWND fake_hwnd_left_ = nullptr; |
| 1331 HWND fake_hwnd_right_ = nullptr; |
| 1332 |
| 1333 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1_5x1x); |
| 1334 }; |
| 1335 |
| 1336 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ScreenToDIPRects) { |
| 1337 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1338 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 1339 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1340 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 1341 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1342 |
| 1343 HWND right_hwnd = GetRightFakeHwnd(); |
| 1344 EXPECT_EQ(gfx::Rect(534, -80, 200, 300), |
| 1345 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1346 gfx::Rect(800, 120, 200, 300))); |
| 1347 EXPECT_EQ(gfx::Rect(987, 296, 100, 200), |
| 1348 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1349 gfx::Rect(1253, 496, 100, 200))); |
| 1350 } |
| 1351 |
| 1352 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToScreenRects) { |
| 1353 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1354 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 1355 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 34, 67))); |
| 1356 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 1357 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(168, 330, 28, 36))); |
| 1358 |
| 1359 HWND right_hwnd = GetRightFakeHwnd(); |
| 1360 EXPECT_EQ(gfx::Rect(800, 120, 200, 300), |
| 1361 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1362 gfx::Rect(534, -80, 200, 300))); |
| 1363 EXPECT_EQ(gfx::Rect(1253, 496, 100, 200), |
| 1364 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1365 gfx::Rect(987, 296, 100, 200))); |
| 1366 } |
| 1367 |
| 1368 TEST_F(ScreenWinTestTwoDisplays1_5x1x, ClientToDIPRects) { |
| 1369 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1370 EXPECT_EQ(gfx::Rect(0, 0, 34, 67), |
| 1371 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1372 EXPECT_EQ(gfx::Rect(168, 330, 28, 36), |
| 1373 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1374 |
| 1375 HWND right_hwnd = GetRightFakeHwnd(); |
| 1376 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1377 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1378 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1379 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1380 gfx::Rect(253, 496, 41, 52))); |
| 1381 } |
| 1382 |
| 1383 TEST_F(ScreenWinTestTwoDisplays1_5x1x, DIPToClientRects) { |
| 1384 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1385 EXPECT_EQ(gfx::Rect(0, 0, 51, 101), |
| 1386 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 34, 67))); |
| 1387 EXPECT_EQ(gfx::Rect(252, 495, 42, 54), |
| 1388 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(168, 330, 28, 36))); |
| 1389 |
| 1390 HWND right_hwnd = GetRightFakeHwnd(); |
| 1391 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1392 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1393 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1394 ScreenWin::DIPToClientRect(right_hwnd, |
| 1395 gfx::Rect(253, 496, 41, 52))); |
| 1396 } |
| 1397 |
| 1398 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplays) { |
| 1399 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 1400 ASSERT_EQ(2u, displays.size()); |
| 1401 EXPECT_EQ(gfx::Rect(0, 0, 534, 400), displays[0].bounds()); |
| 1402 EXPECT_EQ(gfx::Rect(0, 0, 534, 367), displays[0].work_area()); |
| 1403 EXPECT_EQ(gfx::Rect(534, -80, 640, 480), displays[1].bounds()); |
| 1404 EXPECT_EQ(gfx::Rect(534, -80, 640, 480), displays[1].work_area()); |
| 1405 } |
| 1406 |
| 1407 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestWindowPrimaryDisplay) { |
| 1408 gfx::Screen* screen = GetScreen(); |
| 1409 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 1410 screen->GetDisplayNearestWindow(nullptr)); |
| 1411 } |
| 1412 |
| 1413 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestWindow) { |
| 1414 gfx::Screen* screen = GetScreen(); |
| 1415 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1416 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1417 |
| 1418 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 1419 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 1420 |
| 1421 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 1422 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 1423 } |
| 1424 |
| 1425 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayNearestPoint) { |
| 1426 gfx::Screen* screen = GetScreen(); |
| 1427 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1428 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1429 |
| 1430 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 1431 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(125, 253))); |
| 1432 EXPECT_EQ(left_display, |
| 1433 screen->GetDisplayNearestPoint(gfx::Point(533, 399))); |
| 1434 |
| 1435 EXPECT_EQ(right_display, |
| 1436 screen->GetDisplayNearestPoint(gfx::Point(534, -80))); |
| 1437 EXPECT_EQ(right_display, |
| 1438 screen->GetDisplayNearestPoint(gfx::Point(1000, 200))); |
| 1439 EXPECT_EQ(right_display, |
| 1440 screen->GetDisplayNearestPoint(gfx::Point(1173, 399))); |
| 1441 } |
| 1442 |
| 1443 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetDisplayMatching) { |
| 1444 gfx::Screen* screen = GetScreen(); |
| 1445 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1446 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1447 |
| 1448 EXPECT_EQ(left_display, |
| 1449 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 1450 EXPECT_EQ(left_display, |
| 1451 screen->GetDisplayMatching(gfx::Rect(699, 499, 100, 100))); |
| 1452 |
| 1453 EXPECT_EQ(right_display, |
| 1454 screen->GetDisplayMatching(gfx::Rect(800, 120, 100, 100))); |
| 1455 EXPECT_EQ(right_display, |
| 1456 screen->GetDisplayMatching(gfx::Rect(1339, 499, 100, 100))); |
| 1457 } |
| 1458 |
| 1459 TEST_F(ScreenWinTestTwoDisplays1_5x1x, GetPrimaryDisplay) { |
| 1460 gfx::Screen* screen = GetScreen(); |
| 1461 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 1462 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 1463 } |
| 1464 |
| 1465 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor. |
| 1466 class ScreenWinTestTwoDisplays2x1x : public ScreenWinTest { |
| 1467 public: |
| 1468 ScreenWinTestTwoDisplays2x1x() = default; |
| 1469 |
| 1470 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 1471 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 1472 gfx::Rect(0, 0, 1920, 1100), |
| 1473 L"primary", |
| 1474 2.0); |
| 1475 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 1476 gfx::Rect(1920, 0, 800, 600), |
| 1477 L"secondary", |
| 1478 1.0); |
| 1479 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 1480 fake_hwnd_right_ = |
| 1481 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 1482 } |
| 1483 |
| 1484 HWND GetLeftFakeHwnd() { |
| 1485 return fake_hwnd_left_; |
| 1486 } |
| 1487 |
| 1488 HWND GetRightFakeHwnd() { |
| 1489 return fake_hwnd_right_; |
| 1490 } |
| 1491 |
| 1492 private: |
| 1493 HWND fake_hwnd_left_ = nullptr; |
| 1494 HWND fake_hwnd_right_ = nullptr; |
| 1495 |
| 1496 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1x); |
| 1497 }; |
| 1498 |
| 1499 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPRects) { |
| 1500 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1501 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1502 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1503 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1504 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1505 |
| 1506 HWND right_hwnd = GetRightFakeHwnd(); |
| 1507 EXPECT_EQ(gfx::Rect(960, 0, 200, 300), |
| 1508 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1509 gfx::Rect(1920, 0, 200, 300))); |
| 1510 EXPECT_EQ(gfx::Rect(1040, 496, 100, 200), |
| 1511 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1512 gfx::Rect(2000, 496, 100, 200))); |
| 1513 } |
| 1514 |
| 1515 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenRects) { |
| 1516 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1517 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1518 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1519 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1520 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1521 |
| 1522 HWND right_hwnd = GetRightFakeHwnd(); |
| 1523 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), |
| 1524 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1525 gfx::Rect(960, 0, 200, 300))); |
| 1526 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), |
| 1527 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1528 gfx::Rect(1040, 496, 100, 200))); |
| 1529 } |
| 1530 |
| 1531 TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPRects) { |
| 1532 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1533 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1534 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1535 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1536 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1537 |
| 1538 HWND right_hwnd = GetRightFakeHwnd(); |
| 1539 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1540 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1541 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1542 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1543 gfx::Rect(253, 496, 41, 52))); |
| 1544 } |
| 1545 |
| 1546 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientRects) { |
| 1547 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1548 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1549 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1550 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1551 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1552 |
| 1553 HWND right_hwnd = GetRightFakeHwnd(); |
| 1554 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1555 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1556 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), |
| 1557 ScreenWin::DIPToClientRect(right_hwnd, |
| 1558 gfx::Rect(253, 496, 41, 52))); |
| 1559 } |
| 1560 |
| 1561 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplays) { |
| 1562 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 1563 ASSERT_EQ(2u, displays.size()); |
| 1564 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 1565 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 1566 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].bounds()); |
| 1567 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].work_area()); |
| 1568 } |
| 1569 |
| 1570 |
| 1571 TEST_F(ScreenWinTestTwoDisplays2x1x, GetNumDisplays) { |
| 1572 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); |
| 1573 } |
| 1574 |
| 1575 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindowPrimaryDisplay) { |
| 1576 gfx::Screen* screen = GetScreen(); |
| 1577 EXPECT_EQ(screen->GetPrimaryDisplay(), |
| 1578 screen->GetDisplayNearestWindow(nullptr)); |
| 1579 } |
| 1580 |
| 1581 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindow) { |
| 1582 gfx::Screen* screen = GetScreen(); |
| 1583 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1584 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1585 |
| 1586 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); |
| 1587 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); |
| 1588 |
| 1589 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); |
| 1590 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); |
| 1591 } |
| 1592 |
| 1593 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestPoint) { |
| 1594 gfx::Screen* screen = GetScreen(); |
| 1595 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1596 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1597 |
| 1598 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 1599 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 300))); |
| 1600 EXPECT_EQ(left_display, |
| 1601 screen->GetDisplayNearestPoint(gfx::Point(959, 599))); |
| 1602 |
| 1603 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); |
| 1604 EXPECT_EQ(right_display, |
| 1605 screen->GetDisplayNearestPoint(gfx::Point(1500, 400))); |
| 1606 EXPECT_EQ(right_display, |
| 1607 screen->GetDisplayNearestPoint(gfx::Point(1659, 599))); |
| 1608 } |
| 1609 |
| 1610 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayMatching) { |
| 1611 gfx::Screen* screen = GetScreen(); |
| 1612 const gfx::Display left_display = screen->GetAllDisplays()[0]; |
| 1613 const gfx::Display right_display = screen->GetAllDisplays()[1]; |
| 1614 |
| 1615 EXPECT_EQ(left_display, |
| 1616 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 1617 EXPECT_EQ(left_display, |
| 1618 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 1619 |
| 1620 EXPECT_EQ(right_display, |
| 1621 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); |
| 1622 EXPECT_EQ(right_display, |
| 1623 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 1624 } |
| 1625 |
| 1626 TEST_F(ScreenWinTestTwoDisplays2x1x, GetPrimaryDisplay) { |
| 1627 gfx::Screen* screen = GetScreen(); |
| 1628 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 1629 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 1630 } |
| 1631 |
| 674 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under | 1632 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under |
| 675 // Windows DPI Virtualization. Note that the displays do not form a euclidean | 1633 // Windows DPI Virtualization. Note that the displays do not form a euclidean |
| 676 // space. | 1634 // space. |
| 677 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { | 1635 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
| 678 public: | 1636 public: |
| 679 ScreenWinTestTwoDisplays2x1xVirtualized() = default; | 1637 ScreenWinTestTwoDisplays2x1xVirtualized() = default; |
| 680 | 1638 |
| 681 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 1639 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 682 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 683 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), | 1640 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), |
| 684 gfx::Rect(0, 0, 3200, 1500), | 1641 gfx::Rect(0, 0, 3200, 1500), |
| 685 L"primary", | 1642 L"primary", |
| 686 2.0); | 1643 2.0); |
| 687 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), | 1644 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), |
| 688 gfx::Rect(6400, 0, 3840, 2400), | 1645 gfx::Rect(6400, 0, 3840, 2400), |
| 689 L"secondary", | 1646 L"secondary", |
| 690 2.0); | 1647 2.0); |
| 691 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); | 1648 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); |
| 692 fake_hwnd_right_ = | 1649 fake_hwnd_right_ = |
| 693 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); | 1650 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); |
| 694 } | 1651 } |
| 695 | 1652 |
| 696 HWND GetLeftFakeHwnd() { | 1653 HWND GetLeftFakeHwnd() { |
| 697 return fake_hwnd_left_; | 1654 return fake_hwnd_left_; |
| 698 } | 1655 } |
| 699 | 1656 |
| 700 HWND GetRightFakeHwnd() { | 1657 HWND GetRightFakeHwnd() { |
| 701 return fake_hwnd_right_; | 1658 return fake_hwnd_right_; |
| 702 } | 1659 } |
| 703 | 1660 |
| 704 private: | 1661 private: |
| 705 HWND fake_hwnd_left_ = nullptr; | 1662 HWND fake_hwnd_left_ = nullptr; |
| 706 HWND fake_hwnd_right_ = nullptr; | 1663 HWND fake_hwnd_right_ = nullptr; |
| 707 | 1664 |
| 708 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); | 1665 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); |
| 709 }; | 1666 }; |
| 710 | 1667 |
| 1668 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ScreenToDIPRects) { |
| 1669 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1670 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1671 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1672 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1673 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1674 |
| 1675 HWND right_hwnd = GetRightFakeHwnd(); |
| 1676 EXPECT_EQ(gfx::Rect(3200, 0, 100, 150), |
| 1677 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1678 gfx::Rect(6400, 0, 200, 300))); |
| 1679 EXPECT_EQ(gfx::Rect(3500, 248, 50, 100), |
| 1680 ScreenWin::ScreenToDIPRect(right_hwnd, |
| 1681 gfx::Rect(7000, 496, 100, 200))); |
| 1682 } |
| 1683 |
| 1684 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToScreenRects) { |
| 1685 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1686 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1687 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1688 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1689 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1690 |
| 1691 HWND right_hwnd = GetRightFakeHwnd(); |
| 1692 EXPECT_EQ(gfx::Rect(6400, 0, 200, 300), |
| 1693 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1694 gfx::Rect(3200, 0, 100, 150))); |
| 1695 EXPECT_EQ(gfx::Rect(7000, 496, 100, 200), |
| 1696 ScreenWin::DIPToScreenRect(right_hwnd, |
| 1697 gfx::Rect(3500, 248, 50, 100))); |
| 1698 } |
| 1699 |
| 1700 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ClientToDIPRects) { |
| 1701 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1702 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1703 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1704 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1705 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); |
| 1706 |
| 1707 HWND right_hwnd = GetRightFakeHwnd(); |
| 1708 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1709 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); |
| 1710 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1711 ScreenWin::ClientToDIPRect(right_hwnd, |
| 1712 gfx::Rect(253, 496, 41, 52))); |
| 1713 } |
| 1714 |
| 1715 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToClientRects) { |
| 1716 HWND left_hwnd = GetLeftFakeHwnd(); |
| 1717 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1718 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1719 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1720 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); |
| 1721 |
| 1722 HWND right_hwnd = GetRightFakeHwnd(); |
| 1723 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1724 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); |
| 1725 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1726 ScreenWin::DIPToClientRect(right_hwnd, |
| 1727 gfx::Rect(126, 248, 21, 26))); |
| 1728 } |
| 1729 |
| 711 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { | 1730 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { |
| 712 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 1731 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 713 ASSERT_EQ(2u, displays.size()); | 1732 ASSERT_EQ(2u, displays.size()); |
| 714 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); | 1733 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); |
| 715 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); | 1734 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); |
| 716 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); | 1735 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); |
| 717 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); | 1736 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); |
| 718 } | 1737 } |
| 719 | 1738 |
| 720 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { | 1739 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 EXPECT_EQ(right_display, | 1791 EXPECT_EQ(right_display, |
| 773 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); | 1792 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); |
| 774 } | 1793 } |
| 775 | 1794 |
| 776 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { | 1795 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { |
| 777 gfx::Screen* screen = GetScreen(); | 1796 gfx::Screen* screen = GetScreen(); |
| 778 gfx::Display primary = screen->GetPrimaryDisplay(); | 1797 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 779 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 1798 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 780 } | 1799 } |
| 781 | 1800 |
| 1801 // Forced 1x DPI for Other Tests without TestScreenWin. |
| 1802 class ScreenWinUninitializedForced1x : public testing::Test { |
| 1803 public: |
| 1804 ScreenWinUninitializedForced1x() |
| 1805 : old_command_line(*base::CommandLine::ForCurrentProcess()) {} |
| 1806 |
| 1807 void SetUp() override { |
| 1808 testing::Test::SetUp(); |
| 1809 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1810 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1"); |
| 1811 } |
| 1812 |
| 1813 void TearDown() override { |
| 1814 *base::CommandLine::ForCurrentProcess() = old_command_line; |
| 1815 Display::ResetForceDeviceScaleFactorForTesting(); |
| 1816 testing::Test::TearDown(); |
| 1817 } |
| 1818 |
| 1819 private: |
| 1820 base::CommandLine old_command_line; |
| 1821 |
| 1822 DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced1x); |
| 1823 }; |
| 1824 |
| 1825 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPPoints) { |
| 1826 gfx::Point origin(0, 0); |
| 1827 gfx::Point middle(365, 694); |
| 1828 gfx::Point lower_right(1919, 1199); |
| 1829 |
| 1830 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); |
| 1831 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); |
| 1832 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); |
| 1833 } |
| 1834 |
| 1835 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenPoints) { |
| 1836 gfx::Point origin(0, 0); |
| 1837 gfx::Point middle(365, 694); |
| 1838 gfx::Point lower_right(1919, 1199); |
| 1839 |
| 1840 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); |
| 1841 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); |
| 1842 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); |
| 1843 } |
| 1844 |
| 1845 TEST_F(ScreenWinUninitializedForced1x, ClientToDIPPoints) { |
| 1846 gfx::Point origin(0, 0); |
| 1847 gfx::Point middle(365, 694); |
| 1848 gfx::Point lower_right(1919, 1199); |
| 1849 |
| 1850 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(nullptr, origin)); |
| 1851 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(nullptr, middle)); |
| 1852 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(nullptr, lower_right)); |
| 1853 } |
| 1854 |
| 1855 TEST_F(ScreenWinUninitializedForced1x, DIPToClientPoints) { |
| 1856 gfx::Point origin(0, 0); |
| 1857 gfx::Point middle(365, 694); |
| 1858 gfx::Point lower_right(1919, 1199); |
| 1859 |
| 1860 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(nullptr, origin)); |
| 1861 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(nullptr, middle)); |
| 1862 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(nullptr, lower_right)); |
| 1863 } |
| 1864 |
| 1865 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPRects) { |
| 1866 gfx::Rect origin(0, 0, 50, 100); |
| 1867 gfx::Rect middle(253, 495, 41, 52); |
| 1868 |
| 1869 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(nullptr, origin)); |
| 1870 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(nullptr, middle)); |
| 1871 } |
| 1872 |
| 1873 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenRects) { |
| 1874 gfx::Rect origin(0, 0, 50, 100); |
| 1875 gfx::Rect middle(253, 495, 41, 52); |
| 1876 |
| 1877 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(nullptr, origin)); |
| 1878 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(nullptr, middle)); |
| 1879 } |
| 1880 |
| 1881 TEST_F(ScreenWinUninitializedForced1x, ClientToDIPRects) { |
| 1882 gfx::Rect origin(0, 0, 50, 100); |
| 1883 gfx::Rect middle(253, 495, 41, 52); |
| 1884 |
| 1885 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(nullptr, origin)); |
| 1886 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(nullptr, middle)); |
| 1887 } |
| 1888 |
| 1889 TEST_F(ScreenWinUninitializedForced1x, DIPToClientRects) { |
| 1890 gfx::Rect origin(0, 0, 50, 100); |
| 1891 gfx::Rect middle(253, 495, 41, 52); |
| 1892 |
| 1893 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(nullptr, origin)); |
| 1894 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(nullptr, middle)); |
| 1895 } |
| 1896 |
| 1897 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPSize) { |
| 1898 gfx::Size size(42, 131); |
| 1899 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(nullptr, size)); |
| 1900 } |
| 1901 |
| 1902 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenSize) { |
| 1903 gfx::Size size(42, 131); |
| 1904 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(nullptr, size)); |
| 1905 } |
| 1906 |
| 1907 // Forced 2x DPI for Other Tests without TestScreenWin. |
| 1908 class ScreenWinUninitializedForced2x : public testing::Test { |
| 1909 public: |
| 1910 ScreenWinUninitializedForced2x() |
| 1911 : old_command_line(*base::CommandLine::ForCurrentProcess()) {} |
| 1912 |
| 1913 void SetUp() override { |
| 1914 testing::Test::SetUp(); |
| 1915 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1916 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); |
| 1917 } |
| 1918 |
| 1919 void TearDown() override { |
| 1920 *base::CommandLine::ForCurrentProcess() = old_command_line; |
| 1921 Display::ResetForceDeviceScaleFactorForTesting(); |
| 1922 testing::Test::TearDown(); |
| 1923 } |
| 1924 |
| 1925 private: |
| 1926 base::CommandLine old_command_line; |
| 1927 |
| 1928 DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced2x); |
| 1929 }; |
| 1930 |
| 1931 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPPoints) { |
| 1932 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 1933 EXPECT_EQ(gfx::Point(182, 347), |
| 1934 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 1935 EXPECT_EQ(gfx::Point(959, 599), |
| 1936 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 1937 } |
| 1938 |
| 1939 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenPoints) { |
| 1940 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 1941 EXPECT_EQ(gfx::Point(364, 694), |
| 1942 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); |
| 1943 EXPECT_EQ(gfx::Point(1918, 1198), |
| 1944 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); |
| 1945 } |
| 1946 |
| 1947 TEST_F(ScreenWinUninitializedForced2x, ClientToDIPPoints) { |
| 1948 EXPECT_EQ(gfx::Point(0, 0), |
| 1949 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(0, 0))); |
| 1950 EXPECT_EQ(gfx::Point(182, 347), |
| 1951 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(365, 694))); |
| 1952 EXPECT_EQ(gfx::Point(959, 599), |
| 1953 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(1919, 1199))); |
| 1954 } |
| 1955 |
| 1956 TEST_F(ScreenWinUninitializedForced2x, DIPToClientPoints) { |
| 1957 EXPECT_EQ(gfx::Point(0, 0), |
| 1958 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(0, 0))); |
| 1959 EXPECT_EQ(gfx::Point(364, 694), |
| 1960 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(182, 347))); |
| 1961 EXPECT_EQ(gfx::Point(1918, 1198), |
| 1962 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(959, 599))); |
| 1963 } |
| 1964 |
| 1965 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPRects) { |
| 1966 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1967 ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); |
| 1968 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1969 ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); |
| 1970 } |
| 1971 |
| 1972 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenRects) { |
| 1973 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1974 ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(0, 0, 25, 50))); |
| 1975 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1976 ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(126, 248, 21, 26))); |
| 1977 } |
| 1978 |
| 1979 TEST_F(ScreenWinUninitializedForced2x, ClientToDIPRects) { |
| 1980 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), |
| 1981 ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); |
| 1982 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), |
| 1983 ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); |
| 1984 } |
| 1985 |
| 1986 TEST_F(ScreenWinUninitializedForced2x, DIPToClientRects) { |
| 1987 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), |
| 1988 ScreenWin::DIPToClientRect(nullptr, gfx::Rect(0, 0, 25, 50))); |
| 1989 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), |
| 1990 ScreenWin::DIPToClientRect(nullptr, gfx::Rect(126, 248, 21, 26))); |
| 1991 } |
| 1992 |
| 1993 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPSize) { |
| 1994 EXPECT_EQ(gfx::Size(21, 66), |
| 1995 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); |
| 1996 } |
| 1997 |
| 1998 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { |
| 1999 EXPECT_EQ(gfx::Size(42, 132), |
| 2000 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); |
| 2001 } |
| 2002 |
| 782 } // namespace gfx | 2003 } // namespace gfx |
| OLD | NEW |