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