| Index: ash/system/chromeos/screen_layout_observer_unittest.cc
|
| diff --git a/ash/system/chromeos/screen_layout_observer_unittest.cc b/ash/system/chromeos/screen_layout_observer_unittest.cc
|
| index 25346d0f4899c67d8a6b532011353e5564dcd114..8d6477fcfb0669818495e0c9a79fc94f5c27c8ee 100644
|
| --- a/ash/system/chromeos/screen_layout_observer_unittest.cc
|
| +++ b/ash/system/chromeos/screen_layout_observer_unittest.cc
|
| @@ -16,6 +16,7 @@
|
| #include "ui/accessibility/ax_node_data.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/display/display.h"
|
| +#include "ui/display/display_layout_builder.h"
|
| #include "ui/display/manager/display_manager.h"
|
| #include "ui/message_center/message_center.h"
|
| #include "ui/message_center/notification.h"
|
| @@ -93,14 +94,12 @@ const message_center::Notification*
|
| ScreenLayoutObserverTest::GetDisplayNotification() const {
|
| const message_center::NotificationList::Notifications notifications =
|
| message_center::MessageCenter::Get()->GetVisibleNotifications();
|
| - for (message_center::NotificationList::Notifications::const_iterator iter =
|
| - notifications.begin();
|
| - iter != notifications.end(); ++iter) {
|
| - if ((*iter)->id() == ScreenLayoutObserver::kNotificationId)
|
| - return *iter;
|
| + for (const auto& notification : notifications) {
|
| + if (notification->id() == ScreenLayoutObserver::kNotificationId)
|
| + return notification;
|
| }
|
|
|
| - return NULL;
|
| + return nullptr;
|
| }
|
|
|
| TEST_F(ScreenLayoutObserverTest, DisplayNotifications) {
|
| @@ -228,10 +227,13 @@ TEST_F(ScreenLayoutObserverTest, DisplayConfigurationChangedTwice) {
|
| IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
|
| GetDisplayNotificationText());
|
|
|
| - // Back to the single display. It SHOULD remove the notification since the
|
| - // information is stale.
|
| + // Back to the single display. It should show that a display was removed.
|
| UpdateDisplay("400x400");
|
| - EXPECT_TRUE(GetDisplayNotificationText().empty());
|
| + EXPECT_TRUE(base::StartsWith(
|
| + GetDisplayNotificationText(),
|
| + l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
|
| + base::UTF8ToUTF16("")),
|
| + base::CompareCase::SENSITIVE));
|
| }
|
|
|
| // Verify the notification message content when one of the 2 displays that
|
| @@ -272,4 +274,180 @@ TEST_F(ScreenLayoutObserverTest, OverscanDisplay) {
|
| EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
|
| }
|
|
|
| +// Tests that exiting mirror mode by closing the lid shows the correct "docked
|
| +// mode" message.
|
| +TEST_F(ScreenLayoutObserverTest, ExitMirrorModeBecauseOfDockedModeMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + display::Display::SetInternalDisplayId(
|
| + display_manager()->GetSecondaryDisplay().id());
|
| +
|
| + // Mirroring.
|
| + display_manager()->SetSoftwareMirroring(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
|
| + GetMirroringDisplayName()),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Docked.
|
| + CloseNotification();
|
| + display_manager()->SetSoftwareMirroring(false);
|
| + display::Display::SetInternalDisplayId(display_manager()->first_display_id());
|
| + UpdateDisplay("200x200");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
|
| + GetDisplayNotificationText());
|
| + EXPECT_EQ(ash::SubstituteChromeOSDeviceType(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
|
| + GetDisplayNotificationAdditionalText());
|
| +}
|
| +
|
| +// Tests that exiting mirror mode because of adding a third display shows the
|
| +// correct "3+ displays mirror mode is not supported" message.
|
| +TEST_F(ScreenLayoutObserverTest, ExitMirrorModeBecauseOfThirdDisplayMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + display::Display::SetInternalDisplayId(
|
| + display_manager()->GetSecondaryDisplay().id());
|
| +
|
| + // Mirroring.
|
| + display_manager()->SetSoftwareMirroring(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
|
| + GetMirroringDisplayName()),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Adding a third display. Mirror mode for 3+ displays is not supported.
|
| + CloseNotification();
|
| + display_manager()->SetSoftwareMirroring(false);
|
| + UpdateDisplay("400x400,200x200,100x100");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED),
|
| + GetDisplayNotificationText());
|
| +}
|
| +
|
| +// Special case: tests that exiting mirror mode by removing a display shows the
|
| +// correct message.
|
| +TEST_F(ScreenLayoutObserverTest,
|
| + ExitMirrorModeNoInternalDisplayBecauseOfDisplayRemovedMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + display::Display::SetInternalDisplayId(
|
| + display_manager()->GetSecondaryDisplay().id());
|
| +
|
| + // Mirroring.
|
| + display_manager()->SetSoftwareMirroring(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
|
| + GetMirroringDisplayName()),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Removing one of the displays. We show that we exited mirror mode.
|
| + CloseNotification();
|
| + display_manager()->SetSoftwareMirroring(false);
|
| + UpdateDisplay("400x400");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
|
| + GetDisplayNotificationText());
|
| +}
|
| +
|
| +// Tests notification messages shown when adding and removing displays in
|
| +// extended mode.
|
| +TEST_F(ScreenLayoutObserverTest, AddingRemovingDisplayExtendedModeMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400");
|
| + EXPECT_TRUE(GetDisplayNotificationText().empty());
|
| +
|
| + // Adding a display in extended mode.
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Removing a display.
|
| + CloseNotification();
|
| + UpdateDisplay("400x400");
|
| + EXPECT_TRUE(base::StartsWith(
|
| + GetDisplayNotificationText(),
|
| + l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
|
| + base::UTF8ToUTF16("")),
|
| + base::CompareCase::SENSITIVE));
|
| +}
|
| +
|
| +// Tests notification messages shown when entering and exiting unified desktop
|
| +// mode.
|
| +TEST_F(ScreenLayoutObserverTest, EnteringExitingUnifiedModeMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400");
|
| + EXPECT_TRUE(GetDisplayNotificationText().empty());
|
| +
|
| + // Adding a display in extended mode.
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Enter unified mode.
|
| + display_manager()->SetUnifiedDesktopEnabled(true);
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Exit unified mode.
|
| + display_manager()->SetUnifiedDesktopEnabled(false);
|
| + EXPECT_EQ(
|
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Enter unified mode again and exit via closing the lid. The message "Exiting
|
| + // unified mode" should be shown.
|
| + display_manager()->SetUnifiedDesktopEnabled(true);
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
|
| + GetDisplayNotificationText());
|
| +
|
| + // Close the lid.
|
| + display::Display::SetInternalDisplayId(display_manager()->first_display_id());
|
| + UpdateDisplay("200x200");
|
| + display_manager()->SetUnifiedDesktopEnabled(false);
|
| + EXPECT_EQ(
|
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
|
| + GetDisplayNotificationText());
|
| +}
|
| +
|
| +// Special case: Tests notification messages shown when entering docked mode
|
| +// by closing the lid and the internal display is the secondary display.
|
| +TEST_F(ScreenLayoutObserverTest, DockedModeWithExternalPrimaryDisplayMessage) {
|
| + Shell::GetInstance()
|
| + ->screen_layout_observer()
|
| + ->set_show_notifications_for_testing(true);
|
| + UpdateDisplay("400x400,200x200");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
|
| + GetDisplayNotificationText());
|
| + CloseNotification();
|
| +
|
| + const int64_t primary_id = display_manager()->GetDisplayAt(0).id();
|
| + const int64_t internal_secondary_id = display_manager()->GetDisplayAt(1).id();
|
| + display::Display::SetInternalDisplayId(internal_secondary_id);
|
| + display::DisplayLayoutBuilder builder(primary_id);
|
| + builder.AddDisplayPlacement(internal_secondary_id, primary_id,
|
| + display::DisplayPlacement::LEFT, 0);
|
| + display_manager()->SetLayoutForCurrentDisplays(builder.Build());
|
| + EXPECT_TRUE(GetDisplayNotificationText().empty());
|
| +
|
| + // Close the lid and expect we show the docked mode message.
|
| + UpdateDisplay("400x400");
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
|
| + GetDisplayNotificationText());
|
| + EXPECT_EQ(ash::SubstituteChromeOSDeviceType(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
|
| + GetDisplayNotificationAdditionalText());
|
| +}
|
| +
|
| } // namespace ash
|
|
|