| 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/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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 the |
| 332 // correct message. |
| 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 that we exited mirror mode. |
| 350 CloseNotification(); |
| 351 display_manager()->SetSoftwareMirroring(false); |
| 352 UpdateDisplay("400x400"); |
| 353 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT), |
| 354 GetDisplayNotificationText()); |
| 355 } |
| 356 |
| 357 // Tests notification messages shown when adding and removing displays in |
| 358 // extended mode. |
| 359 TEST_F(ScreenLayoutObserverTest, AddingRemovingDisplayExtendedModeMessage) { |
| 360 Shell::GetInstance() |
| 361 ->screen_layout_observer() |
| 362 ->set_show_notifications_for_testing(true); |
| 363 UpdateDisplay("400x400"); |
| 364 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 365 |
| 366 // Adding a display in extended mode. |
| 367 UpdateDisplay("400x400,200x200"); |
| 368 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 369 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), |
| 370 GetDisplayNotificationText()); |
| 371 |
| 372 // Removing a display. |
| 373 CloseNotification(); |
| 374 UpdateDisplay("400x400"); |
| 375 EXPECT_TRUE(base::StartsWith( |
| 376 GetDisplayNotificationText(), |
| 377 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED, |
| 378 base::UTF8ToUTF16("")), |
| 379 base::CompareCase::SENSITIVE)); |
| 380 } |
| 381 |
| 382 // Tests notification messages shown when entering and exiting unified desktop |
| 383 // mode. |
| 384 TEST_F(ScreenLayoutObserverTest, EnteringExitingUnifiedModeMessage) { |
| 385 Shell::GetInstance() |
| 386 ->screen_layout_observer() |
| 387 ->set_show_notifications_for_testing(true); |
| 388 UpdateDisplay("400x400"); |
| 389 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 390 |
| 391 // Adding a display in extended mode. |
| 392 UpdateDisplay("400x400,200x200"); |
| 393 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 394 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), |
| 395 GetDisplayNotificationText()); |
| 396 |
| 397 // Enter unified mode. |
| 398 display_manager()->SetUnifiedDesktopEnabled(true); |
| 399 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED), |
| 400 GetDisplayNotificationText()); |
| 401 |
| 402 // Exit unified mode. |
| 403 display_manager()->SetUnifiedDesktopEnabled(false); |
| 404 EXPECT_EQ( |
| 405 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING), |
| 406 GetDisplayNotificationText()); |
| 407 |
| 408 // Enter unified mode again and exit via closing the lid. The message "Exiting |
| 409 // unified mode" should be shown. |
| 410 display_manager()->SetUnifiedDesktopEnabled(true); |
| 411 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED), |
| 412 GetDisplayNotificationText()); |
| 413 |
| 414 // Close the lid. |
| 415 display::Display::SetInternalDisplayId(display_manager()->first_display_id()); |
| 416 UpdateDisplay("200x200"); |
| 417 display_manager()->SetUnifiedDesktopEnabled(false); |
| 418 EXPECT_EQ( |
| 419 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING), |
| 420 GetDisplayNotificationText()); |
| 421 } |
| 422 |
| 423 // Special case: Tests notification messages shown when entering docked mode |
| 424 // by closing the lid and the internal display is the secondary display. |
| 425 TEST_F(ScreenLayoutObserverTest, DockedModeWithExternalPrimaryDisplayMessage) { |
| 426 Shell::GetInstance() |
| 427 ->screen_layout_observer() |
| 428 ->set_show_notifications_for_testing(true); |
| 429 UpdateDisplay("400x400,200x200"); |
| 430 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 431 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), |
| 432 GetDisplayNotificationText()); |
| 433 CloseNotification(); |
| 434 |
| 435 const int64_t primary_id = display_manager()->GetDisplayAt(0).id(); |
| 436 const int64_t internal_secondary_id = display_manager()->GetDisplayAt(1).id(); |
| 437 display::Display::SetInternalDisplayId(internal_secondary_id); |
| 438 display::DisplayLayoutBuilder builder(primary_id); |
| 439 builder.AddDisplayPlacement(internal_secondary_id, primary_id, |
| 440 display::DisplayPlacement::LEFT, 0); |
| 441 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
| 442 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 443 |
| 444 // Close the lid and expect we show the docked mode message. |
| 445 UpdateDisplay("400x400"); |
| 446 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), |
| 447 GetDisplayNotificationText()); |
| 448 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( |
| 449 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), |
| 450 GetDisplayNotificationAdditionalText()); |
| 451 } |
| 452 |
| 275 } // namespace ash | 453 } // namespace ash |
| OLD | NEW |