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

Side by Side Diff: ash/display/resolution_notification_controller_unittest.cc

Issue 22662005: Don't remember best resolution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/resolution_notification_controller.h" 5 #include "ash/display/resolution_notification_controller.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 25 matching lines...) Expand all
36 Shell::GetInstance()->resolution_notification_controller()-> 36 Shell::GetInstance()->resolution_notification_controller()->
37 SetDisplayResolutionAndNotify( 37 SetDisplayResolutionAndNotify(
38 display.id(), 38 display.id(),
39 info.size_in_pixel(), 39 info.size_in_pixel(),
40 new_resolution, 40 new_resolution,
41 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, 41 base::Bind(&ResolutionNotificationControllerTest::OnAccepted,
42 base::Unretained(this))); 42 base::Unretained(this)));
43 43
44 // OnConfigurationChanged event won't be emitted in the test environment, 44 // OnConfigurationChanged event won't be emitted in the test environment,
45 // so invoke UpdateDisplay() to emit that event explicitly. 45 // so invoke UpdateDisplay() to emit that event explicitly.
46 std::string display_spec; 46 std::vector<DisplayInfo> info_list;
47 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 47 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
48 if (i > 0)
49 display_spec.append(",");
50 int64 id = display_manager->GetDisplayAt(i).id(); 48 int64 id = display_manager->GetDisplayAt(i).id();
51 gfx::Size size = (display.id() == id) ? 49 DisplayInfo info = display_manager->GetDisplayInfo(id);
52 new_resolution : display_manager->GetDisplayInfo(id).size_in_pixel(); 50 if (display.id() == id) {
53 display_spec.append(size.ToString()); 51 gfx::Rect bounds = info.bounds_in_pixel();
52 bounds.set_size(new_resolution);
53 info.SetBounds(bounds);
54 }
55 info_list.push_back(info);
54 } 56 }
55 UpdateDisplay(display_spec); 57 display_manager->OnNativeDisplaysChanged(info_list);
56 RunAllPendingInMessageLoop(); 58 RunAllPendingInMessageLoop();
57 } 59 }
58 60
59 void ClickOnNotification() { 61 void ClickOnNotification() {
60 message_center::MessageCenter::Get()->ClickOnNotification( 62 message_center::MessageCenter::Get()->ClickOnNotification(
61 ResolutionNotificationController::kNotificationId); 63 ResolutionNotificationController::kNotificationId);
62 } 64 }
63 65
64 void ClickOnNotificationButton(int index) { 66 void ClickOnNotificationButton(int index) {
65 message_center::MessageCenter::Get()->ClickOnNotificationButton( 67 message_center::MessageCenter::Get()->ClickOnNotificationButton(
(...skipping 26 matching lines...) Expand all
92 int accept_count_; 94 int accept_count_;
93 95
94 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); 96 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest);
95 }; 97 };
96 98
97 // Basic behaviors and verifies it doesn't cause crashes. 99 // Basic behaviors and verifies it doesn't cause crashes.
98 TEST_F(ResolutionNotificationControllerTest, Basic) { 100 TEST_F(ResolutionNotificationControllerTest, Basic) {
99 if (!SupportsMultipleDisplays()) 101 if (!SupportsMultipleDisplays())
100 return; 102 return;
101 103
102 UpdateDisplay("100x100,150x150"); 104 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200");
103 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 105 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
104 ash::internal::DisplayManager* display_manager = 106 ash::internal::DisplayManager* display_manager =
105 ash::Shell::GetInstance()->display_manager(); 107 ash::Shell::GetInstance()->display_manager();
106 ASSERT_EQ(0, accept_count()); 108 ASSERT_EQ(0, accept_count());
107 EXPECT_FALSE(IsNotificationVisible()); 109 EXPECT_FALSE(IsNotificationVisible());
108 110
109 // Changes the resolution and apply the result. 111 // Changes the resolution and apply the result.
110 SetDisplayResolutionAndNotify( 112 SetDisplayResolutionAndNotify(
111 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); 113 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200));
112 EXPECT_TRUE(IsNotificationVisible()); 114 EXPECT_TRUE(IsNotificationVisible());
113 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 115 EXPECT_FALSE(controller()->DoesNotificationTimeout());
114 gfx::Size resolution; 116 gfx::Size resolution;
115 EXPECT_TRUE( 117 EXPECT_TRUE(
116 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 118 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
117 EXPECT_EQ("200x200", resolution.ToString()); 119 EXPECT_EQ("200x200", resolution.ToString());
118 120
119 // Click the revert button, which reverts the resolution. 121 // Click the revert button, which reverts to the best resolution.
120 ClickOnNotificationButton(0); 122 ClickOnNotificationButton(0);
121 RunAllPendingInMessageLoop(); 123 RunAllPendingInMessageLoop();
122 EXPECT_FALSE(IsNotificationVisible()); 124 EXPECT_FALSE(IsNotificationVisible());
123 EXPECT_EQ(0, accept_count()); 125 EXPECT_EQ(0, accept_count());
124 EXPECT_TRUE( 126 EXPECT_FALSE(
125 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 127 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
126 EXPECT_EQ("150x150", resolution.ToString());
127 } 128 }
128 129
129 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { 130 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) {
130 if (!SupportsMultipleDisplays()) 131 if (!SupportsMultipleDisplays())
131 return; 132 return;
132 133
133 UpdateDisplay("100x100,150x150"); 134 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200");
134 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 135 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
135 ash::internal::DisplayManager* display_manager = 136 ash::internal::DisplayManager* display_manager =
136 ash::Shell::GetInstance()->display_manager(); 137 ash::Shell::GetInstance()->display_manager();
137 ASSERT_EQ(0, accept_count()); 138 ASSERT_EQ(0, accept_count());
138 EXPECT_FALSE(IsNotificationVisible()); 139 EXPECT_FALSE(IsNotificationVisible());
139 140
140 // Changes the resolution and apply the result. 141 // Changes the resolution and apply the result.
141 SetDisplayResolutionAndNotify( 142 SetDisplayResolutionAndNotify(
142 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); 143 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200));
143 EXPECT_TRUE(IsNotificationVisible()); 144 EXPECT_TRUE(IsNotificationVisible());
(...skipping 13 matching lines...) Expand all
157 EXPECT_EQ("200x200", resolution.ToString()); 158 EXPECT_EQ("200x200", resolution.ToString());
158 } 159 }
159 160
160 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { 161 TEST_F(ResolutionNotificationControllerTest, AcceptButton) {
161 if (!SupportsMultipleDisplays()) 162 if (!SupportsMultipleDisplays())
162 return; 163 return;
163 164
164 ash::internal::DisplayManager* display_manager = 165 ash::internal::DisplayManager* display_manager =
165 ash::Shell::GetInstance()->display_manager(); 166 ash::Shell::GetInstance()->display_manager();
166 167
167 UpdateDisplay("100x100"); 168 UpdateDisplay("300x300#300x300|200x200");
168 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay(); 169 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay();
169 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 170 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
170 EXPECT_TRUE(IsNotificationVisible()); 171 EXPECT_TRUE(IsNotificationVisible());
171 172
172 // If there's a single display only, it will have timeout and the first button 173 // If there's a single display only, it will have timeout and the first button
173 // becomes accept. 174 // becomes accept.
174 EXPECT_TRUE(controller()->DoesNotificationTimeout()); 175 EXPECT_TRUE(controller()->DoesNotificationTimeout());
175 ClickOnNotificationButton(0); 176 ClickOnNotificationButton(0);
176 EXPECT_FALSE(IsNotificationVisible()); 177 EXPECT_FALSE(IsNotificationVisible());
177 EXPECT_EQ(1, accept_count()); 178 EXPECT_EQ(1, accept_count());
178 gfx::Size resolution; 179 gfx::Size resolution;
179 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId( 180 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId(
180 display.id(), &resolution)); 181 display.id(), &resolution));
181 EXPECT_EQ("200x200", resolution.ToString()); 182 EXPECT_EQ("200x200", resolution.ToString());
182 183
183 // In that case the second button is revert. 184 // In that case the second button is revert.
184 UpdateDisplay("100x100"); 185 UpdateDisplay("300x300#300x300|200x200");
185 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 186 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
186 EXPECT_TRUE(IsNotificationVisible()); 187 EXPECT_TRUE(IsNotificationVisible());
187 188
188 EXPECT_TRUE(controller()->DoesNotificationTimeout()); 189 EXPECT_TRUE(controller()->DoesNotificationTimeout());
189 ClickOnNotificationButton(1); 190 ClickOnNotificationButton(1);
190 EXPECT_FALSE(IsNotificationVisible()); 191 EXPECT_FALSE(IsNotificationVisible());
191 EXPECT_EQ(1, accept_count()); 192 EXPECT_EQ(1, accept_count());
192 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId( 193 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId(
193 display.id(), &resolution)); 194 display.id(), &resolution));
194 EXPECT_EQ("100x100", resolution.ToString());
195 } 195 }
196 196
197 TEST_F(ResolutionNotificationControllerTest, Timeout) { 197 TEST_F(ResolutionNotificationControllerTest, Timeout) {
198 if (!SupportsMultipleDisplays()) 198 if (!SupportsMultipleDisplays())
199 return; 199 return;
200 200
201 UpdateDisplay("100x100"); 201 UpdateDisplay("300x300#300x300|200x200");
202 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay(); 202 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay();
203 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 203 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
204 204
205 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { 205 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) {
206 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " 206 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after "
207 << i << "-th timer tick"; 207 << i << "-th timer tick";
208 TickTimer(); 208 TickTimer();
209 RunAllPendingInMessageLoop(); 209 RunAllPendingInMessageLoop();
210 } 210 }
211 EXPECT_FALSE(IsNotificationVisible()); 211 EXPECT_FALSE(IsNotificationVisible());
212 EXPECT_EQ(0, accept_count()); 212 EXPECT_EQ(0, accept_count());
213 gfx::Size resolution; 213 gfx::Size resolution;
214 ash::internal::DisplayManager* display_manager = 214 ash::internal::DisplayManager* display_manager =
215 ash::Shell::GetInstance()->display_manager(); 215 ash::Shell::GetInstance()->display_manager();
216 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId( 216 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId(
217 display.id(), &resolution)); 217 display.id(), &resolution));
218 EXPECT_EQ("100x100", resolution.ToString());
219 } 218 }
220 219
221 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { 220 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) {
222 if (!SupportsMultipleDisplays()) 221 if (!SupportsMultipleDisplays())
223 return; 222 return;
224 223
225 UpdateDisplay("100x100,150x150"); 224 UpdateDisplay("300x300#300x300|200x200,200x200#250x250|200x200|100x100");
226 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 225 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
227 ash::internal::DisplayManager* display_manager = 226 ash::internal::DisplayManager* display_manager =
228 ash::Shell::GetInstance()->display_manager(); 227 ash::Shell::GetInstance()->display_manager();
229 SetDisplayResolutionAndNotify( 228 SetDisplayResolutionAndNotify(
230 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); 229 ScreenAsh::GetSecondaryDisplay(), gfx::Size(100, 100));
231 ASSERT_TRUE(IsNotificationVisible()); 230 ASSERT_TRUE(IsNotificationVisible());
232 231
233 // Disconnects the secondary display and verifies it doesn't cause crashes. 232 // Disconnects the secondary display and verifies it doesn't cause crashes.
234 UpdateDisplay("100x100"); 233 UpdateDisplay("300x300#300x300|200x200");
235 RunAllPendingInMessageLoop(); 234 RunAllPendingInMessageLoop();
236 EXPECT_FALSE(IsNotificationVisible()); 235 EXPECT_FALSE(IsNotificationVisible());
237 EXPECT_EQ(0, accept_count()); 236 EXPECT_EQ(0, accept_count());
238 gfx::Size resolution; 237 gfx::Size resolution;
239 EXPECT_TRUE( 238 EXPECT_TRUE(
240 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 239 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
241 EXPECT_EQ("150x150", resolution.ToString()); 240 EXPECT_EQ("200x200", resolution.ToString());
242 } 241 }
243 242
244 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { 243 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) {
245 if (!SupportsMultipleDisplays()) 244 if (!SupportsMultipleDisplays())
246 return; 245 return;
247 246
248 UpdateDisplay("100x100,150x150"); 247 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200");
249 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 248 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
250 ash::internal::DisplayManager* display_manager = 249 ash::internal::DisplayManager* display_manager =
251 ash::Shell::GetInstance()->display_manager(); 250 ash::Shell::GetInstance()->display_manager();
252 251
253 SetDisplayResolutionAndNotify( 252 SetDisplayResolutionAndNotify(
254 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); 253 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200));
255 EXPECT_TRUE(IsNotificationVisible()); 254 EXPECT_TRUE(IsNotificationVisible());
256 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 255 EXPECT_FALSE(controller()->DoesNotificationTimeout());
257 gfx::Size resolution; 256 gfx::Size resolution;
258 EXPECT_TRUE( 257 EXPECT_TRUE(
259 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 258 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
260 EXPECT_EQ("200x200", resolution.ToString()); 259 EXPECT_EQ("200x200", resolution.ToString());
261 260
262 // Invokes SetDisplayResolutionAndNotify during the previous notification is 261 // Invokes SetDisplayResolutionAndNotify during the previous notification is
263 // visible. 262 // visible.
264 SetDisplayResolutionAndNotify( 263 SetDisplayResolutionAndNotify(
265 ScreenAsh::GetSecondaryDisplay(), gfx::Size(250, 250)); 264 ScreenAsh::GetSecondaryDisplay(), gfx::Size(250, 250));
266 EXPECT_TRUE( 265 EXPECT_FALSE(
267 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 266 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
268 EXPECT_EQ("250x250", resolution.ToString());
269 267
270 // Then, click the revert button. Although |old_resolution| for the second 268 // Then, click the revert button. Although |old_resolution| for the second
271 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original 269 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original
272 // size 150x150. 270 // size 150x150.
273 ClickOnNotificationButton(0); 271 ClickOnNotificationButton(0);
274 RunAllPendingInMessageLoop(); 272 RunAllPendingInMessageLoop();
275 EXPECT_FALSE(IsNotificationVisible()); 273 EXPECT_FALSE(IsNotificationVisible());
276 EXPECT_EQ(0, accept_count()); 274 EXPECT_EQ(0, accept_count());
277 EXPECT_TRUE( 275 EXPECT_FALSE(
278 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 276 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
279 EXPECT_EQ("150x150", resolution.ToString());
280 } 277 }
281 278
282 } // namespace internal 279 } // namespace internal
283 } // namespace ash 280 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager_unittest.cc ('k') | chrome/browser/chromeos/display/display_preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698