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

Side by Side Diff: resolution_selector_test.cc

Issue 3304011: monitor_reconfig: Handle external monitors and add tests. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222//monitor_reconfig.git
Patch Set: apply review feedback Created 10 years, 3 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 | « resolution_selector.cc ('k') | no next file » | 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 (c) 2010 The Chromium OS 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 <vector>
6
7 #include <gflags/gflags.h>
8 #include <gtest/gtest.h>
9
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/string_util.h"
13 #include "monitor_reconfig/resolution_selector.h"
14
15 DEFINE_bool(logtostderr, false,
16 "Print debugging messages to stderr (suppressed otherwise)");
17
18 namespace monitor_reconfig {
19
20 using std::string;
21 using std::vector;
22
23 class ResolutionSelectorTest : public ::testing::Test {
24 protected:
25 virtual void SetUp() {}
26
27 // Add a mode to |lcd_modes_|.
28 void AddLcdMode(int width, int height) {
29 lcd_modes_.push_back(
30 ResolutionSelector::Mode(
31 width, height, StringPrintf("%dx%d", width, height)));
32 }
33
34 // Add a mode to |external_modes_|.
35 void AddExternalMode(int width, int height) {
36 external_modes_.push_back(
37 ResolutionSelector::Mode(
38 width, height, StringPrintf("%dx%d", width, height)));
39 }
40
41 // Ask |selector_| for the best resolutions and store them in
42 // |lcd_resolution_|, |external_resolution_|, and |screen_resolution_|.
43 // The return value from |FindBestResolutions()| is returned.
44 bool GetResolutions() {
45 return selector_.FindBestResolutions(lcd_modes_,
46 external_modes_,
47 &lcd_resolution_,
48 &external_resolution_,
49 &screen_resolution_);
50 }
51
52 ResolutionSelector selector_;
53
54 vector<ResolutionSelector::Mode> lcd_modes_;
55 vector<ResolutionSelector::Mode> external_modes_;
56
57 string lcd_resolution_;
58 string external_resolution_;
59 string screen_resolution_;
60 };
61
62 // We should use the LCD's max resolution when there's no external output
63 // connected.
64 TEST_F(ResolutionSelectorTest, NoExternalOutput) {
65 AddLcdMode(1024, 768);
66 AddLcdMode(800, 600);
67 ASSERT_TRUE(GetResolutions());
68 EXPECT_EQ("1024x768", lcd_resolution_);
69 EXPECT_EQ("", external_resolution_);
70 EXPECT_EQ("1024x768", screen_resolution_);
71 }
72
73 // When both outputs have the same max resolution, we should use it.
74 TEST_F(ResolutionSelectorTest, MatchingTopResolutions) {
75 AddLcdMode(1024, 768);
76 AddLcdMode(800, 600);
77 AddExternalMode(1024, 768);
78 AddExternalMode(800, 600);
79 ASSERT_TRUE(GetResolutions());
80 EXPECT_EQ("1024x768", lcd_resolution_);
81 EXPECT_EQ("1024x768", external_resolution_);
82 EXPECT_EQ("1024x768", screen_resolution_);
83 }
84
85 // We should use the highest shared resolution when the LCD has the higher
86 // max resolution.
87 TEST_F(ResolutionSelectorTest, LcdHasHigherResolution) {
88 AddLcdMode(1024, 768);
89 AddLcdMode(800, 600);
90 AddLcdMode(640, 480);
91 AddExternalMode(800, 600);
92 AddExternalMode(640, 480);
93 ASSERT_TRUE(GetResolutions());
94 EXPECT_EQ("800x600", lcd_resolution_);
95 EXPECT_EQ("800x600", external_resolution_);
96 EXPECT_EQ("800x600", screen_resolution_);
97 }
98
99 // We should use the highest shared resolution when the external output has
100 // the higher max resolution.
101 TEST_F(ResolutionSelectorTest, ExternalHasHigherResolution) {
102 AddLcdMode(800, 600);
103 AddLcdMode(640, 480);
104 AddExternalMode(1024, 768);
105 AddExternalMode(800, 600);
106 AddExternalMode(640, 480);
107 ASSERT_TRUE(GetResolutions());
108 EXPECT_EQ("800x600", lcd_resolution_);
109 EXPECT_EQ("800x600", external_resolution_);
110 EXPECT_EQ("800x600", screen_resolution_);
111 }
112
113 // When the maximum resolution offered by the two outputs is different, we
114 // should use the max resolution from the lower-res output.
115 TEST_F(ResolutionSelectorTest, MismatchedMaxResolution) {
116 AddLcdMode(1024, 600);
117 AddLcdMode(800, 600);
118 AddExternalMode(1280, 720);
119 AddExternalMode(1024, 768);
120 AddExternalMode(800, 600);
121 ASSERT_TRUE(GetResolutions());
122 EXPECT_EQ("1024x600", lcd_resolution_);
123 EXPECT_EQ("1024x768", external_resolution_);
124 EXPECT_EQ("1024x600", screen_resolution_);
125 }
126
127 // When the external output is large enough that we think it's a monitor,
128 // we should just use its maximum resolution instead of trying to find a
129 // size that'll also work for the LCD output.
130 TEST_F(ResolutionSelectorTest, ExternalOutputIsMonitor) {
131 AddLcdMode(1024, 768);
132 AddLcdMode(800, 600);
133 AddExternalMode(1600, 1200);
134 AddExternalMode(1280, 960);
135 AddExternalMode(1024, 768);
136 ASSERT_GE(external_modes_[0].width * external_modes_[0].height,
137 ResolutionSelector::kMaxProjectorPixels);
138 ASSERT_TRUE(GetResolutions());
139 EXPECT_EQ("1024x768", lcd_resolution_);
140 EXPECT_EQ("1600x1200", external_resolution_);
141 EXPECT_EQ("1600x1200", screen_resolution_);
142 }
143
144 // We should just fail if there's no common resolution between the two
145 // outputs.
146 TEST_F(ResolutionSelectorTest, FailIfNoCommonResolution) {
147 AddLcdMode(1024, 768);
148 AddExternalMode(1280, 600);
149 EXPECT_FALSE(GetResolutions());
150 }
151
152 } // namespace monitor_reconfig
153
154 int main(int argc, char** argv) {
155 google::ParseCommandLineFlags(&argc, &argv, true);
156 CommandLine::Init(argc, argv);
157 logging::InitLogging(NULL,
158 FLAGS_logtostderr ?
159 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG :
160 logging::LOG_NONE,
161 logging::DONT_LOCK_LOG_FILE,
162 logging::APPEND_TO_OLD_LOG_FILE);
163 ::testing::InitGoogleTest(&argc, argv);
164 return RUN_ALL_TESTS();
165 }
OLDNEW
« no previous file with comments | « resolution_selector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698