OLD | NEW |
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_util.h" | 8 #include "ash/screen_util.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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
17 #include "ui/message_center/notification.h" | 17 #include "ui/message_center/notification.h" |
18 #include "ui/message_center/notification_list.h" | 18 #include "ui/message_center/notification_list.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 namespace internal { | |
22 | |
23 namespace { | 21 namespace { |
24 | 22 |
25 base::string16 ExpectedNotificationMessage(int64 display_id, | 23 base::string16 ExpectedNotificationMessage(int64 display_id, |
26 const gfx::Size& new_resolution) { | 24 const gfx::Size& new_resolution) { |
27 return l10n_util::GetStringFUTF16( | 25 return l10n_util::GetStringFUTF16( |
28 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 26 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
29 base::UTF8ToUTF16( | 27 base::UTF8ToUTF16( |
30 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 28 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
31 display_id)), | 29 display_id)), |
32 base::UTF8ToUTF16(new_resolution.ToString())); | 30 base::UTF8ToUTF16(new_resolution.ToString())); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 150 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
153 }; | 151 }; |
154 | 152 |
155 // Basic behaviors and verifies it doesn't cause crashes. | 153 // Basic behaviors and verifies it doesn't cause crashes. |
156 TEST_F(ResolutionNotificationControllerTest, Basic) { | 154 TEST_F(ResolutionNotificationControllerTest, Basic) { |
157 if (!SupportsMultipleDisplays()) | 155 if (!SupportsMultipleDisplays()) |
158 return; | 156 return; |
159 | 157 |
160 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 158 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
161 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 159 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
162 ash::internal::DisplayManager* display_manager = | 160 ash::DisplayManager* display_manager = |
163 ash::Shell::GetInstance()->display_manager(); | 161 ash::Shell::GetInstance()->display_manager(); |
164 ASSERT_EQ(0, accept_count()); | 162 ASSERT_EQ(0, accept_count()); |
165 EXPECT_FALSE(IsNotificationVisible()); | 163 EXPECT_FALSE(IsNotificationVisible()); |
166 | 164 |
167 // Changes the resolution and apply the result. | 165 // Changes the resolution and apply the result. |
168 SetDisplayResolutionAndNotify( | 166 SetDisplayResolutionAndNotify( |
169 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 167 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
170 EXPECT_TRUE(IsNotificationVisible()); | 168 EXPECT_TRUE(IsNotificationVisible()); |
171 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 169 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
172 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), | 170 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), |
(...skipping 12 matching lines...) Expand all Loading... |
185 EXPECT_EQ("250x250", mode.size.ToString()); | 183 EXPECT_EQ("250x250", mode.size.ToString()); |
186 EXPECT_EQ(59.0, mode.refresh_rate); | 184 EXPECT_EQ(59.0, mode.refresh_rate); |
187 } | 185 } |
188 | 186 |
189 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 187 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
190 if (!SupportsMultipleDisplays()) | 188 if (!SupportsMultipleDisplays()) |
191 return; | 189 return; |
192 | 190 |
193 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 191 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
194 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 192 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
195 ash::internal::DisplayManager* display_manager = | 193 ash::DisplayManager* display_manager = |
196 ash::Shell::GetInstance()->display_manager(); | 194 ash::Shell::GetInstance()->display_manager(); |
197 ASSERT_EQ(0, accept_count()); | 195 ASSERT_EQ(0, accept_count()); |
198 EXPECT_FALSE(IsNotificationVisible()); | 196 EXPECT_FALSE(IsNotificationVisible()); |
199 | 197 |
200 // Changes the resolution and apply the result. | 198 // Changes the resolution and apply the result. |
201 SetDisplayResolutionAndNotify( | 199 SetDisplayResolutionAndNotify( |
202 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 200 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
203 EXPECT_TRUE(IsNotificationVisible()); | 201 EXPECT_TRUE(IsNotificationVisible()); |
204 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 202 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
205 DisplayMode mode; | 203 DisplayMode mode; |
206 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 204 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
207 EXPECT_EQ("200x200", mode.size.ToString()); | 205 EXPECT_EQ("200x200", mode.size.ToString()); |
208 EXPECT_EQ(60.0, mode.refresh_rate); | 206 EXPECT_EQ(60.0, mode.refresh_rate); |
209 | 207 |
210 // Click the revert button, which reverts the resolution. | 208 // Click the revert button, which reverts the resolution. |
211 ClickOnNotification(); | 209 ClickOnNotification(); |
212 RunAllPendingInMessageLoop(); | 210 RunAllPendingInMessageLoop(); |
213 EXPECT_FALSE(IsNotificationVisible()); | 211 EXPECT_FALSE(IsNotificationVisible()); |
214 EXPECT_EQ(1, accept_count()); | 212 EXPECT_EQ(1, accept_count()); |
215 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 213 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
216 EXPECT_EQ("200x200", mode.size.ToString()); | 214 EXPECT_EQ("200x200", mode.size.ToString()); |
217 EXPECT_EQ(60.0, mode.refresh_rate); | 215 EXPECT_EQ(60.0, mode.refresh_rate); |
218 } | 216 } |
219 | 217 |
220 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { | 218 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { |
221 if (!SupportsMultipleDisplays()) | 219 if (!SupportsMultipleDisplays()) |
222 return; | 220 return; |
223 | 221 |
224 ash::internal::DisplayManager* display_manager = | 222 ash::DisplayManager* display_manager = |
225 ash::Shell::GetInstance()->display_manager(); | 223 ash::Shell::GetInstance()->display_manager(); |
226 | 224 |
227 UpdateDisplay("300x300#300x300%59|200x200%60"); | 225 UpdateDisplay("300x300#300x300%59|200x200%60"); |
228 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay(); | 226 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay(); |
229 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 227 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
230 EXPECT_TRUE(IsNotificationVisible()); | 228 EXPECT_TRUE(IsNotificationVisible()); |
231 | 229 |
232 // If there's a single display only, it will have timeout and the first button | 230 // If there's a single display only, it will have timeout and the first button |
233 // becomes accept. | 231 // becomes accept. |
234 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 232 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
(...skipping 20 matching lines...) Expand all Loading... |
255 EXPECT_EQ("300x300", mode.size.ToString()); | 253 EXPECT_EQ("300x300", mode.size.ToString()); |
256 EXPECT_EQ(59.0f, mode.refresh_rate); | 254 EXPECT_EQ(59.0f, mode.refresh_rate); |
257 } | 255 } |
258 | 256 |
259 TEST_F(ResolutionNotificationControllerTest, Close) { | 257 TEST_F(ResolutionNotificationControllerTest, Close) { |
260 if (!SupportsMultipleDisplays()) | 258 if (!SupportsMultipleDisplays()) |
261 return; | 259 return; |
262 | 260 |
263 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 261 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
264 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 262 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
265 ash::internal::DisplayManager* display_manager = | 263 ash::DisplayManager* display_manager = |
266 ash::Shell::GetInstance()->display_manager(); | 264 ash::Shell::GetInstance()->display_manager(); |
267 ASSERT_EQ(0, accept_count()); | 265 ASSERT_EQ(0, accept_count()); |
268 EXPECT_FALSE(IsNotificationVisible()); | 266 EXPECT_FALSE(IsNotificationVisible()); |
269 | 267 |
270 // Changes the resolution and apply the result. | 268 // Changes the resolution and apply the result. |
271 SetDisplayResolutionAndNotify( | 269 SetDisplayResolutionAndNotify( |
272 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 270 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
273 EXPECT_TRUE(IsNotificationVisible()); | 271 EXPECT_TRUE(IsNotificationVisible()); |
274 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 272 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
275 DisplayMode mode; | 273 DisplayMode mode; |
(...skipping 18 matching lines...) Expand all Loading... |
294 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 292 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
295 | 293 |
296 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { | 294 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { |
297 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " | 295 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " |
298 << i << "-th timer tick"; | 296 << i << "-th timer tick"; |
299 TickTimer(); | 297 TickTimer(); |
300 RunAllPendingInMessageLoop(); | 298 RunAllPendingInMessageLoop(); |
301 } | 299 } |
302 EXPECT_FALSE(IsNotificationVisible()); | 300 EXPECT_FALSE(IsNotificationVisible()); |
303 EXPECT_EQ(0, accept_count()); | 301 EXPECT_EQ(0, accept_count()); |
304 ash::internal::DisplayManager* display_manager = | 302 ash::DisplayManager* display_manager = |
305 ash::Shell::GetInstance()->display_manager(); | 303 ash::Shell::GetInstance()->display_manager(); |
306 DisplayMode mode; | 304 DisplayMode mode; |
307 EXPECT_TRUE( | 305 EXPECT_TRUE( |
308 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 306 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); |
309 EXPECT_EQ("300x300", mode.size.ToString()); | 307 EXPECT_EQ("300x300", mode.size.ToString()); |
310 EXPECT_EQ(59.0f, mode.refresh_rate); | 308 EXPECT_EQ(59.0f, mode.refresh_rate); |
311 } | 309 } |
312 | 310 |
313 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 311 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
314 if (!SupportsMultipleDisplays()) | 312 if (!SupportsMultipleDisplays()) |
315 return; | 313 return; |
316 | 314 |
317 UpdateDisplay("300x300#300x300%56|200x200%57," | 315 UpdateDisplay("300x300#300x300%56|200x200%57," |
318 "200x200#250x250%58|200x200%59|100x100%60"); | 316 "200x200#250x250%58|200x200%59|100x100%60"); |
319 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 317 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
320 ash::internal::DisplayManager* display_manager = | 318 ash::DisplayManager* display_manager = |
321 ash::Shell::GetInstance()->display_manager(); | 319 ash::Shell::GetInstance()->display_manager(); |
322 SetDisplayResolutionAndNotify( | 320 SetDisplayResolutionAndNotify( |
323 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); | 321 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); |
324 ASSERT_TRUE(IsNotificationVisible()); | 322 ASSERT_TRUE(IsNotificationVisible()); |
325 | 323 |
326 // Disconnects the secondary display and verifies it doesn't cause crashes. | 324 // Disconnects the secondary display and verifies it doesn't cause crashes. |
327 UpdateDisplay("300x300#300x300%56|200x200%57"); | 325 UpdateDisplay("300x300#300x300%56|200x200%57"); |
328 RunAllPendingInMessageLoop(); | 326 RunAllPendingInMessageLoop(); |
329 EXPECT_FALSE(IsNotificationVisible()); | 327 EXPECT_FALSE(IsNotificationVisible()); |
330 EXPECT_EQ(0, accept_count()); | 328 EXPECT_EQ(0, accept_count()); |
331 DisplayMode mode; | 329 DisplayMode mode; |
332 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 330 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
333 gfx::Size resolution; | 331 gfx::Size resolution; |
334 EXPECT_EQ("200x200", mode.size.ToString()); | 332 EXPECT_EQ("200x200", mode.size.ToString()); |
335 EXPECT_EQ(59.0f, mode.refresh_rate); | 333 EXPECT_EQ(59.0f, mode.refresh_rate); |
336 } | 334 } |
337 | 335 |
338 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 336 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
339 if (!SupportsMultipleDisplays()) | 337 if (!SupportsMultipleDisplays()) |
340 return; | 338 return; |
341 | 339 |
342 UpdateDisplay("300x300#300x300%56|200x200%57," | 340 UpdateDisplay("300x300#300x300%56|200x200%57," |
343 "250x250#250x250%58|200x200%59"); | 341 "250x250#250x250%58|200x200%59"); |
344 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 342 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
345 ash::internal::DisplayManager* display_manager = | 343 ash::DisplayManager* display_manager = |
346 ash::Shell::GetInstance()->display_manager(); | 344 ash::Shell::GetInstance()->display_manager(); |
347 | 345 |
348 SetDisplayResolutionAndNotify( | 346 SetDisplayResolutionAndNotify( |
349 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 347 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
350 EXPECT_TRUE(IsNotificationVisible()); | 348 EXPECT_TRUE(IsNotificationVisible()); |
351 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 349 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
352 DisplayMode mode; | 350 DisplayMode mode; |
353 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 351 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
354 EXPECT_EQ("200x200", mode.size.ToString()); | 352 EXPECT_EQ("200x200", mode.size.ToString()); |
355 EXPECT_EQ(59.0f, mode.refresh_rate); | 353 EXPECT_EQ(59.0f, mode.refresh_rate); |
(...skipping 18 matching lines...) Expand all Loading... |
374 EXPECT_EQ(58.0f, mode.refresh_rate); | 372 EXPECT_EQ(58.0f, mode.refresh_rate); |
375 } | 373 } |
376 | 374 |
377 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 375 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
378 if (!SupportsMultipleDisplays()) | 376 if (!SupportsMultipleDisplays()) |
379 return; | 377 return; |
380 | 378 |
381 UpdateDisplay("300x300#300x300%56|200x200%57," | 379 UpdateDisplay("300x300#300x300%56|200x200%57," |
382 "250x250#250x250%58|220x220%59|200x200%60"); | 380 "250x250#250x250%58|220x220%59|200x200%60"); |
383 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 381 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
384 ash::internal::DisplayManager* display_manager = | 382 ash::DisplayManager* display_manager = |
385 ash::Shell::GetInstance()->display_manager(); | 383 ash::Shell::GetInstance()->display_manager(); |
386 ASSERT_EQ(0, accept_count()); | 384 ASSERT_EQ(0, accept_count()); |
387 EXPECT_FALSE(IsNotificationVisible()); | 385 EXPECT_FALSE(IsNotificationVisible()); |
388 | 386 |
389 // Changes the resolution and apply the result. | 387 // Changes the resolution and apply the result. |
390 SetDisplayResolutionAndNotifyWithResolution( | 388 SetDisplayResolutionAndNotifyWithResolution( |
391 ScreenUtil::GetSecondaryDisplay(), | 389 ScreenUtil::GetSecondaryDisplay(), |
392 gfx::Size(220, 220), | 390 gfx::Size(220, 220), |
393 gfx::Size(200, 200)); | 391 gfx::Size(200, 200)); |
394 EXPECT_TRUE(IsNotificationVisible()); | 392 EXPECT_TRUE(IsNotificationVisible()); |
(...skipping 10 matching lines...) Expand all Loading... |
405 // Click the revert button, which reverts to the best resolution. | 403 // Click the revert button, which reverts to the best resolution. |
406 ClickOnNotificationButton(0); | 404 ClickOnNotificationButton(0); |
407 RunAllPendingInMessageLoop(); | 405 RunAllPendingInMessageLoop(); |
408 EXPECT_FALSE(IsNotificationVisible()); | 406 EXPECT_FALSE(IsNotificationVisible()); |
409 EXPECT_EQ(0, accept_count()); | 407 EXPECT_EQ(0, accept_count()); |
410 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 408 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
411 EXPECT_EQ("250x250", mode.size.ToString()); | 409 EXPECT_EQ("250x250", mode.size.ToString()); |
412 EXPECT_EQ(58.0f, mode.refresh_rate); | 410 EXPECT_EQ(58.0f, mode.refresh_rate); |
413 } | 411 } |
414 | 412 |
415 } // namespace internal | |
416 } // namespace ash | 413 } // namespace ash |
OLD | NEW |