Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ui/display/win/screen_win_unittest.cc

Issue 1889423002: Move Windows DPI Code from ui/gfx to ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a TODO Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/display/win/screen_win_display.cc ('k') | ui/gfx/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/display/win/screen_win.h" 5 #include "ui/display/win/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/macros.h" 17 #include "base/macros.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/display/win/display_info.h" 19 #include "ui/display/win/display_info.h"
20 #include "ui/display/win/dpi.h"
20 #include "ui/display/win/screen_win_display.h" 21 #include "ui/display/win/screen_win_display.h"
21 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
22 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
24 #include "ui/gfx/test/display_util.h" 25 #include "ui/gfx/test/display_util.h"
25 #include "ui/gfx/win/dpi.h"
26 26
27 namespace display { 27 namespace display {
28 namespace win { 28 namespace win {
29 29
30 namespace { 30 namespace {
31 31
32 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor, 32 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor,
33 gfx::Rect work, 33 gfx::Rect work,
34 std::wstring device_name) { 34 std::wstring device_name) {
35 MONITORINFOEX monitor_info; 35 MONITORINFOEX monitor_info;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager); 192 DISALLOW_COPY_AND_ASSIGN(TestScreenWinManager);
193 }; 193 };
194 194
195 class ScreenWinTest : public testing::Test { 195 class ScreenWinTest : public testing::Test {
196 protected: 196 protected:
197 ScreenWinTest() = default; 197 ScreenWinTest() = default;
198 198
199 void SetUp() override { 199 void SetUp() override {
200 testing::Test::SetUp(); 200 testing::Test::SetUp();
201 gfx::SetDefaultDeviceScaleFactor(1.0); 201 display::win::SetDefaultDeviceScaleFactor(1.0);
202 screen_win_initializer_.reset(new TestScreenWinManager()); 202 screen_win_initializer_.reset(new TestScreenWinManager());
203 SetUpScreen(screen_win_initializer_.get()); 203 SetUpScreen(screen_win_initializer_.get());
204 screen_win_initializer_->InitializeScreenWin(); 204 screen_win_initializer_->InitializeScreenWin();
205 } 205 }
206 206
207 void TearDown() override { 207 void TearDown() override {
208 screen_win_initializer_.reset(); 208 screen_win_initializer_.reset();
209 gfx::SetDefaultDeviceScaleFactor(1.0); 209 display::win::SetDefaultDeviceScaleFactor(1.0);
210 testing::Test::TearDown(); 210 testing::Test::TearDown();
211 } 211 }
212 212
213 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0; 213 virtual void SetUpScreen(TestScreenWinInitializer* initializer) = 0;
214 214
215 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const { 215 gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const {
216 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin(); 216 ScreenWin* screen_win = screen_win_initializer_->GetScreenWin();
217 return screen_win->GetNativeWindowFromHWND(hwnd);; 217 return screen_win->GetNativeWindowFromHWND(hwnd);;
218 } 218 }
219 219
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 gfx::Screen* screen = GetScreen(); 290 gfx::Screen* screen = GetScreen();
291 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 291 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
292 } 292 }
293 293
294 // Single Display of 1.25 Device Scale Factor. 294 // Single Display of 1.25 Device Scale Factor.
295 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { 295 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest {
296 public: 296 public:
297 ScreenWinTestSingleDisplay1_25x() = default; 297 ScreenWinTestSingleDisplay1_25x() = default;
298 298
299 void SetUpScreen(TestScreenWinInitializer* initializer) override { 299 void SetUpScreen(TestScreenWinInitializer* initializer) override {
300 gfx::SetDefaultDeviceScaleFactor(1.25); 300 display::win::SetDefaultDeviceScaleFactor(1.25);
301 // Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the 301 // Add Monitor of Scale Factor 1.0 since display::GetDPIScale performs the
302 // clamping and not ScreenWin. 302 // clamping and not ScreenWin.
303 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 303 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
304 gfx::Rect(0, 0, 1920, 1100), 304 gfx::Rect(0, 0, 1920, 1100),
305 L"primary", 305 L"primary",
306 1.0); 306 1.0);
307 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 307 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
308 } 308 }
309 309
310 HWND GetFakeHwnd() { 310 HWND GetFakeHwnd() {
311 return fake_hwnd_; 311 return fake_hwnd_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 gfx::Screen* screen = GetScreen(); 351 gfx::Screen* screen = GetScreen();
352 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 352 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
353 } 353 }
354 354
355 // Single Display of 1.25 Device Scale Factor. 355 // Single Display of 1.25 Device Scale Factor.
356 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { 356 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest {
357 public: 357 public:
358 ScreenWinTestSingleDisplay1_5x() = default; 358 ScreenWinTestSingleDisplay1_5x() = default;
359 359
360 void SetUpScreen(TestScreenWinInitializer* initializer) override { 360 void SetUpScreen(TestScreenWinInitializer* initializer) override {
361 gfx::SetDefaultDeviceScaleFactor(1.5); 361 display::win::SetDefaultDeviceScaleFactor(1.5);
362 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 362 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
363 gfx::Rect(0, 0, 1920, 1100), 363 gfx::Rect(0, 0, 1920, 1100),
364 L"primary", 364 L"primary",
365 1.5); 365 1.5);
366 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 366 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
367 } 367 }
368 368
369 HWND GetFakeHwnd() { 369 HWND GetFakeHwnd() {
370 return fake_hwnd_; 370 return fake_hwnd_;
371 } 371 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); 410 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin());
411 } 411 }
412 412
413 413
414 // Single Display of 2.0 Device Scale Factor. 414 // Single Display of 2.0 Device Scale Factor.
415 class ScreenWinTestSingleDisplay2x : public ScreenWinTest { 415 class ScreenWinTestSingleDisplay2x : public ScreenWinTest {
416 public: 416 public:
417 ScreenWinTestSingleDisplay2x() = default; 417 ScreenWinTestSingleDisplay2x() = default;
418 418
419 void SetUpScreen(TestScreenWinInitializer* initializer) override { 419 void SetUpScreen(TestScreenWinInitializer* initializer) override {
420 gfx::SetDefaultDeviceScaleFactor(2.0); 420 display::win::SetDefaultDeviceScaleFactor(2.0);
421 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 421 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
422 gfx::Rect(0, 0, 1920, 1100), 422 gfx::Rect(0, 0, 1920, 1100),
423 L"primary", 423 L"primary",
424 2.0); 424 2.0);
425 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 425 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
426 } 426 }
427 427
428 HWND GetFakeHwnd() { 428 HWND GetFakeHwnd() {
429 return fake_hwnd_; 429 return fake_hwnd_;
430 } 430 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 gfx::Display primary = screen->GetPrimaryDisplay(); 568 gfx::Display primary = screen->GetPrimaryDisplay();
569 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); 569 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin());
570 } 570 }
571 571
572 // Two Displays of 2.0 Device Scale Factor. 572 // Two Displays of 2.0 Device Scale Factor.
573 class ScreenWinTestTwoDisplays2x : public ScreenWinTest { 573 class ScreenWinTestTwoDisplays2x : public ScreenWinTest {
574 public: 574 public:
575 ScreenWinTestTwoDisplays2x() = default; 575 ScreenWinTestTwoDisplays2x() = default;
576 576
577 void SetUpScreen(TestScreenWinInitializer* initializer) override { 577 void SetUpScreen(TestScreenWinInitializer* initializer) override {
578 gfx::SetDefaultDeviceScaleFactor(2.0); 578 display::win::SetDefaultDeviceScaleFactor(2.0);
579 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), 579 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
580 gfx::Rect(0, 0, 1920, 1100), 580 gfx::Rect(0, 0, 1920, 1100),
581 L"primary", 581 L"primary",
582 2.0); 582 2.0);
583 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), 583 initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600),
584 gfx::Rect(1920, 0, 800, 600), 584 gfx::Rect(1920, 0, 800, 600),
585 L"secondary", 585 L"secondary",
586 2.0); 586 2.0);
587 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); 587 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100));
588 fake_hwnd_right_ = 588 fake_hwnd_right_ =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 671 }
672 672
673 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under 673 // Two Displays of 2.0 (Left) and 1.0 (Right) Device Scale Factor under
674 // Windows DPI Virtualization. Note that the displays do not form a euclidean 674 // Windows DPI Virtualization. Note that the displays do not form a euclidean
675 // space. 675 // space.
676 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest { 676 class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest {
677 public: 677 public:
678 ScreenWinTestTwoDisplays2x1xVirtualized() = default; 678 ScreenWinTestTwoDisplays2x1xVirtualized() = default;
679 679
680 void SetUpScreen(TestScreenWinInitializer* initializer) override { 680 void SetUpScreen(TestScreenWinInitializer* initializer) override {
681 gfx::SetDefaultDeviceScaleFactor(2.0); 681 display::win::SetDefaultDeviceScaleFactor(2.0);
682 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600), 682 initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600),
683 gfx::Rect(0, 0, 3200, 1500), 683 gfx::Rect(0, 0, 3200, 1500),
684 L"primary", 684 L"primary",
685 2.0); 685 2.0);
686 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400), 686 initializer->AddMonitor(gfx::Rect(6400, 0, 3840, 2400),
687 gfx::Rect(6400, 0, 3840, 2400), 687 gfx::Rect(6400, 0, 3840, 2400),
688 L"secondary", 688 L"secondary",
689 2.0); 689 2.0);
690 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500)); 690 fake_hwnd_left_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 3200, 1500));
691 fake_hwnd_right_ = 691 fake_hwnd_right_ =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) { 775 TEST_F(ScreenWinTestTwoDisplays2x1xVirtualized, GetPrimaryDisplay) {
776 gfx::Screen* screen = GetScreen(); 776 gfx::Screen* screen = GetScreen();
777 gfx::Display primary = screen->GetPrimaryDisplay(); 777 gfx::Display primary = screen->GetPrimaryDisplay();
778 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin()); 778 EXPECT_EQ(gfx::Point(0, 0), primary.bounds().origin());
779 } 779 }
780 780
781 } // namespace 781 } // namespace
782 782
783 } // namespace win 783 } // namespace win
784 } // namespace display 784 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/screen_win_display.cc ('k') | ui/gfx/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698