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

Side by Side Diff: ui/display/fake_display_snapshot_unittests.cc

Issue 2395873002: Add more options to --screen-config flag. (Closed)
Patch Set: Use matcher. Created 4 years, 2 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/fake_display_snapshot.cc ('k') | ui/display/types/display_mode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #include <memory>
6
7 #include "base/macros.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/fake_display_snapshot.h"
11 #include "ui/display/types/display_snapshot.h"
12
13 using testing::Matcher;
14 using DisplayModeList = ui::DisplaySnapshot::DisplayModeList;
15
16 namespace display {
17
18 namespace {
19
20 std::unique_ptr<ui::DisplaySnapshot> CreateSnapshot(const std::string& str) {
21 return FakeDisplaySnapshot::CreateFromSpec(1, str);
22 }
23
24 // Matcher to check DisplayMode size and refresh rate.
25 class IsModeMatcher : public testing::MatcherInterface<const ui::DisplayMode&> {
26 public:
27 IsModeMatcher(int width, int height, float refresh_rate)
28 : size_(width, height), refresh_rate_(refresh_rate) {}
29
30 virtual bool MatchAndExplain(const ui::DisplayMode& mode,
Daniel Erat 2016/10/11 21:00:31 if these are coming from MatcherInterface, you sho
kylechar 2016/10/12 13:24:50 Done.
31 testing::MatchResultListener* listener) const {
32 return mode.size() == size_ && mode.refresh_rate() == refresh_rate_;
Daniel Erat 2016/10/11 21:00:31 nit: maybe compare the rate difference against som
kylechar 2016/10/12 13:24:50 Done.
33 }
34
35 virtual void DescribeTo(std::ostream* os) const {
36 *os << "[" << size_.ToString() << " rate=" << refresh_rate_ << "]";
37 }
38
39 virtual void DescribeNegationTo(std::ostream* os) const {
40 *os << "not [" << size_.ToString() << " rate=" << refresh_rate_ << "]";
41 }
42
43 private:
44 gfx::Size size_;
45 float refresh_rate_;
46 };
47
48 inline Matcher<const ui::DisplayMode&> IsMode(int width,
49 int height,
50 float refresh_rate = 60.0f) {
51 return testing::MakeMatcher(new IsModeMatcher(width, height, refresh_rate));
52 }
53
54 } // namespace
55
56 TEST(FakeDisplaySnapshotTest, SizeOnly) {
57 auto display = CreateSnapshot("1024x768");
58
59 ASSERT_EQ(1u, display->modes().size());
60 EXPECT_THAT(*display->native_mode(), IsMode(1024, 768));
61 }
62
63 TEST(FakeDisplaySnapshotTest, DefaultTypeIsUnknown) {
64 auto display = CreateSnapshot("1024x768");
65
66 ASSERT_EQ(1u, display->modes().size());
67 EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_UNKNOWN, display->type());
68 }
69
70 TEST(FakeDisplaySnapshotTest, FullNativeMode) {
71 auto display = CreateSnapshot("1024x768%120");
72
73 ASSERT_EQ(1u, display->modes().size());
74 EXPECT_THAT(*display->native_mode(), IsMode(1024, 768, 120.0f));
75 }
76
77 TEST(FakeDisplaySnapshotTest, FullNativeModeWithDPI) {
78 auto display = CreateSnapshot("1000x1000%120^300");
79
80 ASSERT_EQ(1u, display->modes().size());
81 EXPECT_THAT(*display->native_mode(), IsMode(1000, 1000, 120.0f));
82 EXPECT_EQ(85, display->physical_size().width());
83 EXPECT_EQ(85, display->physical_size().height());
84 }
85
86 TEST(FakeDisplaySnapshotTest, InternalDisplayWithSize) {
87 auto display = CreateSnapshot("1600x900/i");
88
89 ASSERT_EQ(1u, display->modes().size());
90 EXPECT_THAT(*display->native_mode(), IsMode(1600, 900));
91 EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
92 }
93
94 TEST(FakeDisplaySnapshotTest, MultipleOptions) {
95 auto display = CreateSnapshot("1600x900/aci");
96
97 EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
98 EXPECT_TRUE(display->has_color_correction_matrix());
99 EXPECT_TRUE(display->is_aspect_preserving_scaling());
100 }
101
102 TEST(FakeDisplaySnapshotTest, AlternateDisplayModes) {
103 auto display = CreateSnapshot("1920x1080#1600x900:1280x720/i");
104 const DisplayModeList& modes = display->modes();
105
106 ASSERT_EQ(3u, modes.size());
107 EXPECT_THAT(*modes[0], IsMode(1920, 1080));
108 EXPECT_THAT(*modes[1], IsMode(1600, 900));
109 EXPECT_THAT(*modes[2], IsMode(1280, 720));
110 EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
111 }
112
113 TEST(FakeDisplaySnapshotTest, ComplicatedSpecString) {
114 auto display =
115 CreateSnapshot("1920x1080%59.99#1600x900%90:1280x720%120^300/i");
116 const DisplayModeList& modes = display->modes();
117
118 ASSERT_EQ(3u, display->modes().size());
119 EXPECT_THAT(*modes[0], IsMode(1920, 1080, 59.99f));
120 EXPECT_THAT(*modes[1], IsMode(1600, 900, 90.0f));
121 EXPECT_THAT(*modes[2], IsMode(1280, 720, 120.0f));
122 EXPECT_EQ(163, display->physical_size().width());
123 EXPECT_EQ(91, display->physical_size().height());
124 EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
125 }
126
127 TEST(FakeDisplaySnapshotTest, BadDisplayMode) {
128 // Need width and height.
129 EXPECT_EQ(nullptr, CreateSnapshot("1024"));
130 // Display height and width should be separated by 'x' not ','.
131 EXPECT_EQ(nullptr, CreateSnapshot("1024,768"));
132 // Random 'a' before spec starts.
133 EXPECT_EQ(nullptr, CreateSnapshot("a1024,768"));
134 // Need to provide a refresh rate after '%'.
135 EXPECT_EQ(nullptr, CreateSnapshot("1024,768%"));
136 EXPECT_EQ(nullptr, CreateSnapshot("1024,768%a"));
137 // Refresh rate should come before DPI.
138 EXPECT_EQ(nullptr, CreateSnapshot("1000x1000^300%120"));
139 }
140
141 TEST(FakeDisplaySnapshotTest, BadDPI) {
142 // DPI should be an integer value.
143 EXPECT_EQ(nullptr, CreateSnapshot("1024x768^a"));
144 EXPECT_EQ(nullptr, CreateSnapshot("1024x768^300d"));
145 }
146
147 TEST(FakeDisplaySnapshotTest, BadOptions) {
148 // Need a '/' before options.
149 EXPECT_EQ(nullptr, CreateSnapshot("1024x768i"));
150 // Character 'z' is not a valid option.
151 EXPECT_EQ(nullptr, CreateSnapshot("1600x900/z"));
152 EXPECT_EQ(nullptr, CreateSnapshot("1600x900/iz"));
153 // DPI should come before options.
154 EXPECT_EQ(nullptr, CreateSnapshot("1600x900/i^300"));
155 }
156
157 TEST(FakeDisplaySnapshotTest, BadOrderOptionsAndModes) {
158 // Options should come after alternate display modes.
159 auto display = CreateSnapshot("1920x1080/i#1600x900:1280x720");
160 EXPECT_EQ(nullptr, display);
161 }
162
163 TEST(FakeDisplaySnapshotTest, BadOrderModeSeparator) {
164 // Reverse the '#' and ':' delimiters for alternate display modes.
165 auto display = CreateSnapshot("1920x1080:1600x900#1280x720");
166 EXPECT_EQ(nullptr, display);
167 }
168
169 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/fake_display_snapshot.cc ('k') | ui/display/types/display_mode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698