Home | History | Annotate | Download | only in chromeos
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ash/system/chromeos/tray_display.h"
      6 
      7 #include "ash/display/display_manager.h"
      8 #include "ash/root_window_controller.h"
      9 #include "ash/screen_ash.h"
     10 #include "ash/shell.h"
     11 #include "ash/system/tray/system_tray.h"
     12 #include "ash/test/ash_test_base.h"
     13 #include "ash/test/test_system_tray_delegate.h"
     14 #include "base/strings/string16.h"
     15 #include "base/strings/utf_string_conversions.h"
     16 #include "grit/ash_strings.h"
     17 #include "ui/base/l10n/l10n_util.h"
     18 #include "ui/gfx/display.h"
     19 #include "ui/message_center/message_center.h"
     20 #include "ui/message_center/notification.h"
     21 #include "ui/message_center/notification_list.h"
     22 #include "ui/views/controls/label.h"
     23 
     24 namespace ash {
     25 namespace internal {
     26 
     27 base::string16 GetTooltipText(const base::string16& headline,
     28                               const base::string16& name1,
     29                               const std::string& data1,
     30                               const base::string16& name2,
     31                               const std::string& data2) {
     32   std::vector<base::string16> lines;
     33   lines.push_back(headline);
     34   if (data1.empty()) {
     35     lines.push_back(name1);
     36   } else {
     37     lines.push_back(l10n_util::GetStringFUTF16(
     38         IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
     39         name1, UTF8ToUTF16(data1)));
     40   }
     41   if (!name2.empty()) {
     42     lines.push_back(l10n_util::GetStringFUTF16(
     43         IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
     44         name2, UTF8ToUTF16(data2)));
     45   }
     46   return JoinString(lines, '\n');
     47 }
     48 
     49 base::string16 GetMirroredTooltipText(const base::string16& headline,
     50                                       const base::string16& name,
     51                                       const std::string& data) {
     52   return GetTooltipText(headline, name, data, base::string16(), "");
     53 }
     54 
     55 base::string16 GetFirstDisplayName() {
     56   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
     57   return UTF8ToUTF16(display_manager->GetDisplayNameForId(
     58       display_manager->first_display_id()));
     59 }
     60 
     61 base::string16 GetSecondDisplayName() {
     62   return UTF8ToUTF16(
     63       Shell::GetInstance()->display_manager()->GetDisplayNameForId(
     64           ScreenAsh::GetSecondaryDisplay().id()));
     65 }
     66 
     67 base::string16 GetMirroredDisplayName() {
     68   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
     69   return UTF8ToUTF16(display_manager->GetDisplayNameForId(
     70       display_manager->mirrored_display_id()));
     71 }
     72 
     73 class TrayDisplayTest : public ash::test::AshTestBase {
     74  public:
     75   TrayDisplayTest();
     76   virtual ~TrayDisplayTest();
     77 
     78   virtual void SetUp() OVERRIDE;
     79 
     80  protected:
     81   SystemTray* tray() { return tray_; }
     82   TrayDisplay* tray_display() { return tray_display_; }
     83 
     84   void CloseNotification();
     85   bool IsDisplayVisibleInTray() const;
     86   base::string16 GetTrayDisplayText() const;
     87   base::string16 GetTrayDisplayTooltipText() const;
     88   base::string16 GetDisplayNotificationText() const;
     89   base::string16 GetDisplayNotificationAdditionalText() const;
     90 
     91  private:
     92   const message_center::Notification* GetDisplayNotification() const;
     93 
     94   // Weak reference, owned by Shell.
     95   SystemTray* tray_;
     96 
     97   // Weak reference, owned by |tray_|.
     98   TrayDisplay* tray_display_;
     99 
    100   DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest);
    101 };
    102 
    103 TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) {
    104 }
    105 
    106 TrayDisplayTest::~TrayDisplayTest() {
    107 }
    108 
    109 void TrayDisplayTest::SetUp() {
    110   ash::test::AshTestBase::SetUp();
    111   tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray();
    112   tray_display_ = new TrayDisplay(tray_);
    113   tray_->AddTrayItem(tray_display_);
    114 }
    115 
    116 void TrayDisplayTest::CloseNotification() {
    117   message_center::MessageCenter::Get()->RemoveNotification(
    118       TrayDisplay::kNotificationId, false);
    119   RunAllPendingInMessageLoop();
    120 }
    121 
    122 bool TrayDisplayTest::IsDisplayVisibleInTray() const {
    123   return tray_->HasSystemBubble() &&
    124       tray_display_->default_view() &&
    125       tray_display_->default_view()->visible();
    126 }
    127 
    128 base::string16 TrayDisplayTest::GetTrayDisplayText() const {
    129   return tray_display_->GetDefaultViewMessage();
    130 }
    131 
    132 base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() const {
    133   if (!tray_display_->default_view())
    134     return base::string16();
    135 
    136   base::string16 tooltip;
    137   if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip))
    138     return base::string16();
    139   return tooltip;
    140 }
    141 
    142 base::string16 TrayDisplayTest::GetDisplayNotificationText() const {
    143   const message_center::Notification* notification = GetDisplayNotification();
    144   return notification ? notification->title() : base::string16();
    145 }
    146 
    147 base::string16 TrayDisplayTest::GetDisplayNotificationAdditionalText() const {
    148   const message_center::Notification* notification = GetDisplayNotification();
    149   return notification ? notification->message() : base::string16();
    150 }
    151 
    152 const message_center::Notification* TrayDisplayTest::GetDisplayNotification()
    153     const {
    154   const message_center::NotificationList::Notifications notifications =
    155       message_center::MessageCenter::Get()->GetVisibleNotifications();
    156   for (message_center::NotificationList::Notifications::const_iterator iter =
    157            notifications.begin(); iter != notifications.end(); ++iter) {
    158     if ((*iter)->id() == TrayDisplay::kNotificationId)
    159       return *iter;
    160   }
    161 
    162   return NULL;
    163 }
    164 
    165 TEST_F(TrayDisplayTest, NoInternalDisplay) {
    166   UpdateDisplay("400x400");
    167   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    168   EXPECT_FALSE(IsDisplayVisibleInTray());
    169 
    170   UpdateDisplay("400x400,200x200");
    171   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    172   EXPECT_TRUE(IsDisplayVisibleInTray());
    173   base::string16 expected = l10n_util::GetStringUTF16(
    174       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
    175   base::string16 first_name = GetFirstDisplayName();
    176   EXPECT_EQ(expected, GetTrayDisplayText());
    177   EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400",
    178                            GetSecondDisplayName(), "200x200"),
    179             GetTrayDisplayTooltipText());
    180 
    181   // mirroring
    182   Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true);
    183   UpdateDisplay("400x400,200x200");
    184   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    185   EXPECT_TRUE(IsDisplayVisibleInTray());
    186   expected = l10n_util::GetStringUTF16(
    187       IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
    188   EXPECT_EQ(expected, GetTrayDisplayText());
    189   EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"),
    190             GetTrayDisplayTooltipText());
    191 }
    192 
    193 TEST_F(TrayDisplayTest, InternalDisplay) {
    194   UpdateDisplay("400x400");
    195   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
    196   gfx::Display::SetInternalDisplayId(display_manager->first_display_id());
    197 
    198   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    199   EXPECT_FALSE(IsDisplayVisibleInTray());
    200 
    201   // Extended
    202   UpdateDisplay("400x400,200x200");
    203   string16 expected = l10n_util::GetStringFUTF16(
    204       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName());
    205   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    206   EXPECT_TRUE(IsDisplayVisibleInTray());
    207   EXPECT_EQ(expected, GetTrayDisplayText());
    208   EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400",
    209                            GetSecondDisplayName(), "200x200"),
    210             GetTrayDisplayTooltipText());
    211 
    212   // Mirroring
    213   display_manager->SetSoftwareMirroring(true);
    214   UpdateDisplay("400x400,200x200");
    215   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    216   EXPECT_TRUE(IsDisplayVisibleInTray());
    217 
    218   expected = l10n_util::GetStringFUTF16(
    219       IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName());
    220   EXPECT_EQ(expected, GetTrayDisplayText());
    221   EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"),
    222             GetTrayDisplayTooltipText());
    223 }
    224 
    225 TEST_F(TrayDisplayTest, InternalDisplayResized) {
    226   UpdateDisplay("400x400 (at) 1.5");
    227   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
    228   gfx::Display::SetInternalDisplayId(display_manager->first_display_id());
    229 
    230   // Shows the tray_display even though there's a single-display.
    231   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    232   EXPECT_TRUE(IsDisplayVisibleInTray());
    233   base::string16 internal_info = l10n_util::GetStringFUTF16(
    234       IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
    235       GetFirstDisplayName(), UTF8ToUTF16("600x600"));
    236   EXPECT_EQ(internal_info, GetTrayDisplayText());
    237   EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600",
    238                            base::string16(), std::string()),
    239             GetTrayDisplayTooltipText());
    240 
    241   // Extended
    242   UpdateDisplay("400x400 (at) 1.5,200x200");
    243   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    244   EXPECT_TRUE(IsDisplayVisibleInTray());
    245   base::string16 expected = l10n_util::GetStringFUTF16(
    246       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName());
    247   EXPECT_EQ(expected, GetTrayDisplayText());
    248   EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600",
    249                            GetSecondDisplayName(), "200x200"),
    250             GetTrayDisplayTooltipText());
    251 
    252   // Mirroring
    253   display_manager->SetSoftwareMirroring(true);
    254   UpdateDisplay("400x400 (at) 1.5,200x200");
    255   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    256   EXPECT_TRUE(IsDisplayVisibleInTray());
    257   expected = l10n_util::GetStringFUTF16(
    258       IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName());
    259   EXPECT_EQ(expected, GetTrayDisplayText());
    260   EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "600x600"),
    261             GetTrayDisplayTooltipText());
    262 
    263   // Closed lid mode.
    264   display_manager->SetSoftwareMirroring(false);
    265   UpdateDisplay("400x400 (at) 1.5,200x200");
    266   gfx::Display::SetInternalDisplayId(ScreenAsh::GetSecondaryDisplay().id());
    267   UpdateDisplay("400x400 (at) 1.5");
    268   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    269   EXPECT_TRUE(IsDisplayVisibleInTray());
    270   expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
    271   EXPECT_EQ(expected, GetTrayDisplayText());
    272   EXPECT_EQ(
    273       GetTooltipText(
    274           expected, GetFirstDisplayName(), "600x600", base::string16(), ""),
    275       GetTrayDisplayTooltipText());
    276 }
    277 
    278 TEST_F(TrayDisplayTest, ExternalDisplayResized) {
    279   UpdateDisplay("400x400");
    280   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
    281   gfx::Display::SetInternalDisplayId(display_manager->first_display_id());
    282 
    283   // Shows the tray_display even though there's a single-display.
    284   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    285   EXPECT_FALSE(IsDisplayVisibleInTray());
    286 
    287   // Extended
    288   UpdateDisplay("400x400,200x200 (at) 1.5");
    289   const gfx::Display& secondary_display = ScreenAsh::GetSecondaryDisplay();
    290 
    291   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    292   EXPECT_TRUE(IsDisplayVisibleInTray());
    293   base::string16 expected = l10n_util::GetStringFUTF16(
    294       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
    295       l10n_util::GetStringFUTF16(
    296           IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
    297           GetSecondDisplayName(),
    298           UTF8ToUTF16(secondary_display.size().ToString())));
    299   EXPECT_EQ(expected, GetTrayDisplayText());
    300   EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400",
    301                            GetSecondDisplayName(), "300x300"),
    302             GetTrayDisplayTooltipText());
    303 
    304   // Mirroring
    305   display_manager->SetSoftwareMirroring(true);
    306   UpdateDisplay("400x400,200x200 (at) 1.5");
    307   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    308   EXPECT_TRUE(IsDisplayVisibleInTray());
    309   expected = l10n_util::GetStringFUTF16(
    310       IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName());
    311   EXPECT_EQ(expected, GetTrayDisplayText());
    312   EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"),
    313             GetTrayDisplayTooltipText());
    314 }
    315 
    316 TEST_F(TrayDisplayTest, OverscanDisplay) {
    317   UpdateDisplay("400x400,300x300/o");
    318   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
    319   gfx::Display::SetInternalDisplayId(display_manager->first_display_id());
    320 
    321   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    322   EXPECT_TRUE(IsDisplayVisibleInTray());
    323 
    324   // /o creates the default overscan, and if overscan is set, the annotation
    325   // should be the size.
    326   base::string16 overscan = l10n_util::GetStringUTF16(
    327       IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN);
    328   base::string16 headline = l10n_util::GetStringFUTF16(
    329       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
    330       l10n_util::GetStringFUTF16(
    331           IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
    332           GetSecondDisplayName(), UTF8ToUTF16("286x286")));
    333   std::string second_data = l10n_util::GetStringFUTF8(
    334       IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION,
    335       UTF8ToUTF16("286x286"), overscan);
    336   EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400",
    337                            GetSecondDisplayName(), second_data),
    338             GetTrayDisplayTooltipText());
    339 
    340   // reset the overscan.
    341   display_manager->SetOverscanInsets(
    342       ScreenAsh::GetSecondaryDisplay().id(), gfx::Insets());
    343   headline = l10n_util::GetStringFUTF16(
    344       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
    345       l10n_util::GetStringFUTF16(
    346           IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
    347           GetSecondDisplayName(), overscan));
    348   second_data = l10n_util::GetStringFUTF8(
    349       IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION,
    350       UTF8ToUTF16("300x300"), overscan);
    351   EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400",
    352                            GetSecondDisplayName(), second_data),
    353             GetTrayDisplayTooltipText());
    354 }
    355 
    356 TEST_F(TrayDisplayTest, UpdateDuringDisplayConfigurationChange) {
    357   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    358   EXPECT_FALSE(IsDisplayVisibleInTray());
    359 
    360   UpdateDisplay("400x400 (at) 1.5");
    361   EXPECT_TRUE(tray()->HasSystemBubble());
    362   EXPECT_TRUE(IsDisplayVisibleInTray());
    363   base::string16 internal_info = l10n_util::GetStringFUTF16(
    364       IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
    365       GetFirstDisplayName(), UTF8ToUTF16("600x600"));
    366   EXPECT_EQ(internal_info, GetTrayDisplayText());
    367   EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600",
    368                            base::string16(), std::string()),
    369             GetTrayDisplayTooltipText());
    370 
    371   UpdateDisplay("400x400,200x200");
    372   EXPECT_TRUE(tray()->HasSystemBubble());
    373   EXPECT_TRUE(IsDisplayVisibleInTray());
    374   base::string16 expected = l10n_util::GetStringUTF16(
    375       IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
    376   base::string16 first_name = GetFirstDisplayName();
    377   EXPECT_EQ(expected, GetTrayDisplayText());
    378   EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400",
    379                            GetSecondDisplayName(), "200x200"),
    380             GetTrayDisplayTooltipText());
    381 
    382   UpdateDisplay("400x400 (at) 1.5");
    383   tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
    384 
    385   // Back to the default state, the display tray item should disappear.
    386   UpdateDisplay("400x400");
    387   EXPECT_TRUE(tray()->HasSystemBubble());
    388   EXPECT_FALSE(IsDisplayVisibleInTray());
    389 }
    390 
    391 TEST_F(TrayDisplayTest, DisplayNotifications) {
    392   test::TestSystemTrayDelegate* tray_delegate =
    393       static_cast<test::TestSystemTrayDelegate*>(
    394           Shell::GetInstance()->system_tray_delegate());
    395   tray_delegate->set_should_show_display_notification(true);
    396 
    397   UpdateDisplay("400x400");
    398   DisplayManager* display_manager = Shell::GetInstance()->display_manager();
    399   gfx::Display::SetInternalDisplayId(display_manager->first_display_id());
    400   EXPECT_TRUE(GetDisplayNotificationText().empty());
    401 
    402   // rotation.
    403   UpdateDisplay("400x400/r");
    404   EXPECT_EQ(
    405       l10n_util::GetStringFUTF16(
    406           IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
    407           l10n_util::GetStringUTF16(
    408               IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
    409       GetDisplayNotificationText());
    410   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    411 
    412   CloseNotification();
    413   UpdateDisplay("400x400");
    414   EXPECT_EQ(
    415       l10n_util::GetStringFUTF16(
    416           IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
    417           l10n_util::GetStringUTF16(
    418               IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION)),
    419       GetDisplayNotificationText());
    420   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    421 
    422   // UI-scale
    423   CloseNotification();
    424   UpdateDisplay("400x400 (at) 1.5");
    425   EXPECT_EQ(
    426       l10n_util::GetStringFUTF16(
    427           IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
    428           GetFirstDisplayName(), UTF8ToUTF16("600x600")),
    429       GetDisplayNotificationText());
    430   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    431 
    432   // UI-scale to 1.0
    433   CloseNotification();
    434   UpdateDisplay("400x400");
    435   EXPECT_EQ(
    436       l10n_util::GetStringFUTF16(
    437           IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
    438           GetFirstDisplayName(), UTF8ToUTF16("400x400")),
    439       GetDisplayNotificationText());
    440   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    441 
    442   // No-update
    443   CloseNotification();
    444   UpdateDisplay("400x400");
    445   EXPECT_TRUE(GetDisplayNotificationText().empty());
    446   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    447 
    448   // Extended.
    449   CloseNotification();
    450   UpdateDisplay("400x400,200x200");
    451   EXPECT_EQ(
    452       l10n_util::GetStringFUTF16(
    453           IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()),
    454       GetDisplayNotificationText());
    455   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    456 
    457   // Mirroring.
    458   CloseNotification();
    459   display_manager->SetSoftwareMirroring(true);
    460   UpdateDisplay("400x400,200x200");
    461   EXPECT_EQ(
    462       l10n_util::GetStringFUTF16(
    463           IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()),
    464       GetDisplayNotificationText());
    465   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    466 
    467   // Back to extended.
    468   CloseNotification();
    469   display_manager->SetSoftwareMirroring(false);
    470   UpdateDisplay("400x400,200x200");
    471   EXPECT_EQ(
    472       l10n_util::GetStringFUTF16(
    473           IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()),
    474       GetDisplayNotificationText());
    475   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    476 
    477   // Resize the first display.
    478   UpdateDisplay("400x400 (at) 1.5,200x200");
    479   EXPECT_EQ(
    480       l10n_util::GetStringFUTF16(
    481           IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
    482           GetFirstDisplayName(), UTF8ToUTF16("600x600")),
    483       GetDisplayNotificationText());
    484   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    485 
    486   // Rotate the second.
    487   UpdateDisplay("400x400 (at) 1.5,200x200/r");
    488   EXPECT_EQ(
    489       l10n_util::GetStringFUTF16(
    490           IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED,
    491           GetSecondDisplayName(),
    492           l10n_util::GetStringUTF16(
    493               IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
    494       GetDisplayNotificationText());
    495   EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
    496 
    497   // Enters closed lid mode.
    498   UpdateDisplay("400x400 (at) 1.5,200x200");
    499   gfx::Display::SetInternalDisplayId(ScreenAsh::GetSecondaryDisplay().id());
    500   UpdateDisplay("400x400 (at) 1.5");
    501   EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
    502             GetDisplayNotificationText());
    503   EXPECT_EQ(
    504       l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
    505       GetDisplayNotificationAdditionalText());
    506 }
    507 
    508 TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) {
    509   test::TestSystemTrayDelegate* tray_delegate =
    510       static_cast<test::TestSystemTrayDelegate*>(
    511           Shell::GetInstance()->system_tray_delegate());
    512   tray_delegate->set_should_show_display_notification(true);
    513 
    514   UpdateDisplay("400x400,200x200");
    515   EXPECT_EQ(
    516       l10n_util::GetStringUTF16(
    517           IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
    518       GetDisplayNotificationText());
    519 
    520   // OnDisplayConfigurationChanged() may be called more than once for a single
    521   // update display in case of primary is swapped or recovered from dock mode.
    522   // Should not remove the notification in such case.
    523   tray_display()->OnDisplayConfigurationChanged();
    524   EXPECT_EQ(
    525       l10n_util::GetStringUTF16(
    526           IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
    527       GetDisplayNotificationText());
    528 
    529   // Back to the single display. It SHOULD remove the notification since the
    530   // information is stale.
    531   UpdateDisplay("400x400");
    532   EXPECT_TRUE(GetDisplayNotificationText().empty());
    533 }
    534 
    535 TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) {
    536   UpdateDisplay("400x400,200x200");
    537 
    538   test::TestSystemTrayDelegate* tray_delegate =
    539       static_cast<test::TestSystemTrayDelegate*>(
    540           Shell::GetInstance()->system_tray_delegate());
    541   tray_delegate->set_should_show_display_notification(true);
    542 
    543   // rotate the second.
    544   UpdateDisplay("400x400,200x200/r");
    545   EXPECT_EQ(
    546       l10n_util::GetStringFUTF16(
    547           IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED,
    548           GetSecondDisplayName(),
    549           l10n_util::GetStringUTF16(
    550               IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
    551       GetDisplayNotificationText());
    552 }
    553 
    554 }  // namespace internal
    555 }  // namespace ash
    556