Chromium Code Reviews| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 } | 240 } |
| 239 | 241 |
| 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 | 249 |
| 250 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPPoints) { | |
| 251 gfx::Point origin(0, 0); | |
| 252 gfx::Point middle(365, 694); | |
| 253 gfx::Point lower_right(1919, 1199); | |
| 254 | |
| 255 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); | |
| 256 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); | |
| 257 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); | |
| 258 } | |
| 259 | |
| 260 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenPoints) { | |
| 261 gfx::Point origin(0, 0); | |
| 262 gfx::Point middle(365, 694); | |
| 263 gfx::Point lower_right(1919, 1199); | |
| 264 | |
| 265 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); | |
| 266 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); | |
| 267 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); | |
| 268 } | |
| 269 | |
| 270 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPPoints) { | |
| 271 HWND hwnd = GetFakeHwnd(); | |
| 272 | |
| 273 gfx::Point origin(0, 0); | |
| 274 gfx::Point middle(365, 694); | |
| 275 gfx::Point lower_right(1919, 1199); | |
| 276 | |
| 277 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); | |
| 278 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); | |
| 279 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); | |
| 280 } | |
| 281 | |
| 282 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientPoints) { | |
| 283 HWND hwnd = GetFakeHwnd(); | |
| 284 | |
| 285 gfx::Point origin(0, 0); | |
| 286 gfx::Point middle(365, 694); | |
| 287 gfx::Point lower_right(1919, 1199); | |
| 288 | |
| 289 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); | |
| 290 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); | |
| 291 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); | |
| 292 } | |
| 293 | |
| 294 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPRects) { | |
| 295 HWND hwnd = GetFakeHwnd(); | |
| 296 | |
| 297 gfx::Rect origin(0, 0, 50, 100); | |
| 298 gfx::Rect middle(253, 495, 41, 52); | |
| 299 | |
| 300 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); | |
| 301 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); | |
| 302 } | |
| 303 | |
| 304 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenRects) { | |
| 305 HWND hwnd = GetFakeHwnd(); | |
| 306 | |
| 307 gfx::Rect origin(0, 0, 50, 100); | |
| 308 gfx::Rect middle(253, 495, 41, 52); | |
| 309 | |
| 310 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); | |
| 311 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); | |
| 312 } | |
| 313 | |
| 314 TEST_F(ScreenWinTestSingleDisplay1x, ClientToDIPRects) { | |
| 315 HWND hwnd = GetFakeHwnd(); | |
| 316 | |
| 317 gfx::Rect origin(0, 0, 50, 100); | |
| 318 gfx::Rect middle(253, 495, 41, 52); | |
| 319 | |
| 320 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); | |
| 321 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); | |
| 322 } | |
| 323 | |
| 324 TEST_F(ScreenWinTestSingleDisplay1x, DIPToClientRects) { | |
| 325 HWND hwnd = GetFakeHwnd(); | |
| 326 | |
| 327 gfx::Rect origin(0, 0, 50, 100); | |
| 328 gfx::Rect middle(253, 495, 41, 52); | |
| 329 | |
| 330 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); | |
| 331 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); | |
| 332 } | |
| 333 | |
| 334 TEST_F(ScreenWinTestSingleDisplay1x, ScreenToDIPSize) { | |
| 335 HWND hwnd = GetFakeHwnd(); | |
| 336 | |
| 337 gfx::Size size(42, 131); | |
| 338 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); | |
| 339 } | |
| 340 | |
| 341 TEST_F(ScreenWinTestSingleDisplay1x, DIPToScreenSize) { | |
| 342 HWND hwnd = GetFakeHwnd(); | |
| 343 | |
| 344 gfx::Size size(42, 131); | |
| 345 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); | |
| 346 } | |
| 347 | |
| 248 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { | 348 TEST_F(ScreenWinTestSingleDisplay1x, GetDisplays) { |
| 249 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 349 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 250 ASSERT_EQ(1u, displays.size()); | 350 ASSERT_EQ(1u, displays.size()); |
| 251 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 351 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 252 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 352 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 253 } | 353 } |
| 254 | 354 |
| 255 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { | 355 TEST_F(ScreenWinTestSingleDisplay1x, GetNumDisplays) { |
| 256 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); | 356 EXPECT_EQ(1, GetScreen()->GetNumDisplays()); |
| 257 } | 357 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 gfx::Screen* screen = GetScreen(); | 389 gfx::Screen* screen = GetScreen(); |
| 290 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 390 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 291 } | 391 } |
| 292 | 392 |
| 293 // Single Display of 2.0 Device Scale Factor. | 393 // Single Display of 2.0 Device Scale Factor. |
| 294 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { | 394 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { |
| 295 public: | 395 public: |
| 296 ScreenWinTestSingleDisplay2x() = default; | 396 ScreenWinTestSingleDisplay2x() = default; |
| 297 | 397 |
| 298 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 398 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 299 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 300 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 399 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 301 gfx::Rect(0, 0, 1920, 1100), | 400 gfx::Rect(0, 0, 1920, 1100), |
| 302 L"primary", | 401 L"primary", |
| 303 2.0); | 402 2.0); |
| 304 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 403 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 305 } | 404 } |
| 306 | 405 |
| 307 HWND GetFakeHwnd() { | 406 HWND GetFakeHwnd() { |
| 308 return fake_hwnd_; | 407 return fake_hwnd_; |
| 309 } | 408 } |
| 310 | 409 |
| 311 private: | 410 private: |
| 312 HWND fake_hwnd_ = nullptr; | 411 HWND fake_hwnd_ = nullptr; |
| 313 | 412 |
| 314 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); | 413 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay2x); |
| 315 }; | 414 }; |
| 316 | 415 |
| 416 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPPoints) { | |
| 417 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); | |
| 418 EXPECT_EQ(gfx::Point(182, 347), | |
| 419 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); | |
| 420 EXPECT_EQ(gfx::Point(959, 599), | |
| 421 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); | |
| 422 } | |
| 423 | |
| 424 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenPoints) { | |
| 425 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); | |
| 426 EXPECT_EQ(gfx::Point(364, 694), | |
| 427 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); | |
| 428 EXPECT_EQ(gfx::Point(1918, 1198), | |
| 429 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); | |
| 430 } | |
| 431 | |
| 432 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPPoints) { | |
| 433 HWND hwnd = GetFakeHwnd(); | |
| 434 EXPECT_EQ(gfx::Point(0, 0), | |
| 435 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); | |
| 436 EXPECT_EQ(gfx::Point(182, 347), | |
| 437 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); | |
| 438 EXPECT_EQ(gfx::Point(959, 599), | |
| 439 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); | |
| 440 } | |
| 441 | |
| 442 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientPoints) { | |
| 443 HWND hwnd = GetFakeHwnd(); | |
| 444 EXPECT_EQ(gfx::Point(0, 0), | |
| 445 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); | |
| 446 EXPECT_EQ(gfx::Point(364, 694), | |
| 447 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(182, 347))); | |
| 448 EXPECT_EQ(gfx::Point(1918, 1198), | |
| 449 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(959, 599))); | |
| 450 } | |
| 451 | |
| 452 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPRects) { | |
| 453 HWND hwnd = GetFakeHwnd(); | |
| 454 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 455 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 456 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 457 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 458 } | |
| 459 | |
| 460 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenRects) { | |
| 461 HWND hwnd = GetFakeHwnd(); | |
| 462 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 463 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 464 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 465 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 466 } | |
| 467 | |
| 468 TEST_F(ScreenWinTestSingleDisplay2x, ClientToDIPRects) { | |
| 469 HWND hwnd = GetFakeHwnd(); | |
| 470 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 471 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 472 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 473 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 474 } | |
| 475 | |
| 476 TEST_F(ScreenWinTestSingleDisplay2x, DIPToClientRects) { | |
| 477 HWND hwnd = GetFakeHwnd(); | |
| 478 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 479 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 480 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 481 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 482 } | |
| 483 | |
| 484 TEST_F(ScreenWinTestSingleDisplay2x, ScreenToDIPSize) { | |
| 485 EXPECT_EQ(gfx::Size(21, 66), | |
| 486 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); | |
| 487 } | |
| 488 | |
| 489 TEST_F(ScreenWinTestSingleDisplay2x, DIPToScreenSize) { | |
| 490 EXPECT_EQ(gfx::Size(42, 132), | |
| 491 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(21, 66))); | |
| 492 } | |
| 493 | |
| 317 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { | 494 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplays) { |
| 318 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 495 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 319 ASSERT_EQ(1u, displays.size()); | 496 ASSERT_EQ(1u, displays.size()); |
| 320 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 497 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 321 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 498 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 322 } | 499 } |
| 323 | 500 |
| 324 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { | 501 TEST_F(ScreenWinTestSingleDisplay2x, GetDisplayNearestPoint) { |
| 325 gfx::Screen* screen = GetScreen(); | 502 gfx::Screen* screen = GetScreen(); |
| 326 gfx::Display display = screen->GetAllDisplays()[0]; | 503 gfx::Display display = screen->GetAllDisplays()[0]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 return fake_hwnd_right_; | 541 return fake_hwnd_right_; |
| 365 } | 542 } |
| 366 | 543 |
| 367 private: | 544 private: |
| 368 HWND fake_hwnd_left_ = nullptr; | 545 HWND fake_hwnd_left_ = nullptr; |
| 369 HWND fake_hwnd_right_ = nullptr; | 546 HWND fake_hwnd_right_ = nullptr; |
| 370 | 547 |
| 371 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); | 548 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x); |
| 372 }; | 549 }; |
| 373 | 550 |
| 551 TEST_F(ScreenWinTestTwoDisplays1x, ScreenToDIPRects) { | |
| 552 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 553 gfx::Rect left_origin(0, 0, 50, 100); | |
| 554 gfx::Rect left_middle(253, 495, 41, 52); | |
| 555 EXPECT_EQ(left_origin, ScreenWin::ScreenToDIPRect(left_hwnd, left_origin)); | |
| 556 EXPECT_EQ(left_middle, ScreenWin::ScreenToDIPRect(left_hwnd, left_middle)); | |
| 557 | |
| 558 HWND right_hwnd = GetRightFakeHwnd(); | |
| 559 gfx::Rect right_origin(1920, 0, 200, 300); | |
| 560 gfx::Rect right_middle(2000, 496, 100, 200); | |
| 561 EXPECT_EQ(right_origin, ScreenWin::ScreenToDIPRect(right_hwnd, right_origin)); | |
| 562 EXPECT_EQ(right_middle, ScreenWin::ScreenToDIPRect(right_hwnd, right_middle)); | |
| 563 } | |
| 564 | |
| 565 TEST_F(ScreenWinTestTwoDisplays1x, DIPToScreenRects) { | |
| 566 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 567 gfx::Rect left_origin(0, 0, 50, 100); | |
| 568 gfx::Rect left_middle(253, 495, 41, 52); | |
| 569 EXPECT_EQ(left_origin, ScreenWin::DIPToScreenRect(left_hwnd, left_origin)); | |
| 570 EXPECT_EQ(left_middle, ScreenWin::DIPToScreenRect(left_hwnd, left_middle)); | |
| 571 | |
| 572 HWND right_hwnd = GetRightFakeHwnd(); | |
| 573 gfx::Rect right_origin(1920, 0, 200, 300); | |
| 574 gfx::Rect right_middle(2000, 496, 100, 200); | |
| 575 EXPECT_EQ(right_origin, ScreenWin::DIPToScreenRect(right_hwnd, right_origin)); | |
| 576 EXPECT_EQ(right_middle, ScreenWin::DIPToScreenRect(right_hwnd, right_middle)); | |
| 577 } | |
| 578 | |
| 579 TEST_F(ScreenWinTestTwoDisplays1x, ClientToDIPRects) { | |
| 580 gfx::Rect origin(0, 0, 50, 100); | |
| 581 gfx::Rect middle(253, 495, 41, 52); | |
| 582 | |
| 583 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 584 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(left_hwnd, origin)); | |
| 585 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(left_hwnd, middle)); | |
| 586 | |
| 587 | |
| 588 HWND right_hwnd = GetRightFakeHwnd(); | |
| 589 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(right_hwnd, origin)); | |
| 590 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(right_hwnd, middle)); | |
| 591 } | |
| 592 | |
| 593 TEST_F(ScreenWinTestTwoDisplays1x, DIPToClientRects) { | |
| 594 gfx::Rect origin(0, 0, 50, 100); | |
| 595 gfx::Rect middle(253, 495, 41, 52); | |
| 596 | |
| 597 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 598 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(left_hwnd, origin)); | |
| 599 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(left_hwnd, middle)); | |
| 600 | |
| 601 | |
| 602 HWND right_hwnd = GetRightFakeHwnd(); | |
| 603 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(right_hwnd, origin)); | |
| 604 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(right_hwnd, middle)); | |
| 605 } | |
| 606 | |
| 374 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { | 607 TEST_F(ScreenWinTestTwoDisplays1x, GetDisplays) { |
| 375 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 608 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 376 ASSERT_EQ(2u, displays.size()); | 609 ASSERT_EQ(2u, displays.size()); |
| 377 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 610 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); |
| 378 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | 611 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); |
| 379 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); | 612 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].bounds()); |
| 380 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); | 613 EXPECT_EQ(gfx::Rect(1920, 0, 800, 600), displays[1].work_area()); |
| 381 } | 614 } |
| 382 | 615 |
| 383 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { | 616 TEST_F(ScreenWinTestTwoDisplays1x, GetNumDisplays) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 gfx::Display primary = screen->GetPrimaryDisplay(); | 673 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 441 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 674 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 442 } | 675 } |
| 443 | 676 |
| 444 // Two Displays of 2.0 Device Scale Factor. | 677 // Two Displays of 2.0 Device Scale Factor. |
| 445 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { | 678 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { |
| 446 public: | 679 public: |
| 447 ScreenWinTestTwoDisplays2x() = default; | 680 ScreenWinTestTwoDisplays2x() = default; |
| 448 | 681 |
| 449 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 682 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 450 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 451 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 683 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 452 gfx::Rect(0, 0, 1920, 1100), | 684 gfx::Rect(0, 0, 1920, 1100), |
| 453 L"primary", | 685 L"primary", |
| 454 2.0); | 686 2.0); |
| 455 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | 687 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), |
| 456 gfx::Rect(1920, 0, 800, 600), | 688 gfx::Rect(1920, 0, 800, 600), |
| 457 L"secondary", | 689 L"secondary", |
| 458 2.0); | 690 2.0); |
| 459 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 691 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 460 fake_hwnd_right_ = | 692 fake_hwnd_right_ = |
| 461 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | 693 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); |
| 462 } | 694 } |
| 463 | 695 |
| 464 HWND GetLeftFakeHwnd() { | 696 HWND GetLeftFakeHwnd() { |
| 465 return fake_hwnd_left_; | 697 return fake_hwnd_left_; |
| 466 } | 698 } |
| 467 | 699 |
| 468 HWND GetRightFakeHwnd() { | 700 HWND GetRightFakeHwnd() { |
| 469 return fake_hwnd_right_; | 701 return fake_hwnd_right_; |
| 470 } | 702 } |
| 471 | 703 |
| 472 private: | 704 private: |
| 473 HWND fake_hwnd_left_ = nullptr; | 705 HWND fake_hwnd_left_ = nullptr; |
| 474 HWND fake_hwnd_right_ = nullptr; | 706 HWND fake_hwnd_right_ = nullptr; |
| 475 | 707 |
| 476 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); | 708 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x); |
| 477 }; | 709 }; |
| 478 | 710 |
| 711 TEST_F(ScreenWinTestTwoDisplays2x, ScreenToDIPRects) { | |
|
scottmg
2016/02/09 20:21:36
Maybe a couple fractional scale tests here to codi
robliao
2016/02/10 22:50:03
Done.
| |
| 712 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 713 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 714 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 715 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 716 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 717 | |
| 718 HWND right_hwnd = GetRightFakeHwnd(); | |
| 719 EXPECT_EQ(gfx::Rect(960, 0, 100, 150), | |
| 720 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 721 gfx::Rect(1920, 0, 200, 300))); | |
| 722 EXPECT_EQ(gfx::Rect(1000, 248, 50, 100), | |
| 723 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 724 gfx::Rect(2000, 496, 100, 200))); | |
| 725 } | |
| 726 | |
| 727 TEST_F(ScreenWinTestTwoDisplays2x, DIPToScreenRects) { | |
| 728 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 729 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 730 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 731 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 732 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 733 | |
| 734 HWND right_hwnd = GetRightFakeHwnd(); | |
| 735 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), | |
| 736 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 737 gfx::Rect(960, 0, 100, 150))); | |
| 738 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), | |
| 739 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 740 gfx::Rect(1000, 248, 50, 100))); | |
| 741 } | |
| 742 | |
| 743 TEST_F(ScreenWinTestTwoDisplays2x, ClientToDIPRects) { | |
| 744 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 745 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 746 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 747 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 748 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 749 | |
| 750 HWND right_hwnd = GetRightFakeHwnd(); | |
| 751 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 752 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 753 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 754 ScreenWin::ClientToDIPRect(right_hwnd, | |
| 755 gfx::Rect(253, 496, 41, 52))); | |
| 756 } | |
| 757 | |
| 758 TEST_F(ScreenWinTestTwoDisplays2x, DIPToClientRects) { | |
| 759 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 760 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 761 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 762 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 763 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 764 } | |
| 765 | |
| 479 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { | 766 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplays) { |
| 480 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 767 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 481 ASSERT_EQ(2u, displays.size()); | 768 ASSERT_EQ(2u, displays.size()); |
| 482 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | 769 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); |
| 483 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | 770 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); |
| 484 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); | 771 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].bounds()); |
| 485 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); | 772 EXPECT_EQ(gfx::Rect(960, 0, 400, 300), displays[1].work_area()); |
| 486 } | 773 } |
| 487 | 774 |
| 488 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { | 775 TEST_F(ScreenWinTestTwoDisplays2x, GetDisplayNearestWindowPrimaryDisplay) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 EXPECT_EQ(right_display, | 822 EXPECT_EQ(right_display, |
| 536 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | 823 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); |
| 537 } | 824 } |
| 538 | 825 |
| 539 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { | 826 TEST_F(ScreenWinTestTwoDisplays2x, GetPrimaryDisplay) { |
| 540 gfx::Screen* screen = GetScreen(); | 827 gfx::Screen* screen = GetScreen(); |
| 541 gfx::Display primary = screen->GetPrimaryDisplay(); | 828 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 542 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 829 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 543 } | 830 } |
| 544 | 831 |
| 832 // Two Displays of 1.0 (Left) and 2.0 (Right) Device Scale Factor. | |
| 833 class ScreenWinTestTwoDisplays1x2x : public ScreenWinTest { | |
| 834 public: | |
| 835 ScreenWinTestTwoDisplays1x2x() = default; | |
| 836 | |
| 837 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 838 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 839 gfx::Rect(0, 0, 1920, 1100), | |
| 840 L"primary", | |
| 841 1.0); | |
| 842 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | |
| 843 gfx::Rect(1920, 0, 800, 600), | |
| 844 L"secondary", | |
| 845 2.0); | |
| 846 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 847 fake_hwnd_right_ = | |
| 848 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | |
| 849 } | |
| 850 | |
| 851 HWND GetLeftFakeHwnd() { | |
| 852 return fake_hwnd_left_; | |
| 853 } | |
| 854 | |
| 855 HWND GetRightFakeHwnd() { | |
| 856 return fake_hwnd_right_; | |
| 857 } | |
| 858 | |
| 859 private: | |
| 860 HWND fake_hwnd_left_ = nullptr; | |
| 861 HWND fake_hwnd_right_ = nullptr; | |
| 862 | |
| 863 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays1x2x); | |
| 864 }; | |
| 865 | |
| 866 TEST_F(ScreenWinTestTwoDisplays1x2x, ScreenToDIPRects) { | |
| 867 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 868 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 869 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 870 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), | |
| 871 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 872 | |
| 873 HWND right_hwnd = GetRightFakeHwnd(); | |
| 874 EXPECT_EQ(gfx::Rect(1920, 0, 100, 150), | |
| 875 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 876 gfx::Rect(1920, 0, 200, 300))); | |
| 877 EXPECT_EQ(gfx::Rect(1960, 248, 50, 100), | |
| 878 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 879 gfx::Rect(2000, 496, 100, 200))); | |
| 880 } | |
| 881 | |
| 882 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToScreenRects) { | |
| 883 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 884 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 885 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 886 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 887 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); | |
| 888 | |
| 889 HWND right_hwnd = GetRightFakeHwnd(); | |
| 890 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), | |
| 891 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 892 gfx::Rect(1920, 0, 100, 150))); | |
| 893 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), | |
| 894 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 895 gfx::Rect(1960, 248, 50, 100))); | |
| 896 } | |
| 897 | |
| 898 TEST_F(ScreenWinTestTwoDisplays1x2x, ClientToDIPRects) { | |
| 899 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 900 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 901 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 902 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), | |
| 903 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 904 | |
| 905 HWND right_hwnd = GetRightFakeHwnd(); | |
| 906 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 907 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 908 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 909 ScreenWin::ClientToDIPRect(right_hwnd, | |
| 910 gfx::Rect(253, 496, 41, 52))); | |
| 911 } | |
| 912 | |
| 913 TEST_F(ScreenWinTestTwoDisplays1x2x, DIPToClientRects) { | |
| 914 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 915 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 916 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 917 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 918 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(252, 496, 42, 52))); | |
| 919 | |
| 920 HWND right_hwnd = GetRightFakeHwnd(); | |
| 921 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 922 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 923 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 924 ScreenWin::DIPToClientRect(right_hwnd, | |
| 925 gfx::Rect(126, 248, 21, 26))); | |
| 926 } | |
| 927 | |
| 928 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplays) { | |
| 929 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 930 ASSERT_EQ(2u, displays.size()); | |
| 931 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | |
| 932 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | |
| 933 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].bounds()); | |
| 934 EXPECT_EQ(gfx::Rect(1920, 0, 400, 300), displays[1].work_area()); | |
| 935 } | |
| 936 | |
| 937 TEST_F(ScreenWinTestTwoDisplays1x2x, GetNumDisplays) { | |
| 938 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); | |
| 939 } | |
| 940 | |
| 941 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindowPrimaryDisplay) { | |
| 942 gfx::Screen* screen = GetScreen(); | |
| 943 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 944 screen->GetDisplayNearestWindow(nullptr)); | |
| 945 } | |
| 946 | |
| 947 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestWindow) { | |
| 948 gfx::Screen* screen = GetScreen(); | |
| 949 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 950 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 951 | |
| 952 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); | |
| 953 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); | |
| 954 | |
| 955 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); | |
| 956 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); | |
| 957 } | |
| 958 | |
| 959 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayNearestPoint) { | |
| 960 gfx::Screen* screen = GetScreen(); | |
| 961 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 962 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 963 | |
| 964 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 965 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); | |
| 966 EXPECT_EQ(left_display, | |
| 967 screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); | |
| 968 | |
| 969 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(1920, 0))); | |
| 970 EXPECT_EQ(right_display, | |
| 971 screen->GetDisplayNearestPoint(gfx::Point(2000, 200))); | |
| 972 EXPECT_EQ(right_display, | |
| 973 screen->GetDisplayNearestPoint(gfx::Point(2319, 299))); | |
| 974 } | |
| 975 | |
| 976 TEST_F(ScreenWinTestTwoDisplays1x2x, GetDisplayMatching) { | |
| 977 gfx::Screen* screen = GetScreen(); | |
| 978 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 979 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 980 | |
| 981 EXPECT_EQ(left_display, | |
| 982 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 983 EXPECT_EQ(left_display, | |
| 984 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 985 | |
| 986 EXPECT_EQ(right_display, | |
| 987 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); | |
| 988 EXPECT_EQ(right_display, | |
| 989 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | |
| 990 } | |
| 991 | |
| 992 TEST_F(ScreenWinTestTwoDisplays1x2x, GetPrimaryDisplay) { | |
| 993 gfx::Screen* screen = GetScreen(); | |
| 994 gfx::Display primary = screen->GetPrimaryDisplay(); | |
| 995 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | |
| 996 } | |
| 997 | |
| 998 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor. | |
| 999 class ScreenWinTestTwoDisplays2x1x : public ScreenWinTest { | |
| 1000 public: | |
| 1001 ScreenWinTestTwoDisplays2x1x() = default; | |
| 1002 | |
| 1003 void SetUpScreen(TestScreenWinInitializer* initializer) override { | |
| 1004 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | |
| 1005 gfx::Rect(0, 0, 1920, 1100), | |
| 1006 L"primary", | |
| 1007 2.0); | |
| 1008 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), | |
| 1009 gfx::Rect(1920, 0, 800, 600), | |
| 1010 L"secondary", | |
| 1011 1.0); | |
| 1012 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | |
| 1013 fake_hwnd_right_ = | |
| 1014 initializer->CreateFakeHwnd(gfx::Rect(1920, 0, 800, 600)); | |
| 1015 } | |
| 1016 | |
| 1017 HWND GetLeftFakeHwnd() { | |
| 1018 return fake_hwnd_left_; | |
| 1019 } | |
| 1020 | |
| 1021 HWND GetRightFakeHwnd() { | |
| 1022 return fake_hwnd_right_; | |
| 1023 } | |
| 1024 | |
| 1025 private: | |
| 1026 HWND fake_hwnd_left_ = nullptr; | |
| 1027 HWND fake_hwnd_right_ = nullptr; | |
| 1028 | |
| 1029 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1x); | |
| 1030 }; | |
| 1031 | |
| 1032 TEST_F(ScreenWinTestTwoDisplays2x1x, ScreenToDIPRects) { | |
| 1033 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1034 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1035 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1036 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1037 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 1038 | |
| 1039 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1040 EXPECT_EQ(gfx::Rect(960, 0, 200, 300), | |
| 1041 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 1042 gfx::Rect(1920, 0, 200, 300))); | |
| 1043 EXPECT_EQ(gfx::Rect(1040, 496, 100, 200), | |
| 1044 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 1045 gfx::Rect(2000, 496, 100, 200))); | |
| 1046 } | |
| 1047 | |
| 1048 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToScreenRects) { | |
| 1049 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1050 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1051 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 1052 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1053 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 1054 | |
| 1055 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1056 EXPECT_EQ(gfx::Rect(1920, 0, 200, 300), | |
| 1057 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 1058 gfx::Rect(960, 0, 200, 300))); | |
| 1059 EXPECT_EQ(gfx::Rect(2000, 496, 100, 200), | |
| 1060 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 1061 gfx::Rect(1040, 496, 100, 200))); | |
| 1062 } | |
| 1063 | |
| 1064 TEST_F(ScreenWinTestTwoDisplays2x1x, ClientToDIPRects) { | |
| 1065 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1066 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1067 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1068 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1069 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 1070 | |
| 1071 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1072 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1073 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1074 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), | |
| 1075 ScreenWin::ClientToDIPRect(right_hwnd, | |
| 1076 gfx::Rect(253, 496, 41, 52))); | |
| 1077 } | |
| 1078 | |
| 1079 TEST_F(ScreenWinTestTwoDisplays2x1x, DIPToClientRects) { | |
| 1080 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1081 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1082 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 1083 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1084 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 1085 | |
| 1086 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1087 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1088 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1089 EXPECT_EQ(gfx::Rect(253, 496, 41, 52), | |
| 1090 ScreenWin::DIPToClientRect(right_hwnd, | |
| 1091 gfx::Rect(253, 496, 41, 52))); | |
| 1092 } | |
| 1093 | |
| 1094 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplays) { | |
| 1095 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | |
| 1096 ASSERT_EQ(2u, displays.size()); | |
| 1097 EXPECT_EQ(gfx::Rect(0, 0, 960, 600), displays[0].bounds()); | |
| 1098 EXPECT_EQ(gfx::Rect(0, 0, 960, 550), displays[0].work_area()); | |
| 1099 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].bounds()); | |
| 1100 EXPECT_EQ(gfx::Rect(960, 0, 800, 600), displays[1].work_area()); | |
| 1101 } | |
| 1102 | |
| 1103 | |
| 1104 TEST_F(ScreenWinTestTwoDisplays2x1x, GetNumDisplays) { | |
| 1105 EXPECT_EQ(2, GetScreen()->GetNumDisplays()); | |
| 1106 } | |
| 1107 | |
| 1108 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindowPrimaryDisplay) { | |
| 1109 gfx::Screen* screen = GetScreen(); | |
| 1110 EXPECT_EQ(screen->GetPrimaryDisplay(), | |
| 1111 screen->GetDisplayNearestWindow(nullptr)); | |
| 1112 } | |
| 1113 | |
| 1114 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestWindow) { | |
| 1115 gfx::Screen* screen = GetScreen(); | |
| 1116 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 1117 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 1118 | |
| 1119 gfx::NativeWindow left_window = GetNativeWindowFromHWND(GetLeftFakeHwnd()); | |
| 1120 EXPECT_EQ(left_display, screen->GetDisplayNearestWindow(left_window)); | |
| 1121 | |
| 1122 gfx::NativeWindow right_window = GetNativeWindowFromHWND(GetRightFakeHwnd()); | |
| 1123 EXPECT_EQ(right_display, screen->GetDisplayNearestWindow(right_window)); | |
| 1124 } | |
| 1125 | |
| 1126 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayNearestPoint) { | |
| 1127 gfx::Screen* screen = GetScreen(); | |
| 1128 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 1129 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 1130 | |
| 1131 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | |
| 1132 EXPECT_EQ(left_display, screen->GetDisplayNearestPoint(gfx::Point(250, 300))); | |
| 1133 EXPECT_EQ(left_display, | |
| 1134 screen->GetDisplayNearestPoint(gfx::Point(959, 599))); | |
| 1135 | |
| 1136 EXPECT_EQ(right_display, screen->GetDisplayNearestPoint(gfx::Point(960, 0))); | |
| 1137 EXPECT_EQ(right_display, | |
| 1138 screen->GetDisplayNearestPoint(gfx::Point(1500, 400))); | |
| 1139 EXPECT_EQ(right_display, | |
| 1140 screen->GetDisplayNearestPoint(gfx::Point(1659, 599))); | |
| 1141 } | |
| 1142 | |
| 1143 TEST_F(ScreenWinTestTwoDisplays2x1x, GetDisplayMatching) { | |
| 1144 gfx::Screen* screen = GetScreen(); | |
| 1145 const gfx::Display left_display = screen->GetAllDisplays()[0]; | |
| 1146 const gfx::Display right_display = screen->GetAllDisplays()[1]; | |
| 1147 | |
| 1148 EXPECT_EQ(left_display, | |
| 1149 screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | |
| 1150 EXPECT_EQ(left_display, | |
| 1151 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | |
| 1152 | |
| 1153 EXPECT_EQ(right_display, | |
| 1154 screen->GetDisplayMatching(gfx::Rect(1920, 0, 100, 100))); | |
| 1155 EXPECT_EQ(right_display, | |
| 1156 screen->GetDisplayMatching(gfx::Rect(2619, 499, 100, 100))); | |
| 1157 } | |
| 1158 | |
| 1159 TEST_F(ScreenWinTestTwoDisplays2x1x, GetPrimaryDisplay) { | |
| 1160 gfx::Screen* screen = GetScreen(); | |
| 1161 gfx::Display primary = screen->GetPrimaryDisplay(); | |
| 1162 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | |
| 1163 } | |
| 1164 | |
| 545 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under | 1165 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under |
| 546 // Windows DPI Virtualization. Note that the displays do not form a euclidean | 1166 // Windows DPI Virtualization. Note that the displays do not form a euclidean |
| 547 // space. | 1167 // space. |
| 548 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { | 1168 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { |
| 549 public: | 1169 public: |
| 550 ScreenWinTestTwoDisplays2x1xVirtualized() = default; | 1170 ScreenWinTestTwoDisplays2x1xVirtualized() = default; |
| 551 | 1171 |
| 552 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 1172 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 553 gfx::SetDefaultDeviceScaleFactor(2.0); | |
| 554 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), | 1173 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), |
| 555 gfx::Rect(0, 0, 3200, 1500), | 1174 gfx::Rect(0, 0, 3200, 1500), |
| 556 L"primary", | 1175 L"primary", |
| 557 2.0); | 1176 2.0); |
| 558 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), | 1177 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), |
| 559 gfx::Rect(6400, 0, 3840, 2400), | 1178 gfx::Rect(6400, 0, 3840, 2400), |
| 560 L"secondary", | 1179 L"secondary", |
| 561 2.0); | 1180 2.0); |
| 562 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); | 1181 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); |
| 563 fake_hwnd_right_ = | 1182 fake_hwnd_right_ = |
| 564 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); | 1183 initializer->CreateFakeHwnd(gfx::Rect(6400, 0, 3840, 2400)); |
| 565 } | 1184 } |
| 566 | 1185 |
| 567 HWND GetLeftFakeHwnd() { | 1186 HWND GetLeftFakeHwnd() { |
| 568 return fake_hwnd_left_; | 1187 return fake_hwnd_left_; |
| 569 } | 1188 } |
| 570 | 1189 |
| 571 HWND GetRightFakeHwnd() { | 1190 HWND GetRightFakeHwnd() { |
| 572 return fake_hwnd_right_; | 1191 return fake_hwnd_right_; |
| 573 } | 1192 } |
| 574 | 1193 |
| 575 private: | 1194 private: |
| 576 HWND fake_hwnd_left_ = nullptr; | 1195 HWND fake_hwnd_left_ = nullptr; |
| 577 HWND fake_hwnd_right_ = nullptr; | 1196 HWND fake_hwnd_right_ = nullptr; |
| 578 | 1197 |
| 579 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); | 1198 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplays2x1xVirtualized); |
| 580 }; | 1199 }; |
| 581 | 1200 |
| 1201 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ScreenToDIPRects) { | |
| 1202 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1203 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1204 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1205 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1206 ScreenWin::ScreenToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 1207 | |
| 1208 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1209 EXPECT_EQ(gfx::Rect(3200, 0, 100, 150), | |
| 1210 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 1211 gfx::Rect(6400, 0, 200, 300))); | |
| 1212 EXPECT_EQ(gfx::Rect(3500, 248, 50, 100), | |
| 1213 ScreenWin::ScreenToDIPRect(right_hwnd, | |
| 1214 gfx::Rect(7000, 496, 100, 200))); | |
| 1215 } | |
| 1216 | |
| 1217 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToScreenRects) { | |
| 1218 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1219 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1220 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 1221 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1222 ScreenWin::DIPToScreenRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 1223 | |
| 1224 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1225 EXPECT_EQ(gfx::Rect(6400, 0, 200, 300), | |
| 1226 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 1227 gfx::Rect(3200, 0, 100, 150))); | |
| 1228 EXPECT_EQ(gfx::Rect(7000, 496, 100, 200), | |
| 1229 ScreenWin::DIPToScreenRect(right_hwnd, | |
| 1230 gfx::Rect(3500, 248, 50, 100))); | |
| 1231 } | |
| 1232 | |
| 1233 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, ClientToDIPRects) { | |
| 1234 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1235 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1236 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1237 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1238 ScreenWin::ClientToDIPRect(left_hwnd, gfx::Rect(253, 496, 41, 52))); | |
| 1239 | |
| 1240 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1241 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1242 ScreenWin::ClientToDIPRect(right_hwnd, gfx::Rect(0, 0, 50, 100))); | |
| 1243 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1244 ScreenWin::ClientToDIPRect(right_hwnd, | |
| 1245 gfx::Rect(253, 496, 41, 52))); | |
| 1246 } | |
| 1247 | |
| 1248 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, DIPToClientRects) { | |
| 1249 HWND left_hwnd = GetLeftFakeHwnd(); | |
| 1250 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1251 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 1252 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1253 ScreenWin::DIPToClientRect(left_hwnd, gfx::Rect(126, 248, 21, 26))); | |
| 1254 | |
| 1255 HWND right_hwnd = GetRightFakeHwnd(); | |
| 1256 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1257 ScreenWin::DIPToClientRect(right_hwnd, gfx::Rect(0, 0, 25, 50))); | |
| 1258 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1259 ScreenWin::DIPToClientRect(right_hwnd, | |
| 1260 gfx::Rect(126, 248, 21, 26))); | |
| 1261 } | |
| 1262 | |
| 582 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { | 1263 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetDisplays) { |
| 583 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); | 1264 std::vector<gfx::Display> displays = GetScreen()->GetAllDisplays(); |
| 584 ASSERT_EQ(2u, displays.size()); | 1265 ASSERT_EQ(2u, displays.size()); |
| 585 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); | 1266 EXPECT_EQ(gfx::Rect(0, 0, 1600, 800), displays[0].bounds()); |
| 586 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); | 1267 EXPECT_EQ(gfx::Rect(0, 0, 1600, 750), displays[0].work_area()); |
| 587 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); | 1268 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].bounds()); |
| 588 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); | 1269 EXPECT_EQ(gfx::Rect(3200, 0, 1920, 1200), displays[1].work_area()); |
| 589 } | 1270 } |
| 590 | 1271 |
| 591 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { | 1272 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetNumDisplays) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 EXPECT_EQ(right_display, | 1324 EXPECT_EQ(right_display, |
| 644 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); | 1325 screen->GetDisplayMatching(gfx::Rect(10139, 2299, 100, 100))); |
| 645 } | 1326 } |
| 646 | 1327 |
| 647 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { | 1328 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { |
| 648 gfx::Screen* screen = GetScreen(); | 1329 gfx::Screen* screen = GetScreen(); |
| 649 gfx::Display primary = screen->GetPrimaryDisplay(); | 1330 gfx::Display primary = screen->GetPrimaryDisplay(); |
| 650 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); | 1331 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); |
| 651 } | 1332 } |
| 652 | 1333 |
| 1334 // Forced 1x DPI for Other Tests without TestScreenWin. | |
| 1335 class ScreenWinUninitializedForced1x : public testing::Test { | |
| 1336 public: | |
| 1337 ScreenWinUninitializedForced1x() | |
| 1338 : old_command_line(*base::CommandLine::ForCurrentProcess()) {} | |
| 1339 | |
| 1340 void SetUp() override { | |
| 1341 testing::Test::SetUp(); | |
| 1342 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 1343 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1"); | |
| 1344 } | |
| 1345 | |
| 1346 void TearDown() override { | |
| 1347 *base::CommandLine::ForCurrentProcess() = old_command_line; | |
| 1348 Display::ResetForceDeviceScaleFactorForTesting(); | |
| 1349 testing::Test::TearDown(); | |
| 1350 } | |
| 1351 | |
| 1352 private: | |
| 1353 base::CommandLine old_command_line; | |
| 1354 | |
| 1355 DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced1x); | |
| 1356 }; | |
| 1357 | |
| 1358 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPPoints) { | |
| 1359 gfx::Point origin(0, 0); | |
| 1360 gfx::Point middle(365, 694); | |
| 1361 gfx::Point lower_right(1919, 1199); | |
| 1362 | |
| 1363 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); | |
| 1364 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); | |
| 1365 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); | |
| 1366 } | |
| 1367 | |
| 1368 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenPoints) { | |
| 1369 gfx::Point origin(0, 0); | |
| 1370 gfx::Point middle(365, 694); | |
| 1371 gfx::Point lower_right(1919, 1199); | |
| 1372 | |
| 1373 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); | |
| 1374 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); | |
| 1375 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); | |
| 1376 } | |
| 1377 | |
| 1378 TEST_F(ScreenWinUninitializedForced1x, ClientToDIPPoints) { | |
| 1379 gfx::Point origin(0, 0); | |
| 1380 gfx::Point middle(365, 694); | |
| 1381 gfx::Point lower_right(1919, 1199); | |
| 1382 | |
| 1383 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(nullptr, origin)); | |
| 1384 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(nullptr, middle)); | |
| 1385 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(nullptr, lower_right)); | |
| 1386 } | |
| 1387 | |
| 1388 TEST_F(ScreenWinUninitializedForced1x, DIPToClientPoints) { | |
| 1389 gfx::Point origin(0, 0); | |
| 1390 gfx::Point middle(365, 694); | |
| 1391 gfx::Point lower_right(1919, 1199); | |
| 1392 | |
| 1393 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(nullptr, origin)); | |
| 1394 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(nullptr, middle)); | |
| 1395 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(nullptr, lower_right)); | |
| 1396 } | |
| 1397 | |
| 1398 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPRects) { | |
| 1399 gfx::Rect origin(0, 0, 50, 100); | |
| 1400 gfx::Rect middle(253, 495, 41, 52); | |
| 1401 | |
| 1402 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(nullptr, origin)); | |
| 1403 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(nullptr, middle)); | |
| 1404 } | |
| 1405 | |
| 1406 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenRects) { | |
| 1407 gfx::Rect origin(0, 0, 50, 100); | |
| 1408 gfx::Rect middle(253, 495, 41, 52); | |
| 1409 | |
| 1410 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(nullptr, origin)); | |
| 1411 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(nullptr, middle)); | |
| 1412 } | |
| 1413 | |
| 1414 TEST_F(ScreenWinUninitializedForced1x, ClientToDIPRects) { | |
| 1415 gfx::Rect origin(0, 0, 50, 100); | |
| 1416 gfx::Rect middle(253, 495, 41, 52); | |
| 1417 | |
| 1418 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(nullptr, origin)); | |
| 1419 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(nullptr, middle)); | |
| 1420 } | |
| 1421 | |
| 1422 TEST_F(ScreenWinUninitializedForced1x, DIPToClientRects) { | |
| 1423 gfx::Rect origin(0, 0, 50, 100); | |
| 1424 gfx::Rect middle(253, 495, 41, 52); | |
| 1425 | |
| 1426 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(nullptr, origin)); | |
| 1427 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(nullptr, middle)); | |
| 1428 } | |
| 1429 | |
| 1430 TEST_F(ScreenWinUninitializedForced1x, ScreenToDIPSize) { | |
| 1431 gfx::Size size(42, 131); | |
| 1432 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(nullptr, size)); | |
| 1433 } | |
| 1434 | |
| 1435 TEST_F(ScreenWinUninitializedForced1x, DIPToScreenSize) { | |
| 1436 gfx::Size size(42, 131); | |
| 1437 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(nullptr, size)); | |
| 1438 } | |
| 1439 | |
| 1440 // Forced 2x DPI for Other Tests without TestScreenWin. | |
| 1441 class ScreenWinUninitializedForced2x : public testing::Test { | |
| 1442 public: | |
| 1443 ScreenWinUninitializedForced2x() | |
| 1444 : old_command_line(*base::CommandLine::ForCurrentProcess()) {} | |
| 1445 | |
| 1446 void SetUp() override { | |
| 1447 testing::Test::SetUp(); | |
| 1448 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 1449 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); | |
| 1450 } | |
| 1451 | |
| 1452 void TearDown() override { | |
| 1453 *base::CommandLine::ForCurrentProcess() = old_command_line; | |
| 1454 Display::ResetForceDeviceScaleFactorForTesting(); | |
| 1455 testing::Test::TearDown(); | |
| 1456 } | |
| 1457 | |
| 1458 private: | |
| 1459 base::CommandLine old_command_line; | |
| 1460 | |
| 1461 DISALLOW_COPY_AND_ASSIGN(ScreenWinUninitializedForced2x); | |
| 1462 }; | |
| 1463 | |
| 1464 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPPoints) { | |
| 1465 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); | |
| 1466 EXPECT_EQ(gfx::Point(182, 347), | |
| 1467 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); | |
| 1468 EXPECT_EQ(gfx::Point(959, 599), | |
| 1469 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); | |
| 1470 } | |
| 1471 | |
| 1472 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenPoints) { | |
| 1473 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); | |
| 1474 EXPECT_EQ(gfx::Point(364, 694), | |
| 1475 ScreenWin::DIPToScreenPoint(gfx::Point(182, 347))); | |
| 1476 EXPECT_EQ(gfx::Point(1918, 1198), | |
| 1477 ScreenWin::DIPToScreenPoint(gfx::Point(959, 599))); | |
| 1478 } | |
| 1479 | |
| 1480 TEST_F(ScreenWinUninitializedForced2x, ClientToDIPPoints) { | |
| 1481 EXPECT_EQ(gfx::Point(0, 0), | |
| 1482 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(0, 0))); | |
| 1483 EXPECT_EQ(gfx::Point(182, 347), | |
| 1484 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(365, 694))); | |
| 1485 EXPECT_EQ(gfx::Point(959, 599), | |
| 1486 ScreenWin::ClientToDIPPoint(nullptr, gfx::Point(1919, 1199))); | |
| 1487 } | |
| 1488 | |
| 1489 TEST_F(ScreenWinUninitializedForced2x, DIPToClientPoints) { | |
| 1490 EXPECT_EQ(gfx::Point(0, 0), | |
| 1491 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(0, 0))); | |
| 1492 EXPECT_EQ(gfx::Point(364, 694), | |
| 1493 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(182, 347))); | |
| 1494 EXPECT_EQ(gfx::Point(1918, 1198), | |
| 1495 ScreenWin::DIPToClientPoint(nullptr, gfx::Point(959, 599))); | |
| 1496 } | |
| 1497 | |
| 1498 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPRects) { | |
| 1499 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1500 ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); | |
| 1501 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1502 ScreenWin::ScreenToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); | |
| 1503 } | |
| 1504 | |
| 1505 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenRects) { | |
| 1506 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1507 ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(0, 0, 25, 50))); | |
| 1508 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1509 ScreenWin::DIPToScreenRect(nullptr, gfx::Rect(126, 248, 21, 26))); | |
| 1510 } | |
| 1511 | |
| 1512 TEST_F(ScreenWinUninitializedForced2x, ClientToDIPRects) { | |
| 1513 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), | |
| 1514 ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(0, 0, 50, 100))); | |
| 1515 EXPECT_EQ(gfx::Rect(126, 248, 21, 26), | |
| 1516 ScreenWin::ClientToDIPRect(nullptr, gfx::Rect(253, 496, 41, 52))); | |
| 1517 } | |
| 1518 | |
| 1519 TEST_F(ScreenWinUninitializedForced2x, DIPToClientRects) { | |
| 1520 EXPECT_EQ(gfx::Rect(0, 0, 50, 100), | |
| 1521 ScreenWin::DIPToClientRect(nullptr, gfx::Rect(0, 0, 25, 50))); | |
| 1522 EXPECT_EQ(gfx::Rect(252, 496, 42, 52), | |
| 1523 ScreenWin::DIPToClientRect(nullptr, gfx::Rect(126, 248, 21, 26))); | |
| 1524 } | |
| 1525 | |
| 1526 TEST_F(ScreenWinUninitializedForced2x, ScreenToDIPSize) { | |
| 1527 EXPECT_EQ(gfx::Size(21, 66), | |
| 1528 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); | |
| 1529 } | |
| 1530 | |
| 1531 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { | |
| 1532 EXPECT_EQ(gfx::Size(42, 132), | |
| 1533 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); | |
| 1534 } | |
| 1535 | |
| 653 } // namespace gfx | 1536 } // namespace gfx |
| OLD | NEW |