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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/display/fake_display_snapshot_unittests.cc
diff --git a/ui/display/fake_display_snapshot_unittests.cc b/ui/display/fake_display_snapshot_unittests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..addb4af407ea2508d8300619d5f90a18bbeeb514
--- /dev/null
+++ b/ui/display/fake_display_snapshot_unittests.cc
@@ -0,0 +1,169 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <memory>
+
+#include "base/macros.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/display/fake_display_snapshot.h"
+#include "ui/display/types/display_snapshot.h"
+
+using testing::Matcher;
+using DisplayModeList = ui::DisplaySnapshot::DisplayModeList;
+
+namespace display {
+
+namespace {
+
+std::unique_ptr<ui::DisplaySnapshot> CreateSnapshot(const std::string& str) {
+ return FakeDisplaySnapshot::CreateFromSpec(1, str);
+}
+
+// Matcher to check DisplayMode size and refresh rate.
+class IsModeMatcher : public testing::MatcherInterface<const ui::DisplayMode&> {
+ public:
+ IsModeMatcher(int width, int height, float refresh_rate)
+ : size_(width, height), refresh_rate_(refresh_rate) {}
+
+ 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.
+ testing::MatchResultListener* listener) const {
+ 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.
+ }
+
+ virtual void DescribeTo(std::ostream* os) const {
+ *os << "[" << size_.ToString() << " rate=" << refresh_rate_ << "]";
+ }
+
+ virtual void DescribeNegationTo(std::ostream* os) const {
+ *os << "not [" << size_.ToString() << " rate=" << refresh_rate_ << "]";
+ }
+
+ private:
+ gfx::Size size_;
+ float refresh_rate_;
+};
+
+inline Matcher<const ui::DisplayMode&> IsMode(int width,
+ int height,
+ float refresh_rate = 60.0f) {
+ return testing::MakeMatcher(new IsModeMatcher(width, height, refresh_rate));
+}
+
+} // namespace
+
+TEST(FakeDisplaySnapshotTest, SizeOnly) {
+ auto display = CreateSnapshot("1024x768");
+
+ ASSERT_EQ(1u, display->modes().size());
+ EXPECT_THAT(*display->native_mode(), IsMode(1024, 768));
+}
+
+TEST(FakeDisplaySnapshotTest, DefaultTypeIsUnknown) {
+ auto display = CreateSnapshot("1024x768");
+
+ ASSERT_EQ(1u, display->modes().size());
+ EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_UNKNOWN, display->type());
+}
+
+TEST(FakeDisplaySnapshotTest, FullNativeMode) {
+ auto display = CreateSnapshot("1024x768%120");
+
+ ASSERT_EQ(1u, display->modes().size());
+ EXPECT_THAT(*display->native_mode(), IsMode(1024, 768, 120.0f));
+}
+
+TEST(FakeDisplaySnapshotTest, FullNativeModeWithDPI) {
+ auto display = CreateSnapshot("1000x1000%120^300");
+
+ ASSERT_EQ(1u, display->modes().size());
+ EXPECT_THAT(*display->native_mode(), IsMode(1000, 1000, 120.0f));
+ EXPECT_EQ(85, display->physical_size().width());
+ EXPECT_EQ(85, display->physical_size().height());
+}
+
+TEST(FakeDisplaySnapshotTest, InternalDisplayWithSize) {
+ auto display = CreateSnapshot("1600x900/i");
+
+ ASSERT_EQ(1u, display->modes().size());
+ EXPECT_THAT(*display->native_mode(), IsMode(1600, 900));
+ EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
+}
+
+TEST(FakeDisplaySnapshotTest, MultipleOptions) {
+ auto display = CreateSnapshot("1600x900/aci");
+
+ EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
+ EXPECT_TRUE(display->has_color_correction_matrix());
+ EXPECT_TRUE(display->is_aspect_preserving_scaling());
+}
+
+TEST(FakeDisplaySnapshotTest, AlternateDisplayModes) {
+ auto display = CreateSnapshot("1920x1080#1600x900:1280x720/i");
+ const DisplayModeList& modes = display->modes();
+
+ ASSERT_EQ(3u, modes.size());
+ EXPECT_THAT(*modes[0], IsMode(1920, 1080));
+ EXPECT_THAT(*modes[1], IsMode(1600, 900));
+ EXPECT_THAT(*modes[2], IsMode(1280, 720));
+ EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
+}
+
+TEST(FakeDisplaySnapshotTest, ComplicatedSpecString) {
+ auto display =
+ CreateSnapshot("1920x1080%59.99#1600x900%90:1280x720%120^300/i");
+ const DisplayModeList& modes = display->modes();
+
+ ASSERT_EQ(3u, display->modes().size());
+ EXPECT_THAT(*modes[0], IsMode(1920, 1080, 59.99f));
+ EXPECT_THAT(*modes[1], IsMode(1600, 900, 90.0f));
+ EXPECT_THAT(*modes[2], IsMode(1280, 720, 120.0f));
+ EXPECT_EQ(163, display->physical_size().width());
+ EXPECT_EQ(91, display->physical_size().height());
+ EXPECT_EQ(ui::DISPLAY_CONNECTION_TYPE_INTERNAL, display->type());
+}
+
+TEST(FakeDisplaySnapshotTest, BadDisplayMode) {
+ // Need width and height.
+ EXPECT_EQ(nullptr, CreateSnapshot("1024"));
+ // Display height and width should be separated by 'x' not ','.
+ EXPECT_EQ(nullptr, CreateSnapshot("1024,768"));
+ // Random 'a' before spec starts.
+ EXPECT_EQ(nullptr, CreateSnapshot("a1024,768"));
+ // Need to provide a refresh rate after '%'.
+ EXPECT_EQ(nullptr, CreateSnapshot("1024,768%"));
+ EXPECT_EQ(nullptr, CreateSnapshot("1024,768%a"));
+ // Refresh rate should come before DPI.
+ EXPECT_EQ(nullptr, CreateSnapshot("1000x1000^300%120"));
+}
+
+TEST(FakeDisplaySnapshotTest, BadDPI) {
+ // DPI should be an integer value.
+ EXPECT_EQ(nullptr, CreateSnapshot("1024x768^a"));
+ EXPECT_EQ(nullptr, CreateSnapshot("1024x768^300d"));
+}
+
+TEST(FakeDisplaySnapshotTest, BadOptions) {
+ // Need a '/' before options.
+ EXPECT_EQ(nullptr, CreateSnapshot("1024x768i"));
+ // Character 'z' is not a valid option.
+ EXPECT_EQ(nullptr, CreateSnapshot("1600x900/z"));
+ EXPECT_EQ(nullptr, CreateSnapshot("1600x900/iz"));
+ // DPI should come before options.
+ EXPECT_EQ(nullptr, CreateSnapshot("1600x900/i^300"));
+}
+
+TEST(FakeDisplaySnapshotTest, BadOrderOptionsAndModes) {
+ // Options should come after alternate display modes.
+ auto display = CreateSnapshot("1920x1080/i#1600x900:1280x720");
+ EXPECT_EQ(nullptr, display);
+}
+
+TEST(FakeDisplaySnapshotTest, BadOrderModeSeparator) {
+ // Reverse the '#' and ':' delimiters for alternate display modes.
+ auto display = CreateSnapshot("1920x1080:1600x900#1280x720");
+ EXPECT_EQ(nullptr, display);
+}
+
+} // namespace display
« 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