Chromium Code Reviews| 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/system/chromeos/tray_display.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/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/display_manager_test_api.h" | 13 #include "ash/test/display_manager_test_api.h" |
| 14 #include "ash/test/test_system_tray_delegate.h" | 14 #include "ash/test/test_system_tray_delegate.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 19 #include "ui/accessibility/ax_view_state.h" | 19 #include "ui/accessibility/ax_view_state.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 22 #include "ui/message_center/message_center.h" | 22 #include "ui/message_center/message_center.h" |
| 23 #include "ui/message_center/notification.h" | 23 #include "ui/message_center/notification.h" |
| 24 #include "ui/message_center/notification_list.h" | 24 #include "ui/message_center/notification_list.h" |
| 25 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
| 26 | 26 |
| 27 namespace ash { | 27 namespace ash { |
| 28 | 28 |
| 29 base::string16 GetTooltipText(const base::string16& headline, | |
| 30 const base::string16& name1, | |
| 31 const std::string& data1, | |
| 32 const base::string16& name2, | |
| 33 const std::string& data2) { | |
| 34 std::vector<base::string16> lines; | |
| 35 lines.push_back(headline); | |
| 36 if (data1.empty()) { | |
| 37 lines.push_back(name1); | |
| 38 } else { | |
| 39 lines.push_back( | |
| 40 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | |
| 41 name1, base::UTF8ToUTF16(data1))); | |
| 42 } | |
| 43 if (!name2.empty()) { | |
| 44 lines.push_back( | |
| 45 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | |
| 46 name2, base::UTF8ToUTF16(data2))); | |
| 47 } | |
| 48 return base::JoinString(lines, base::ASCIIToUTF16("\n")); | |
| 49 } | |
| 50 | |
| 51 base::string16 GetMirroredTooltipText(const base::string16& headline, | |
| 52 const base::string16& name, | |
| 53 const std::string& data) { | |
| 54 return GetTooltipText(headline, name, data, base::string16(), ""); | |
| 55 } | |
| 56 | |
| 57 base::string16 GetFirstDisplayName() { | 29 base::string16 GetFirstDisplayName() { |
| 58 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 30 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 59 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | 31 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( |
| 60 display_manager->first_display_id())); | 32 display_manager->first_display_id())); |
| 61 } | 33 } |
| 62 | 34 |
| 63 base::string16 GetSecondDisplayName() { | 35 base::string16 GetSecondDisplayName() { |
| 64 return base::UTF8ToUTF16( | 36 return base::UTF8ToUTF16( |
| 65 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 37 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
| 66 ScreenUtil::GetSecondaryDisplay().id())); | 38 ScreenUtil::GetSecondaryDisplay().id())); |
| 67 } | 39 } |
| 68 | 40 |
| 69 base::string16 GetMirroringDisplayName() { | 41 base::string16 GetMirroringDisplayName() { |
| 70 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 42 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 71 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | 43 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( |
| 72 display_manager->mirroring_display_id())); | 44 display_manager->mirroring_display_id())); |
| 73 } | 45 } |
| 74 | 46 |
| 75 class TrayDisplayTest : public ash::test::AshTestBase { | 47 class ScreenLayoutObserverTest : public ash::test::AshTestBase { |
|
James Cook
2016/08/05 17:00:25
nit: ash:: not needed
yiyix
2016/08/13 05:28:51
Done.
| |
| 76 public: | 48 public: |
| 77 TrayDisplayTest(); | 49 ScreenLayoutObserverTest(); |
| 78 ~TrayDisplayTest() override; | 50 ~ScreenLayoutObserverTest() override; |
| 79 | 51 |
| 80 void SetUp() override; | 52 void SetUp() override; |
| 81 | 53 |
| 82 protected: | 54 protected: |
| 83 SystemTray* GetTray(); | 55 ScreenLayoutObserver* UpdateTrayDisplay(); |
| 84 TrayDisplay* GetTrayDisplay(); | |
| 85 void CheckUpdate(); | 56 void CheckUpdate(); |
| 86 | 57 |
| 87 void CloseNotification(); | 58 void CloseNotification(); |
| 88 bool IsDisplayVisibleInTray() const; | |
| 89 base::string16 GetTrayDisplayText() const; | |
| 90 void CheckAccessibleName() const; | |
| 91 base::string16 GetTrayDisplayTooltipText() const; | |
| 92 base::string16 GetDisplayNotificationText() const; | 59 base::string16 GetDisplayNotificationText() const; |
| 93 base::string16 GetDisplayNotificationAdditionalText() const; | 60 base::string16 GetDisplayNotificationAdditionalText() const; |
| 94 | 61 |
| 95 private: | 62 private: |
| 96 const message_center::Notification* GetDisplayNotification() const; | 63 const message_center::Notification* GetDisplayNotification() const; |
| 97 | 64 |
| 98 // Weak reference, owned by Shell. | 65 // Weak reference, owned by Shell. |
|
James Cook
2016/08/05 17:00:25
Is this still true?
yiyix
2016/08/13 05:28:51
it used to owned by |tray_|, it is now owned by sh
| |
| 99 SystemTray* tray_; | 66 ScreenLayoutObserver* screen_layout_observer_; |
|
James Cook
2016/08/05 17:00:25
This does not appear to be read. Perhaps you meant
yiyix
2016/08/13 05:28:51
I removed this method, the ScreenLayoutObserver is
| |
| 100 | 67 |
| 101 // Weak reference, owned by |tray_|. | 68 DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTest); |
| 102 TrayDisplay* tray_display_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest); | |
| 105 }; | 69 }; |
| 106 | 70 |
| 107 TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) {} | 71 ScreenLayoutObserverTest::ScreenLayoutObserverTest() |
| 72 : screen_layout_observer_() {} | |
|
James Cook
2016/08/05 17:00:25
not needed
yiyix
2016/08/13 05:28:51
Done.
| |
| 108 | 73 |
| 109 TrayDisplayTest::~TrayDisplayTest() {} | 74 ScreenLayoutObserverTest::~ScreenLayoutObserverTest() {} |
| 110 | 75 |
| 111 void TrayDisplayTest::SetUp() { | 76 void ScreenLayoutObserverTest::SetUp() { |
|
James Cook
2016/08/05 17:00:25
Eliminate this method, because it does nothing.
yiyix
2016/08/13 05:28:51
Done.
| |
| 112 ash::test::AshTestBase::SetUp(); | 77 ash::test::AshTestBase::SetUp(); |
| 113 // Populate tray_ and tray_display_. | |
| 114 CheckUpdate(); | |
| 115 } | 78 } |
| 116 | 79 |
| 117 SystemTray* TrayDisplayTest::GetTray() { | 80 ScreenLayoutObserver* ScreenLayoutObserverTest::UpdateTrayDisplay() { |
|
James Cook
2016/08/05 17:00:25
This method name is odd -- I thought TrayDisplay w
yiyix
2016/08/13 05:28:51
I forget to update the name. Sorry.
| |
| 118 CheckUpdate(); | 81 screen_layout_observer_ = new ScreenLayoutObserver(); |
|
James Cook
2016/08/05 17:00:25
I think this leaks memory. ScreenLayoutObserver do
yiyix
2016/08/13 05:28:51
It is updated.
| |
| 119 return tray_; | 82 return screen_layout_observer_; |
| 120 } | 83 } |
| 121 | 84 |
| 122 TrayDisplay* TrayDisplayTest::GetTrayDisplay() { | 85 void ScreenLayoutObserverTest::CloseNotification() { |
| 123 CheckUpdate(); | |
| 124 return tray_display_; | |
| 125 } | |
| 126 | |
| 127 void TrayDisplayTest::CheckUpdate() { | |
| 128 SystemTray* current = GetPrimarySystemTray(); | |
| 129 if (tray_ != current) { | |
| 130 tray_ = current; | |
| 131 tray_display_ = new TrayDisplay(tray_); | |
| 132 tray_->AddTrayItem(tray_display_); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void TrayDisplayTest::CloseNotification() { | |
| 137 message_center::MessageCenter::Get()->RemoveNotification( | 86 message_center::MessageCenter::Get()->RemoveNotification( |
| 138 TrayDisplay::kNotificationId, false); | 87 ScreenLayoutObserver::kNotificationId, false); |
| 139 RunAllPendingInMessageLoop(); | 88 RunAllPendingInMessageLoop(); |
| 140 } | 89 } |
| 141 | 90 |
| 142 bool TrayDisplayTest::IsDisplayVisibleInTray() const { | 91 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationText() const { |
| 143 return tray_->HasSystemBubble() && tray_display_->default_view() && | |
| 144 tray_display_->default_view()->visible(); | |
| 145 } | |
| 146 | |
| 147 base::string16 TrayDisplayTest::GetTrayDisplayText() const { | |
| 148 return tray_display_->GetDefaultViewMessage(); | |
| 149 } | |
| 150 | |
| 151 void TrayDisplayTest::CheckAccessibleName() const { | |
| 152 ui::AXViewState state; | |
| 153 if (tray_display_->GetAccessibleStateForTesting(&state)) { | |
| 154 base::string16 expected = tray_display_->GetDefaultViewMessage(); | |
| 155 EXPECT_EQ(expected, state.name); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() const { | |
| 160 if (!tray_display_->default_view()) | |
| 161 return base::string16(); | |
| 162 | |
| 163 base::string16 tooltip; | |
| 164 if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip)) | |
| 165 return base::string16(); | |
| 166 return tooltip; | |
| 167 } | |
| 168 | |
| 169 base::string16 TrayDisplayTest::GetDisplayNotificationText() const { | |
| 170 const message_center::Notification* notification = GetDisplayNotification(); | 92 const message_center::Notification* notification = GetDisplayNotification(); |
| 171 return notification ? notification->title() : base::string16(); | 93 return notification ? notification->title() : base::string16(); |
| 172 } | 94 } |
| 173 | 95 |
| 174 base::string16 TrayDisplayTest::GetDisplayNotificationAdditionalText() const { | 96 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationAdditionalText() |
| 97 const { | |
| 175 const message_center::Notification* notification = GetDisplayNotification(); | 98 const message_center::Notification* notification = GetDisplayNotification(); |
| 176 return notification ? notification->message() : base::string16(); | 99 return notification ? notification->message() : base::string16(); |
| 177 } | 100 } |
| 178 | 101 |
| 179 const message_center::Notification* TrayDisplayTest::GetDisplayNotification() | 102 const message_center::Notification* |
| 180 const { | 103 ScreenLayoutObserverTest::GetDisplayNotification() const { |
| 181 const message_center::NotificationList::Notifications notifications = | 104 const message_center::NotificationList::Notifications notifications = |
| 182 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 105 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 183 for (message_center::NotificationList::Notifications::const_iterator iter = | 106 for (message_center::NotificationList::Notifications::const_iterator iter = |
| 184 notifications.begin(); | 107 notifications.begin(); |
| 185 iter != notifications.end(); ++iter) { | 108 iter != notifications.end(); ++iter) { |
| 186 if ((*iter)->id() == TrayDisplay::kNotificationId) | 109 if ((*iter)->id() == ScreenLayoutObserver::kNotificationId) |
| 187 return *iter; | 110 return *iter; |
| 188 } | 111 } |
| 189 | 112 |
| 190 return NULL; | 113 return NULL; |
| 191 } | 114 } |
| 192 | 115 |
| 193 TEST_F(TrayDisplayTest, NoInternalDisplay) { | 116 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) { |
| 194 UpdateDisplay("400x400"); | |
| 195 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 196 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 197 | |
| 198 UpdateDisplay("400x400,200x200"); | |
| 199 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 200 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 201 base::string16 expected = l10n_util::GetStringUTF16( | |
| 202 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | |
| 203 base::string16 first_name = GetFirstDisplayName(); | |
| 204 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 205 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
| 206 GetSecondDisplayName(), "200x200"), | |
| 207 GetTrayDisplayTooltipText()); | |
| 208 CheckAccessibleName(); | |
| 209 | |
| 210 // mirroring | |
| 211 Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true); | |
| 212 UpdateDisplay("400x400,200x200"); | |
| 213 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 214 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 215 expected = l10n_util::GetStringUTF16( | |
| 216 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); | |
| 217 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 218 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
| 219 GetTrayDisplayTooltipText()); | |
| 220 CheckAccessibleName(); | |
| 221 } | |
| 222 | |
| 223 TEST_F(TrayDisplayTest, InternalDisplay) { | |
| 224 UpdateDisplay("400x400"); | |
| 225 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 226 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 227 | |
| 228 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 229 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 230 | |
| 231 // Extended | |
| 232 UpdateDisplay("400x400,200x200"); | |
| 233 base::string16 expected = l10n_util::GetStringFUTF16( | |
| 234 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); | |
| 235 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 236 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 237 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 238 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
| 239 GetSecondDisplayName(), "200x200"), | |
| 240 GetTrayDisplayTooltipText()); | |
| 241 CheckAccessibleName(); | |
| 242 | |
| 243 // Mirroring | |
| 244 display_manager->SetSoftwareMirroring(true); | |
| 245 UpdateDisplay("400x400,200x200"); | |
| 246 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 247 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 248 | |
| 249 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
| 250 GetMirroringDisplayName()); | |
| 251 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 252 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
| 253 GetTrayDisplayTooltipText()); | |
| 254 CheckAccessibleName(); | |
| 255 } | |
| 256 | |
| 257 TEST_F(TrayDisplayTest, InternalDisplayResized) { | |
| 258 UpdateDisplay("400x400@1.5"); | |
| 259 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 260 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 261 | |
| 262 // Shows the tray_display even though there's a single-display. | |
| 263 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 264 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 265 base::string16 internal_info = l10n_util::GetStringFUTF16( | |
| 266 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, GetFirstDisplayName(), | |
| 267 base::UTF8ToUTF16("600x600")); | |
| 268 EXPECT_EQ(internal_info, GetTrayDisplayText()); | |
| 269 EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", | |
| 270 base::string16(), std::string()), | |
| 271 GetTrayDisplayTooltipText()); | |
| 272 CheckAccessibleName(); | |
| 273 | |
| 274 // Extended | |
| 275 UpdateDisplay("400x400@1.5,200x200"); | |
| 276 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 277 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 278 base::string16 expected = l10n_util::GetStringFUTF16( | |
| 279 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); | |
| 280 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 281 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600", | |
| 282 GetSecondDisplayName(), "200x200"), | |
| 283 GetTrayDisplayTooltipText()); | |
| 284 CheckAccessibleName(); | |
| 285 | |
| 286 // Mirroring | |
| 287 display_manager->SetSoftwareMirroring(true); | |
| 288 UpdateDisplay("400x400@1.5,200x200"); | |
| 289 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 290 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 291 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
| 292 GetMirroringDisplayName()); | |
| 293 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 294 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "600x600"), | |
| 295 GetTrayDisplayTooltipText()); | |
| 296 CheckAccessibleName(); | |
| 297 | |
| 298 // Closed lid mode. | |
| 299 display_manager->SetSoftwareMirroring(false); | |
| 300 UpdateDisplay("400x400@1.5,200x200"); | |
| 301 display::Display::SetInternalDisplayId( | |
| 302 ScreenUtil::GetSecondaryDisplay().id()); | |
| 303 UpdateDisplay("400x400@1.5"); | |
| 304 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 305 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 306 expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); | |
| 307 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 308 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600", | |
| 309 base::string16(), ""), | |
| 310 GetTrayDisplayTooltipText()); | |
| 311 CheckAccessibleName(); | |
| 312 | |
| 313 // Unified mode | |
| 314 display_manager->SetUnifiedDesktopEnabled(true); | |
| 315 UpdateDisplay("300x200,400x500"); | |
| 316 // Update the cache variables as the primary root window changed. | |
| 317 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 318 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 319 expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED); | |
| 320 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 321 } | |
| 322 | |
| 323 TEST_F(TrayDisplayTest, ExternalDisplayResized) { | |
| 324 UpdateDisplay("400x400"); | |
| 325 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 326 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 327 | |
| 328 // Shows the tray_display even though there's a single-display. | |
| 329 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 330 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 331 | |
| 332 // Extended | |
| 333 UpdateDisplay("400x400,200x200@1.5"); | |
| 334 const display::Display& secondary_display = ScreenUtil::GetSecondaryDisplay(); | |
| 335 | |
| 336 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 337 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 338 base::string16 expected = l10n_util::GetStringFUTF16( | |
| 339 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
| 340 l10n_util::GetStringFUTF16( | |
| 341 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, GetSecondDisplayName(), | |
| 342 base::UTF8ToUTF16(secondary_display.size().ToString()))); | |
| 343 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 344 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
| 345 GetSecondDisplayName(), "300x300"), | |
| 346 GetTrayDisplayTooltipText()); | |
| 347 CheckAccessibleName(); | |
| 348 | |
| 349 // Mirroring | |
| 350 display_manager->SetSoftwareMirroring(true); | |
| 351 UpdateDisplay("400x400,200x200@1.5"); | |
| 352 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 353 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 354 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
| 355 GetMirroringDisplayName()); | |
| 356 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 357 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
| 358 GetTrayDisplayTooltipText()); | |
| 359 CheckAccessibleName(); | |
| 360 } | |
| 361 | |
| 362 TEST_F(TrayDisplayTest, OverscanDisplay) { | |
| 363 UpdateDisplay("400x400,300x300/o"); | |
| 364 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 365 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 366 | |
| 367 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 368 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 369 | |
| 370 // /o creates the default overscan, and if overscan is set, the annotation | |
| 371 // should be the size. | |
| 372 base::string16 overscan = l10n_util::GetStringUTF16( | |
| 373 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN); | |
| 374 base::string16 headline = l10n_util::GetStringFUTF16( | |
| 375 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
| 376 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | |
| 377 GetSecondDisplayName(), | |
| 378 base::UTF8ToUTF16("286x286"))); | |
| 379 std::string second_data = | |
| 380 l10n_util::GetStringFUTF8(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, | |
| 381 base::UTF8ToUTF16("286x286"), overscan); | |
| 382 EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", | |
| 383 GetSecondDisplayName(), second_data), | |
| 384 GetTrayDisplayTooltipText()); | |
| 385 | |
| 386 // reset the overscan. | |
| 387 display_manager->SetOverscanInsets(ScreenUtil::GetSecondaryDisplay().id(), | |
| 388 gfx::Insets()); | |
| 389 headline = l10n_util::GetStringFUTF16( | |
| 390 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
| 391 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | |
| 392 GetSecondDisplayName(), overscan)); | |
| 393 second_data = | |
| 394 l10n_util::GetStringFUTF8(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, | |
| 395 base::UTF8ToUTF16("300x300"), overscan); | |
| 396 EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", | |
| 397 GetSecondDisplayName(), second_data), | |
| 398 GetTrayDisplayTooltipText()); | |
| 399 } | |
| 400 | |
| 401 TEST_F(TrayDisplayTest, UpdateDuringDisplayConfigurationChange) { | |
| 402 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 403 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 404 | |
| 405 UpdateDisplay("400x400@1.5"); | |
| 406 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
| 407 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 408 base::string16 internal_info = l10n_util::GetStringFUTF16( | |
| 409 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, GetFirstDisplayName(), | |
| 410 base::UTF8ToUTF16("600x600")); | |
| 411 EXPECT_EQ(internal_info, GetTrayDisplayText()); | |
| 412 EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", | |
| 413 base::string16(), std::string()), | |
| 414 GetTrayDisplayTooltipText()); | |
| 415 CheckAccessibleName(); | |
| 416 | |
| 417 UpdateDisplay("400x400,200x200"); | |
| 418 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
| 419 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 420 base::string16 expected = l10n_util::GetStringUTF16( | |
| 421 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | |
| 422 base::string16 first_name = GetFirstDisplayName(); | |
| 423 EXPECT_EQ(expected, GetTrayDisplayText()); | |
| 424 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
| 425 GetSecondDisplayName(), "200x200"), | |
| 426 GetTrayDisplayTooltipText()); | |
| 427 CheckAccessibleName(); | |
| 428 | |
| 429 UpdateDisplay("400x400@1.5"); | |
| 430 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 431 | |
| 432 // Back to the default state, the display tray item should disappear. | |
| 433 UpdateDisplay("400x400"); | |
| 434 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
| 435 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 436 } | |
|
James Cook
2016/08/05 17:00:25
I'm concerned that you're removing so much test co
yiyix
2016/08/13 05:28:51
I believe most of them are covered. Tests are miss
| |
| 437 | |
| 438 TEST_F(TrayDisplayTest, DisplayNotifications) { | |
| 439 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | 117 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); |
| 440 tray_delegate->set_should_show_display_notification(true); | 118 tray_delegate->set_should_show_display_notification(true); |
| 441 | 119 |
| 442 UpdateDisplay("400x400"); | 120 UpdateDisplay("400x400"); |
| 443 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 121 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 444 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | 122 display::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 445 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 123 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 446 | 124 |
| 447 // rotation. | 125 // rotation. |
| 448 UpdateDisplay("400x400/r"); | 126 UpdateDisplay("400x400/r"); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 display::Display::SetInternalDisplayId( | 212 display::Display::SetInternalDisplayId( |
| 535 ScreenUtil::GetSecondaryDisplay().id()); | 213 ScreenUtil::GetSecondaryDisplay().id()); |
| 536 UpdateDisplay("400x400@1.5"); | 214 UpdateDisplay("400x400@1.5"); |
| 537 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), | 215 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), |
| 538 GetDisplayNotificationText()); | 216 GetDisplayNotificationText()); |
| 539 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( | 217 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( |
| 540 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), | 218 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), |
| 541 GetDisplayNotificationAdditionalText()); | 219 GetDisplayNotificationAdditionalText()); |
| 542 } | 220 } |
| 543 | 221 |
| 544 TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) { | 222 // Test if notification shows when display is switched to extend mode. |
|
James Cook
2016/08/05 17:00:25
Thanks for documenting what the test does!
| |
| 223 TEST_F(ScreenLayoutObserverTest, DisplayConfigurationChangedTwice) { | |
| 545 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | 224 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); |
| 546 tray_delegate->set_should_show_display_notification(true); | 225 tray_delegate->set_should_show_display_notification(true); |
| 547 | |
| 548 UpdateDisplay("400x400,200x200"); | 226 UpdateDisplay("400x400,200x200"); |
| 549 EXPECT_EQ(l10n_util::GetStringUTF16( | 227 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 550 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), | 228 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), |
| 551 GetDisplayNotificationText()); | 229 GetDisplayNotificationText()); |
| 552 | 230 |
| 553 // OnDisplayConfigurationChanged() may be called more than once for a single | 231 // OnDisplayConfigurationChanged() may be called more than once for a single |
| 554 // update display in case of primary is swapped or recovered from dock mode. | 232 // update display in case of primary is swapped or recovered from dock mode. |
| 555 // Should not remove the notification in such case. | 233 // Should not remove the notification in such case. |
| 556 GetTrayDisplay()->OnDisplayConfigurationChanged(); | 234 UpdateTrayDisplay()->OnDisplayConfigurationChanged(); |
|
James Cook
2016/08/05 17:00:25
This reads strangely to me. I think creating the o
yiyix
2016/08/13 05:28:51
It is updated.
| |
| 557 EXPECT_EQ(l10n_util::GetStringUTF16( | 235 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 558 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), | 236 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), |
| 559 GetDisplayNotificationText()); | 237 GetDisplayNotificationText()); |
| 560 | 238 |
| 561 // Back to the single display. It SHOULD remove the notification since the | 239 // Back to the single display. It SHOULD remove the notification since the |
| 562 // information is stale. | 240 // information is stale. |
| 563 UpdateDisplay("400x400"); | 241 UpdateDisplay("400x400"); |
| 564 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 242 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 565 } | 243 } |
| 566 | 244 |
| 567 TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) { | 245 TEST_F(ScreenLayoutObserverTest, UpdateAfterSuppressDisplayNotification) { |
| 568 UpdateDisplay("400x400,200x200"); | 246 UpdateDisplay("400x400,200x200"); |
| 569 | 247 |
| 570 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | 248 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); |
| 571 tray_delegate->set_should_show_display_notification(true); | 249 tray_delegate->set_should_show_display_notification(true); |
| 572 | 250 |
| 573 // rotate the second. | 251 // rotate the second. |
| 574 UpdateDisplay("400x400,200x200/r"); | 252 UpdateDisplay("400x400,200x200/r"); |
| 575 EXPECT_EQ(l10n_util::GetStringFUTF16( | 253 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 576 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), | 254 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), |
| 577 l10n_util::GetStringUTF16( | 255 l10n_util::GetStringUTF16( |
| 578 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | 256 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), |
| 579 GetDisplayNotificationAdditionalText()); | 257 GetDisplayNotificationAdditionalText()); |
| 580 } | 258 } |
| 581 | 259 |
| 582 // Tests that when the only change is rotation, that it is only displayed when | |
| 583 // caused by user changes, and not by accelerometers. | |
| 584 TEST_F(TrayDisplayTest, RotationOnInternalDisplay) { | |
|
James Cook
2016/08/05 17:00:25
I still see code in CreateOrUpdateNotification() t
yiyix
2016/08/13 05:28:51
Notification center uses ignore_display_configurat
| |
| 585 UpdateDisplay("400x400"); | |
| 586 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 587 const int64_t display_id = display_manager->first_display_id(); | |
| 588 display::Display::SetInternalDisplayId(display_id); | |
| 589 | |
| 590 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 591 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 592 | |
| 593 // Accelerometer change does not display. | |
| 594 display_manager->SetDisplayRotation( | |
| 595 display_id, display::Display::ROTATE_90, | |
| 596 display::Display::ROTATION_SOURCE_ACCELEROMETER); | |
| 597 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 598 | |
| 599 // User change does. | |
| 600 display_manager->SetDisplayRotation(display_id, display::Display::ROTATE_180, | |
| 601 display::Display::ROTATION_SOURCE_USER); | |
| 602 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 603 | |
| 604 // If a user setting matches the accelerometer, do not display if caused by | |
| 605 // the accelerometer. | |
| 606 display_manager->SetDisplayRotation( | |
| 607 display_id, display::Display::ROTATE_180, | |
| 608 display::Display::ROTATION_SOURCE_ACCELEROMETER); | |
| 609 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
| 610 | |
| 611 // If a non-rotation setting is changed, display regardless of the source of | |
| 612 // rotation so that the full message is shown. | |
| 613 UpdateDisplay("400x400@1.5"); | |
| 614 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
| 615 } | |
| 616 | |
| 617 } // namespace ash | 260 } // namespace ash |
| OLD | NEW |