Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / display / display_change_observer_chromeos_unittest.cc
blobd274764d765daf99a63e899ffc47f745f83baa19
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
3 // found in the LICENSE file.
5 #include "ash/display/display_change_observer_chromeos.h"
7 #include "ash/display/display_info.h"
8 #include "base/memory/scoped_vector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/chromeos/display_configurator.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/types/chromeos/display_mode.h"
14 using ui::DisplayConfigurator;
16 typedef testing::Test DisplayChangeObserverTest;
18 namespace ash {
20 TEST_F(DisplayChangeObserverTest, GetExternalDisplayModeList) {
21 ScopedVector<const ui::DisplayMode> modes;
22 modes.push_back(new ui::DisplayMode(gfx::Size(1920, 1200), false, 60));
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));
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));
29 // Interlaced vs non-interlaced.
30 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), true, 60));
31 modes.push_back(new ui::DisplayMode(gfx::Size(1280, 720), false, 60));
33 // Interlaced only.
34 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 768), true, 70));
35 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 768), true, 60));
37 // Mixed.
38 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), true, 60));
39 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), false, 70));
40 modes.push_back(new ui::DisplayMode(gfx::Size(1024, 600), false, 60));
42 // Just one interlaced mode.
43 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), true, 60));
45 ui::TestDisplaySnapshot display_snapshot;
46 display_snapshot.set_modes(modes.get());
47 DisplayConfigurator::DisplayState output;
48 output.display = &display_snapshot;
50 std::vector<DisplayMode> display_modes =
51 DisplayChangeObserver::GetExternalDisplayModeList(output);
52 ASSERT_EQ(6u, display_modes.size());
53 EXPECT_EQ("640x480", display_modes[0].size.ToString());
54 EXPECT_TRUE(display_modes[0].interlaced);
55 EXPECT_EQ(display_modes[0].refresh_rate, 60);
57 EXPECT_EQ("1024x600", display_modes[1].size.ToString());
58 EXPECT_FALSE(display_modes[1].interlaced);
59 EXPECT_EQ(display_modes[1].refresh_rate, 70);
61 EXPECT_EQ("1024x768", display_modes[2].size.ToString());
62 EXPECT_TRUE(display_modes[2].interlaced);
63 EXPECT_EQ(display_modes[2].refresh_rate, 70);
65 EXPECT_EQ("1280x720", display_modes[3].size.ToString());
66 EXPECT_FALSE(display_modes[3].interlaced);
67 EXPECT_EQ(display_modes[3].refresh_rate, 60);
69 EXPECT_EQ("1920x1080", display_modes[4].size.ToString());
70 EXPECT_FALSE(display_modes[4].interlaced);
71 EXPECT_EQ(display_modes[4].refresh_rate, 80);
73 EXPECT_EQ("1920x1200", display_modes[5].size.ToString());
74 EXPECT_FALSE(display_modes[5].interlaced);
75 EXPECT_EQ(display_modes[5].refresh_rate, 60);
77 // Outputs without any modes shouldn't cause a crash.
78 modes.clear();
79 display_snapshot.set_modes(modes.get());
81 display_modes = DisplayChangeObserver::GetExternalDisplayModeList(output);
82 EXPECT_EQ(0u, display_modes.size());
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));
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;
100 DisplayInfo info;
101 info.SetBounds(gfx::Rect(0, 0, 1366, 768));
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);
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);
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);
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);
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);
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));
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));
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));
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));
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));
155 // Just one interlaced mode.
156 modes.push_back(new ui::DisplayMode(gfx::Size(640, 480), true, 60));
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;
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);
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);
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);
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);
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);
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);
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);
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);
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);
208 // Outputs without any modes shouldn't cause a crash.
209 modes.clear();
210 display_snapshot.set_modes(modes.get());
212 display_modes = DisplayChangeObserver::GetExternalDisplayModeList(output);
213 EXPECT_EQ(0u, display_modes.size());
216 TEST_F(DisplayChangeObserverTest, FindDeviceScaleFactor) {
217 // 19.5" 1600x900
218 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(94.14f));
220 // 21.5" 1920x1080
221 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(102.46f));
223 // 12.1" 1280x800
224 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(124.75f));
226 // 13.3" 1920x1080
227 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(157.35f));
229 // 14" 1920x1080
230 EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(165.63f));
232 // 12.85" 2560x1700
233 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(239.15f));
235 // Erroneous values should still work.
236 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(-100.0f));
237 EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(0.0f));
238 EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(10000.0f));
241 } // namespace ash