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

Unified Diff: ui/display/fake_display_snapshot_unittests.cc

Issue 2395873002: Add more options to --screen-config flag. (Closed)
Patch Set: Improve tests / fixes. 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_snapshot.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..2f29e31ce96aa89ffc3a8c4189cc878fa01b7717
--- /dev/null
+++ b/ui/display/fake_display_snapshot_unittests.cc
@@ -0,0 +1,147 @@
+// 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/gtest/include/gtest/gtest.h"
+#include "ui/display/fake_display_snapshot.h"
+#include "ui/display/types/display_snapshot.h"
+
+namespace display {
+
+using DisplayModeList = ui::DisplaySnapshot::DisplayModeList;
+
+namespace {
+
+std::unique_ptr<ui::DisplaySnapshot> CreateSnapshot(const std::string& str) {
+ return FakeDisplaySnapshot::CreateFromSpec(1, str);
+}
+
+void ExpectDisplayMode(const ui::DisplayMode* mode,
Daniel Erat 2016/10/11 15:50:06 the main reason i don't like helper functions like
kylechar 2016/10/11 20:39:04 Hmm. That's a good point. Although I'm weary about
+ int width,
+ int height,
+ float refresh_rate = 60.0f) {
+ DCHECK(mode);
+ EXPECT_EQ(width, mode->size().width());
+ EXPECT_EQ(height, mode->size().height());
+ EXPECT_EQ(refresh_rate, mode->refresh_rate());
+}
+
+} // namespace
+
+TEST(FakeDisplaySnapshotTest, SizeOnly) {
+ auto display = CreateSnapshot("1024x768");
+
+ ASSERT_EQ(1u, display->modes().size());
+ ExpectDisplayMode(display->native_mode(), 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());
+ ExpectDisplayMode(display->native_mode(), 1024, 768, 120.0f);
+}
+
+TEST(FakeDisplaySnapshotTest, FullNativeModeWithDPI) {
+ auto display = CreateSnapshot("1000x1000%120^300");
+
+ ASSERT_EQ(1u, display->modes().size());
+ ExpectDisplayMode(display->native_mode(), 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());
+ ExpectDisplayMode(display->native_mode(), 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());
+ ExpectDisplayMode(modes[0].get(), 1920, 1080);
+ ExpectDisplayMode(modes[1].get(), 1600, 900);
+ ExpectDisplayMode(modes[2].get(), 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());
+ ExpectDisplayMode(modes[0].get(), 1920, 1080, 59.99f);
+ ExpectDisplayMode(modes[1].get(), 1600, 900, 90.0f);
+ ExpectDisplayMode(modes[2].get(), 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_snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698