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

Side by Side Diff: ash/display/display_change_observer_chromeos_unittest.cc

Issue 417113012: Introduce user customization of external HighDPI mode for 4K monitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ash/display/display_change_observer_chromeos.cc ('k') | ash/display/display_info.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/display/display_change_observer_chromeos.h" 5 #include "ash/display/display_change_observer_chromeos.h"
6 6
7 #include "ash/display/display_info.h" 7 #include "ash/display/display_info.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/chromeos/display_configurator.h" 10 #include "ui/display/chromeos/display_configurator.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h" 11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/types/chromeos/display_mode.h" 12 #include "ui/display/types/chromeos/display_mode.h"
13 13
14 using ui::DisplayConfigurator; 14 using ui::DisplayConfigurator;
15 15
16 typedef testing::Test DisplayChangeObserverTest; 16 typedef testing::Test DisplayChangeObserverTest;
17 17
18 namespace ash { 18 namespace ash {
19 19
20 TEST_F(DisplayChangeObserverTest, GetDisplayModeList) { 20 TEST_F(DisplayChangeObserverTest, GetExternalDisplayModeList) {
21 ScopedVector<const ui::DisplayMode> modes; 21 ScopedVector<const ui::DisplayMode> modes;
22 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1200), false, 60)); 22 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1200), false, 60));
23 23
24 // All non-interlaced (as would be seen with different refresh rates). 24 // All non-interlaced (as would be seen with different refresh rates).
25 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 80)); 25 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 80));
26 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 70)); 26 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 70));
27 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 60)); 27 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 60));
28 28
29 // Interlaced vs non-interlaced. 29 // Interlaced vs non-interlaced.
30 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), true, 60)); 30 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), true, 60));
(...skipping 10 matching lines...) Expand all
41 41
42 // Just one interlaced mode. 42 // Just one interlaced mode.
43 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), true, 60)); 43 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), true, 60));
44 44
45 ui::TestDisplaySnapshot display_snapshot; 45 ui::TestDisplaySnapshot display_snapshot;
46 display_snapshot.set_modes(modes.get()); 46 display_snapshot.set_modes(modes.get());
47 DisplayConfigurator::DisplayState output; 47 DisplayConfigurator::DisplayState output;
48 output.display = &display_snapshot; 48 output.display = &display_snapshot;
49 49
50 std::vector<DisplayMode> display_modes = 50 std::vector<DisplayMode> display_modes =
51 DisplayChangeObserver::GetDisplayModeList(output); 51 DisplayChangeObserver::GetExternalDisplayModeList(output);
52 ASSERT_EQ(6u, display_modes.size()); 52 ASSERT_EQ(6u, display_modes.size());
53 EXPECT_EQ("1920x1200", display_modes[0].size.ToString()); 53 EXPECT_EQ("640x480", display_modes[0].size.ToString());
54 EXPECT_FALSE(display_modes[0].interlaced); 54 EXPECT_TRUE(display_modes[0].interlaced);
55 EXPECT_EQ(display_modes[0].refresh_rate, 60); 55 EXPECT_EQ(display_modes[0].refresh_rate, 60);
56 56
57 EXPECT_EQ("1920x1080", display_modes[1].size.ToString()); 57 EXPECT_EQ("1024x600", display_modes[1].size.ToString());
58 EXPECT_FALSE(display_modes[1].interlaced); 58 EXPECT_FALSE(display_modes[1].interlaced);
59 EXPECT_EQ(display_modes[1].refresh_rate, 80); 59 EXPECT_EQ(display_modes[1].refresh_rate, 70);
60 60
61 EXPECT_EQ("1280x720", display_modes[2].size.ToString()); 61 EXPECT_EQ("1024x768", display_modes[2].size.ToString());
62 EXPECT_FALSE(display_modes[2].interlaced); 62 EXPECT_TRUE(display_modes[2].interlaced);
63 EXPECT_EQ(display_modes[2].refresh_rate, 60); 63 EXPECT_EQ(display_modes[2].refresh_rate, 70);
64 64
65 EXPECT_EQ("1024x768", display_modes[3].size.ToString()); 65 EXPECT_EQ("1280x720", display_modes[3].size.ToString());
66 EXPECT_TRUE(display_modes[3].interlaced); 66 EXPECT_FALSE(display_modes[3].interlaced);
67 EXPECT_EQ(display_modes[3].refresh_rate, 70); 67 EXPECT_EQ(display_modes[3].refresh_rate, 60);
68 68
69 EXPECT_EQ("1024x600", display_modes[4].size.ToString()); 69 EXPECT_EQ("1920x1080", display_modes[4].size.ToString());
70 EXPECT_FALSE(display_modes[4].interlaced); 70 EXPECT_FALSE(display_modes[4].interlaced);
71 EXPECT_EQ(display_modes[4].refresh_rate, 70); 71 EXPECT_EQ(display_modes[4].refresh_rate, 80);
72 72
73 EXPECT_EQ("640x480", display_modes[5].size.ToString()); 73 EXPECT_EQ("1920x1200", display_modes[5].size.ToString());
74 EXPECT_TRUE(display_modes[5].interlaced); 74 EXPECT_FALSE(display_modes[5].interlaced);
75 EXPECT_EQ(display_modes[5].refresh_rate, 60); 75 EXPECT_EQ(display_modes[5].refresh_rate, 60);
76 76
77 // Outputs without any modes shouldn't cause a crash. 77 // Outputs without any modes shouldn't cause a crash.
78 modes.clear(); 78 modes.clear();
79 display_snapshot.set_modes(modes.get()); 79 display_snapshot.set_modes(modes.get());
80 80
81 display_modes = DisplayChangeObserver::GetDisplayModeList(output); 81 display_modes = DisplayChangeObserver::GetExternalDisplayModeList(output);
82 EXPECT_EQ(0u, display_modes.size()); 82 EXPECT_EQ(0u, display_modes.size());
83 } 83 }
84 84
85 TEST_F(DisplayChangeObserverTest, GetInternalDisplayModeList) {
86 ScopedVector<const ui::DisplayMode> modes;
87 // Data picked from peppy.
88 modes.push_back(new ui::DisplayMode(gfx::Size(1366, 768), false, 60));
89 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 768), false, 60));
90 modes.push_back(new ui::DisplayMode(gfx::Size(800, 600), false, 60));
91 modes.push_back(new ui::DisplayMode(gfx::Size(600, 600), false, 56.2));
92 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), false, 59.9));
93
94 ui::TestDisplaySnapshot display_snapshot;
95 display_snapshot.set_modes(modes.get());
96 display_snapshot.set_native_mode(modes[0]);
97 DisplayConfigurator::DisplayState output;
98 output.display = &display_snapshot;
99
100 DisplayInfo info;
101 info.SetBounds(gfx::Rect(0, 0, 1366, 768));
102
103 std::vector<DisplayMode> display_modes =
104 DisplayChangeObserver::GetInternalDisplayModeList(info, output);
105 ASSERT_EQ(5u, display_modes.size());
106 EXPECT_EQ("1366x768", display_modes[0].size.ToString());
107 EXPECT_FALSE(display_modes[0].native);
108 EXPECT_NEAR(display_modes[0].ui_scale, 0.5, 0.01);
109 EXPECT_EQ(display_modes[0].refresh_rate, 60);
110
111 EXPECT_EQ("1366x768", display_modes[1].size.ToString());
112 EXPECT_FALSE(display_modes[1].native);
113 EXPECT_NEAR(display_modes[1].ui_scale, 0.6, 0.01);
114 EXPECT_EQ(display_modes[1].refresh_rate, 60);
115
116 EXPECT_EQ("1366x768", display_modes[2].size.ToString());
117 EXPECT_FALSE(display_modes[2].native);
118 EXPECT_NEAR(display_modes[2].ui_scale, 0.75, 0.01);
119 EXPECT_EQ(display_modes[2].refresh_rate, 60);
120
121 EXPECT_EQ("1366x768", display_modes[3].size.ToString());
122 EXPECT_TRUE(display_modes[3].native);
123 EXPECT_NEAR(display_modes[3].ui_scale, 1.0, 0.01);
124 EXPECT_EQ(display_modes[3].refresh_rate, 60);
125
126 EXPECT_EQ("1366x768", display_modes[4].size.ToString());
127 EXPECT_FALSE(display_modes[4].native);
128 EXPECT_NEAR(display_modes[4].ui_scale, 1.125, 0.01);
129 EXPECT_EQ(display_modes[4].refresh_rate, 60);
130 }
131
132 TEST_F(DisplayChangeObserverTest, GetExternalDisplayModeList4K) {
133 ScopedVector<const ui::DisplayMode> modes;
134 modes.push_back(new ui::DisplayMode(gfx::Size(3840, 2160), false, 30));
135 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1200), false, 60));
136
137 // All non-interlaced (as would be seen with different refresh rates).
138 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 80));
139 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 70));
140 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1080), false, 60));
141
142 // Interlaced vs non-interlaced.
143 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), true, 60));
144 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), false, 60));
145
146 // Interlaced only.
147 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 768), true, 70));
148 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 768), true, 60));
149
150 // Mixed.
151 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), true, 60));
152 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), false, 70));
153 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), false, 60));
154
155 // Just one interlaced mode.
156 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), true, 60));
157
158 ui::TestDisplaySnapshot display_snapshot;
159 display_snapshot.set_modes(modes.get());
160 display_snapshot.set_native_mode(modes[0]);
161 DisplayConfigurator::DisplayState output;
162 output.display = &display_snapshot;
163
164 std::vector<DisplayMode> display_modes =
165 DisplayChangeObserver::GetExternalDisplayModeList(output);
166 ASSERT_EQ(9u, display_modes.size());
167 EXPECT_EQ("640x480", display_modes[0].size.ToString());
168 EXPECT_TRUE(display_modes[0].interlaced);
169 EXPECT_EQ(display_modes[0].refresh_rate, 60);
170
171 EXPECT_EQ("1024x600", display_modes[1].size.ToString());
172 EXPECT_FALSE(display_modes[1].interlaced);
173 EXPECT_EQ(display_modes[1].refresh_rate, 70);
174
175 EXPECT_EQ("1024x768", display_modes[2].size.ToString());
176 EXPECT_TRUE(display_modes[2].interlaced);
177 EXPECT_EQ(display_modes[2].refresh_rate, 70);
178
179 EXPECT_EQ("1280x720", display_modes[3].size.ToString());
180 EXPECT_FALSE(display_modes[3].interlaced);
181 EXPECT_EQ(display_modes[3].refresh_rate, 60);
182
183 EXPECT_EQ("1920x1080", display_modes[4].size.ToString());
184 EXPECT_FALSE(display_modes[4].interlaced);
185 EXPECT_EQ(display_modes[4].refresh_rate, 80);
186
187 EXPECT_EQ("3840x2160", display_modes[5].size.ToString());
188 EXPECT_FALSE(display_modes[5].interlaced);
189 EXPECT_FALSE(display_modes[5].native);
190 EXPECT_EQ(display_modes[5].refresh_rate, 30);
191 EXPECT_EQ(display_modes[5].device_scale_factor, 2.0);
192
193 EXPECT_EQ("1920x1200", display_modes[6].size.ToString());
194 EXPECT_FALSE(display_modes[6].interlaced);
195 EXPECT_EQ(display_modes[6].refresh_rate, 60);
196
197 EXPECT_EQ("3840x2160", display_modes[7].size.ToString());
198 EXPECT_FALSE(display_modes[7].interlaced);
199 EXPECT_FALSE(display_modes[7].native);
200 EXPECT_EQ(display_modes[7].refresh_rate, 30);
201 EXPECT_EQ(display_modes[7].device_scale_factor, 1.25);
202
203 EXPECT_EQ("3840x2160", display_modes[8].size.ToString());
204 EXPECT_FALSE(display_modes[8].interlaced);
205 EXPECT_TRUE(display_modes[8].native);
206 EXPECT_EQ(display_modes[8].refresh_rate, 30);
207
208 // Outputs without any modes shouldn't cause a crash.
209 modes.clear();
210 display_snapshot.set_modes(modes.get());
211
212 display_modes = DisplayChangeObserver::GetExternalDisplayModeList(output);
213 EXPECT_EQ(0u, display_modes.size());
214 }
215
85 TEST_F(DisplayChangeObserverTest, FindDeviceScaleFactor) { 216 TEST_F(DisplayChangeObserverTest, FindDeviceScaleFactor) {
86 // 19.5" 1600x900 217 // 19.5" 1600x900
87 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(94.14f)); 218 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(94.14f));
88 219
89 // 21.5" 1920x1080 220 // 21.5" 1920x1080
90 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(102.46f)); 221 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(102.46f));
91 222
92 // 12.1" 1280x800 223 // 12.1" 1280x800
93 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(124.75f)); 224 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(124.75f));
94 225
95 // 13.3" 1920x1080 226 // 13.3" 1920x1080
96 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(157.35f)); 227 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(157.35f));
97 228
98 // 14" 1920x1080 229 // 14" 1920x1080
99 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(165.63f)); 230 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(165.63f));
100 231
101 // 12.85" 2560x1700 232 // 12.85" 2560x1700
102 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(239.15f)); 233 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(239.15f));
103 234
104 // Erroneous values should still work. 235 // Erroneous values should still work.
105 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(-100.0f)); 236 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(-100.0f));
106 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(0.0f)); 237 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(0.0f));
107 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(10000.0f)); 238 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(10000.0f));
108 } 239 }
109 240
110 } // namespace ash 241 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_change_observer_chromeos.cc ('k') | ash/display/display_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698