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

Side by Side Diff: ui/gfx/screen_win_unittest.cc

Issue 1813493002: COMPLETED PREVIEW Migrate to Display Placement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gfxmove
Patch Set: Created 4 years, 9 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/gfx/screen_win.cc ('k') | ui/gfx/win/rect_util.h » ('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/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/command_line.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gfx/display.h" 20 #include "ui/gfx/display.h"
21 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
23 #include "ui/gfx/switches.h" 23 #include "ui/gfx/switches.h"
24 #include "ui/gfx/test/display_util.h" 24 #include "ui/gfx/test/display_util.h"
25 #include "ui/gfx/test/screen_util_win.h"
25 #include "ui/gfx/win/display_info.h" 26 #include "ui/gfx/win/display_info.h"
26 #include "ui/gfx/win/dpi.h" 27 #include "ui/gfx/win/dpi.h"
27 #include "ui/gfx/win/screen_win_display.h" 28 #include "ui/gfx/win/screen_win_display.h"
28 29
29 namespace gfx { 30 namespace gfx {
30 31
31 namespace { 32 namespace {
32 33
33 MONITORINFOEX CreateMonitorInfo(gfx::Rect monitor,
34 gfx::Rect work,
35 std::wstring device_name) {
36 MONITORINFOEX monitor_info;
37 ::ZeroMemory(&monitor_info, sizeof(monitor_info));
38 monitor_info.cbSize = sizeof(monitor_info);
39 monitor_info.rcMonitor = monitor.ToRECT();
40 monitor_info.rcWork = work.ToRECT();
41 size_t device_char_count = ARRAYSIZE(monitor_info.szDevice);
42 wcsncpy(monitor_info.szDevice, device_name.c_str(), device_char_count);
43 monitor_info.szDevice[device_char_count-1] = L'\0';
44 return monitor_info;
45 }
46
47 class TestScreenWin : public gfx::ScreenWin { 34 class TestScreenWin : public gfx::ScreenWin {
48 public: 35 public:
49 TestScreenWin(const std::vector<gfx::win::DisplayInfo>& display_infos, 36 TestScreenWin(const std::vector<gfx::win::DisplayInfo>& display_infos,
50 const std::vector<MONITORINFOEX>& monitor_infos, 37 const std::vector<MONITORINFOEX>& monitor_infos,
51 const std::unordered_map<HWND, gfx::Rect>& hwnd_map) 38 const std::unordered_map<HWND, gfx::Rect>& hwnd_map)
52 : monitor_infos_(monitor_infos), 39 : monitor_infos_(monitor_infos),
53 hwnd_map_(hwnd_map) { 40 hwnd_map_(hwnd_map) {
54 UpdateFromDisplayInfos(display_infos); 41 UpdateFromDisplayInfos(display_infos);
55 } 42 }
56 43
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 TestScreenWinManager() = default; 138 TestScreenWinManager() = default;
152 139
153 ~TestScreenWinManager() { 140 ~TestScreenWinManager() {
154 gfx::Screen::SetScreenInstance(nullptr); 141 gfx::Screen::SetScreenInstance(nullptr);
155 } 142 }
156 143
157 void AddMonitor(const gfx::Rect& pixel_bounds, 144 void AddMonitor(const gfx::Rect& pixel_bounds,
158 const gfx::Rect& pixel_work, 145 const gfx::Rect& pixel_work,
159 const wchar_t* device_name, 146 const wchar_t* device_name,
160 float device_scale_factor) override { 147 float device_scale_factor) override {
161 MONITORINFOEX monitor_info = CreateMonitorInfo(pixel_bounds, 148 MONITORINFOEX monitor_info = gfx::test::CreateMonitorInfo(pixel_bounds,
162 pixel_work, 149 pixel_work,
163 device_name); 150 device_name);
164 monitor_infos_.push_back(monitor_info); 151 monitor_infos_.push_back(monitor_info);
165 display_infos_.push_back(gfx::win::DisplayInfo(monitor_info, 152 display_infos_.push_back(gfx::win::DisplayInfo(monitor_info,
166 device_scale_factor, 153 device_scale_factor,
167 gfx::Display::ROTATE_0)); 154 gfx::Display::ROTATE_0));
168 } 155 }
169 156
170 HWND CreateFakeHwnd(const gfx::Rect& bounds) override { 157 HWND CreateFakeHwnd(const gfx::Rect& bounds) override {
171 EXPECT_EQ(screen_win_, nullptr); 158 EXPECT_EQ(screen_win_, nullptr);
172 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds)); 159 hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds));
173 return hwndLast_; 160 return hwndLast_;
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 EXPECT_EQ(gfx::Size(21, 66), 1980 EXPECT_EQ(gfx::Size(21, 66),
1994 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131))); 1981 ScreenWin::ScreenToDIPSize(nullptr, gfx::Size(42, 131)));
1995 } 1982 }
1996 1983
1997 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) { 1984 TEST_F(ScreenWinUninitializedForced2x, DIPToScreenSize) {
1998 EXPECT_EQ(gfx::Size(42, 132), 1985 EXPECT_EQ(gfx::Size(42, 132),
1999 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66))); 1986 ScreenWin::DIPToScreenSize(nullptr, gfx::Size(21, 66)));
2000 } 1987 }
2001 1988
2002 } // namespace gfx 1989 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/screen_win.cc ('k') | ui/gfx/win/rect_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698