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

Side by Side Diff: ash/system/chromeos/screen_layout_observer_unittest.cc

Issue 2644593003: Fix bugs in the display notification (Closed)
Patch Set: Adding 2 more test stories Created 3 years, 11 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
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/system/chromeos/screen_layout_observer.h" 5 #include "ash/system/chromeos/screen_layout_observer.h"
6 6
7 #include "ash/common/system/chromeos/devicetype_utils.h" 7 #include "ash/common/system/chromeos/devicetype_utils.h"
8 #include "ash/common/system/tray/system_tray.h" 8 #include "ash/common/system/tray/system_tray.h"
9 #include "ash/common/test/test_system_tray_delegate.h" 9 #include "ash/common/test/test_system_tray_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
16 #include "ui/accessibility/ax_node_data.h" 16 #include "ui/accessibility/ax_node_data.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/display/display.h" 18 #include "ui/display/display.h"
19 #include "ui/display/display_layout_builder.h"
19 #include "ui/display/manager/display_manager.h" 20 #include "ui/display/manager/display_manager.h"
20 #include "ui/message_center/message_center.h" 21 #include "ui/message_center/message_center.h"
21 #include "ui/message_center/notification.h" 22 #include "ui/message_center/notification.h"
22 #include "ui/message_center/notification_list.h" 23 #include "ui/message_center/notification_list.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 25
25 namespace ash { 26 namespace ash {
26 27
27 class ScreenLayoutObserverTest : public test::AshTestBase { 28 class ScreenLayoutObserverTest : public test::AshTestBase {
28 public: 29 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 base::string16 ScreenLayoutObserverTest::GetMirroringDisplayName() { 88 base::string16 ScreenLayoutObserverTest::GetMirroringDisplayName() {
88 return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId( 89 return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(
89 display_manager()->mirroring_display_id())); 90 display_manager()->mirroring_display_id()));
90 } 91 }
91 92
92 const message_center::Notification* 93 const message_center::Notification*
93 ScreenLayoutObserverTest::GetDisplayNotification() const { 94 ScreenLayoutObserverTest::GetDisplayNotification() const {
94 const message_center::NotificationList::Notifications notifications = 95 const message_center::NotificationList::Notifications notifications =
95 message_center::MessageCenter::Get()->GetVisibleNotifications(); 96 message_center::MessageCenter::Get()->GetVisibleNotifications();
96 for (message_center::NotificationList::Notifications::const_iterator iter = 97 for (const auto& notification : notifications) {
97 notifications.begin(); 98 if (notification->id() == ScreenLayoutObserver::kNotificationId)
98 iter != notifications.end(); ++iter) { 99 return notification;
99 if ((*iter)->id() == ScreenLayoutObserver::kNotificationId)
100 return *iter;
101 } 100 }
102 101
103 return NULL; 102 return nullptr;
104 } 103 }
105 104
106 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) { 105 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) {
107 Shell::GetInstance() 106 Shell::GetInstance()
108 ->screen_layout_observer() 107 ->screen_layout_observer()
109 ->set_show_notifications_for_testing(true); 108 ->set_show_notifications_for_testing(true);
110 109
111 UpdateDisplay("400x400"); 110 UpdateDisplay("400x400");
112 display::Display::SetInternalDisplayId(display_manager()->first_display_id()); 111 display::Display::SetInternalDisplayId(display_manager()->first_display_id());
113 EXPECT_TRUE(GetDisplayNotificationText().empty()); 112 EXPECT_TRUE(GetDisplayNotificationText().empty());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 GetDisplayNotificationText()); 220 GetDisplayNotificationText());
222 221
223 // OnDisplayConfigurationChanged() may be called more than once for a single 222 // OnDisplayConfigurationChanged() may be called more than once for a single
224 // update display in case of primary is swapped or recovered from dock mode. 223 // update display in case of primary is swapped or recovered from dock mode.
225 // Should not remove the notification in such case. 224 // Should not remove the notification in such case.
226 GetScreenLayoutObserver()->OnDisplayConfigurationChanged(); 225 GetScreenLayoutObserver()->OnDisplayConfigurationChanged();
227 EXPECT_EQ(l10n_util::GetStringUTF16( 226 EXPECT_EQ(l10n_util::GetStringUTF16(
228 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), 227 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
229 GetDisplayNotificationText()); 228 GetDisplayNotificationText());
230 229
231 // Back to the single display. It SHOULD remove the notification since the 230 // Back to the single display. It should show that a display was removed.
232 // information is stale.
233 UpdateDisplay("400x400"); 231 UpdateDisplay("400x400");
234 EXPECT_TRUE(GetDisplayNotificationText().empty()); 232 EXPECT_TRUE(base::StartsWith(
233 GetDisplayNotificationText(),
234 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
235 base::UTF8ToUTF16("")),
236 base::CompareCase::SENSITIVE));
235 } 237 }
236 238
237 // Verify the notification message content when one of the 2 displays that 239 // Verify the notification message content when one of the 2 displays that
238 // connected to the device is rotated. 240 // connected to the device is rotated.
239 TEST_F(ScreenLayoutObserverTest, UpdateAfterSuppressDisplayNotification) { 241 TEST_F(ScreenLayoutObserverTest, UpdateAfterSuppressDisplayNotification) {
240 UpdateDisplay("400x400,200x200"); 242 UpdateDisplay("400x400,200x200");
241 243
242 Shell::GetInstance() 244 Shell::GetInstance()
243 ->screen_layout_observer() 245 ->screen_layout_observer()
244 ->set_show_notifications_for_testing(true); 246 ->set_show_notifications_for_testing(true);
(...skipping 20 matching lines...) Expand all
265 EXPECT_TRUE(GetDisplayNotificationText().empty()); 267 EXPECT_TRUE(GetDisplayNotificationText().empty());
266 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); 268 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
267 269
268 // Reset the overscan. 270 // Reset the overscan.
269 Shell::GetInstance()->display_manager()->SetOverscanInsets( 271 Shell::GetInstance()->display_manager()->SetOverscanInsets(
270 display_manager()->GetSecondaryDisplay().id(), gfx::Insets()); 272 display_manager()->GetSecondaryDisplay().id(), gfx::Insets());
271 EXPECT_TRUE(GetDisplayNotificationText().empty()); 273 EXPECT_TRUE(GetDisplayNotificationText().empty());
272 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); 274 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
273 } 275 }
274 276
277 // Tests that exiting mirror mode by closing the lid shows the correct "docked
278 // mode" message.
279 TEST_F(ScreenLayoutObserverTest, ExitMirrorModeBecauseOfDockedModeMessage) {
280 Shell::GetInstance()
281 ->screen_layout_observer()
282 ->set_show_notifications_for_testing(true);
283 UpdateDisplay("400x400,200x200");
284 display::Display::SetInternalDisplayId(
285 display_manager()->GetSecondaryDisplay().id());
286
287 // Mirroring.
288 display_manager()->SetSoftwareMirroring(true);
289 UpdateDisplay("400x400,200x200");
290 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
291 GetMirroringDisplayName()),
292 GetDisplayNotificationText());
293
294 // Docked.
295 CloseNotification();
296 display_manager()->SetSoftwareMirroring(false);
297 display::Display::SetInternalDisplayId(display_manager()->first_display_id());
298 UpdateDisplay("200x200");
299 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
300 GetDisplayNotificationText());
301 EXPECT_EQ(ash::SubstituteChromeOSDeviceType(
302 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
303 GetDisplayNotificationAdditionalText());
304 }
305
306 // Tests that exiting mirror mode because of adding a third display shows the
307 // correct "3+ displays mirror mode is not supported" message.
308 TEST_F(ScreenLayoutObserverTest, ExitMirrorModeBecauseOfThirdDisplayMessage) {
309 Shell::GetInstance()
310 ->screen_layout_observer()
311 ->set_show_notifications_for_testing(true);
312 UpdateDisplay("400x400,200x200");
313 display::Display::SetInternalDisplayId(
314 display_manager()->GetSecondaryDisplay().id());
315
316 // Mirroring.
317 display_manager()->SetSoftwareMirroring(true);
318 UpdateDisplay("400x400,200x200");
319 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
320 GetMirroringDisplayName()),
321 GetDisplayNotificationText());
322
323 // Adding a third display. Mirror mode for 3+ displays is not supported.
324 CloseNotification();
325 display_manager()->SetSoftwareMirroring(false);
326 UpdateDisplay("400x400,200x200,100x100");
327 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED),
328 GetDisplayNotificationText());
329 }
330
331 // Special case: tests that exiting mirror mode by removing a display shows no
332 // notifications.
333 TEST_F(ScreenLayoutObserverTest,
334 ExitMirrorModeNoInternalDisplayBecauseOfDisplayRemovedMessage) {
335 Shell::GetInstance()
336 ->screen_layout_observer()
337 ->set_show_notifications_for_testing(true);
338 UpdateDisplay("400x400,200x200");
339 display::Display::SetInternalDisplayId(
340 display_manager()->GetSecondaryDisplay().id());
341
342 // Mirroring.
343 display_manager()->SetSoftwareMirroring(true);
344 UpdateDisplay("400x400,200x200");
345 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
346 GetMirroringDisplayName()),
347 GetDisplayNotificationText());
348
349 // Removing one of the displays. We show no notification.
350 CloseNotification();
351 display_manager()->SetSoftwareMirroring(false);
352 UpdateDisplay("400x400");
353 EXPECT_TRUE(GetDisplayNotificationText().empty());
354 }
355
356 // Tests notification messages shown when adding and removing displays in
357 // extended mode.
358 TEST_F(ScreenLayoutObserverTest, AddingRemovingDisplayExtendedModeMessage) {
359 Shell::GetInstance()
360 ->screen_layout_observer()
361 ->set_show_notifications_for_testing(true);
362 UpdateDisplay("400x400");
363 EXPECT_TRUE(GetDisplayNotificationText().empty());
364
365 // Adding a display in extended mode.
366 UpdateDisplay("400x400,200x200");
367 EXPECT_EQ(l10n_util::GetStringUTF16(
368 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
369 GetDisplayNotificationText());
370
371 // Removing a display.
372 CloseNotification();
373 UpdateDisplay("400x400");
374 EXPECT_TRUE(base::StartsWith(
375 GetDisplayNotificationText(),
376 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
377 base::UTF8ToUTF16("")),
378 base::CompareCase::SENSITIVE));
379 }
380
381 // Tests notification messages shown when entering and exiting unified desktop
382 // mode.
383 TEST_F(ScreenLayoutObserverTest, EnteringExitingUnifiedModeMessage) {
384 Shell::GetInstance()
385 ->screen_layout_observer()
386 ->set_show_notifications_for_testing(true);
387 UpdateDisplay("400x400");
388 EXPECT_TRUE(GetDisplayNotificationText().empty());
389
390 // Adding a display in extended mode.
391 UpdateDisplay("400x400,200x200");
392 EXPECT_EQ(l10n_util::GetStringUTF16(
393 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
394 GetDisplayNotificationText());
395
396 // Enter unified mode.
397 display_manager()->SetUnifiedDesktopEnabled(true);
398 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
399 GetDisplayNotificationText());
400
401 // Exit unified mode.
402 display_manager()->SetUnifiedDesktopEnabled(false);
403 EXPECT_EQ(
404 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
405 GetDisplayNotificationText());
406
407 // Enter unified mode again and exit via closing the lid. The message "Exiting
408 // unified mode" should be shown.
409 display_manager()->SetUnifiedDesktopEnabled(true);
410 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
411 GetDisplayNotificationText());
412
413 // Close the lid.
414 display::Display::SetInternalDisplayId(display_manager()->first_display_id());
415 UpdateDisplay("200x200");
416 display_manager()->SetUnifiedDesktopEnabled(false);
417 EXPECT_EQ(
418 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
419 GetDisplayNotificationText());
420 }
421
422 // Special case: Tests notification messages shown when entering docked mode
423 // by closing the lid and the internal display is the secondary display.
424 TEST_F(ScreenLayoutObserverTest, DockedModeWithExternalPrimaryDisplayMessage) {
425 Shell::GetInstance()
426 ->screen_layout_observer()
427 ->set_show_notifications_for_testing(true);
428 UpdateDisplay("400x400,200x200");
429 EXPECT_EQ(l10n_util::GetStringUTF16(
430 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
431 GetDisplayNotificationText());
432 CloseNotification();
433
434 const int64_t primary_id = display_manager()->GetDisplayAt(0).id();
435 const int64_t internal_secondary_id = display_manager()->GetDisplayAt(1).id();
436 display::Display::SetInternalDisplayId(internal_secondary_id);
437 display::DisplayLayoutBuilder builder(primary_id);
438 builder.AddDisplayPlacement(internal_secondary_id, primary_id,
439 display::DisplayPlacement::LEFT, 0);
440 display_manager()->SetLayoutForCurrentDisplays(builder.Build());
441 EXPECT_TRUE(GetDisplayNotificationText().empty());
442
443 // Close the lid and expect we show the docked mode message.
444 UpdateDisplay("400x400");
445 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
446 GetDisplayNotificationText());
447 EXPECT_EQ(ash::SubstituteChromeOSDeviceType(
448 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
449 GetDisplayNotificationAdditionalText());
450 }
451
275 } // namespace ash 452 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698