| 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/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/screen_util.h" | |
| 11 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/display_manager_test_api.h" | 12 #include "ash/test/display_manager_test_api.h" |
| 14 #include "ash/test/test_system_tray_delegate.h" | 13 #include "ash/test/test_system_tray_delegate.h" |
| 15 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 18 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 19 #include "ui/accessibility/ax_view_state.h" | 18 #include "ui/accessibility/ax_view_state.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
| 22 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
| 23 #include "ui/message_center/notification.h" | 22 #include "ui/message_center/notification.h" |
| 24 #include "ui/message_center/notification_list.h" | 23 #include "ui/message_center/notification_list.h" |
| 25 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 26 | 25 |
| 27 namespace ash { | 26 namespace ash { |
| 28 | 27 |
| 29 base::string16 GetFirstDisplayName() { | |
| 30 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 31 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | |
| 32 display_manager->first_display_id())); | |
| 33 } | |
| 34 | |
| 35 base::string16 GetSecondDisplayName() { | |
| 36 return base::UTF8ToUTF16( | |
| 37 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | |
| 38 ScreenUtil::GetSecondaryDisplay().id())); | |
| 39 } | |
| 40 | |
| 41 base::string16 GetMirroringDisplayName() { | |
| 42 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 43 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | |
| 44 display_manager->mirroring_display_id())); | |
| 45 } | |
| 46 | |
| 47 class ScreenLayoutObserverTest : public test::AshTestBase { | 28 class ScreenLayoutObserverTest : public test::AshTestBase { |
| 48 public: | 29 public: |
| 49 ScreenLayoutObserverTest(); | 30 ScreenLayoutObserverTest(); |
| 50 ~ScreenLayoutObserverTest() override; | 31 ~ScreenLayoutObserverTest() override; |
| 51 | 32 |
| 52 protected: | 33 protected: |
| 53 ScreenLayoutObserver* GetScreenLayoutObserver(); | 34 ScreenLayoutObserver* GetScreenLayoutObserver(); |
| 54 void CheckUpdate(); | 35 void CheckUpdate(); |
| 55 | 36 |
| 56 void CloseNotification(); | 37 void CloseNotification(); |
| 57 base::string16 GetDisplayNotificationText() const; | 38 base::string16 GetDisplayNotificationText() const; |
| 58 base::string16 GetDisplayNotificationAdditionalText() const; | 39 base::string16 GetDisplayNotificationAdditionalText() const; |
| 59 | 40 |
| 41 base::string16 GetFirstDisplayName(); |
| 42 |
| 43 base::string16 GetSecondDisplayName(); |
| 44 |
| 45 base::string16 GetMirroringDisplayName(); |
| 46 |
| 60 private: | 47 private: |
| 61 const message_center::Notification* GetDisplayNotification() const; | 48 const message_center::Notification* GetDisplayNotification() const; |
| 62 | 49 |
| 63 DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTest); | 50 DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTest); |
| 64 }; | 51 }; |
| 65 | 52 |
| 66 ScreenLayoutObserverTest::ScreenLayoutObserverTest() {} | 53 ScreenLayoutObserverTest::ScreenLayoutObserverTest() {} |
| 67 | 54 |
| 68 ScreenLayoutObserverTest::~ScreenLayoutObserverTest() {} | 55 ScreenLayoutObserverTest::~ScreenLayoutObserverTest() {} |
| 69 | 56 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 const message_center::Notification* notification = GetDisplayNotification(); | 68 const message_center::Notification* notification = GetDisplayNotification(); |
| 82 return notification ? notification->title() : base::string16(); | 69 return notification ? notification->title() : base::string16(); |
| 83 } | 70 } |
| 84 | 71 |
| 85 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationAdditionalText() | 72 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationAdditionalText() |
| 86 const { | 73 const { |
| 87 const message_center::Notification* notification = GetDisplayNotification(); | 74 const message_center::Notification* notification = GetDisplayNotification(); |
| 88 return notification ? notification->message() : base::string16(); | 75 return notification ? notification->message() : base::string16(); |
| 89 } | 76 } |
| 90 | 77 |
| 78 base::string16 ScreenLayoutObserverTest::GetFirstDisplayName() { |
| 79 return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId( |
| 80 display_manager()->first_display_id())); |
| 81 } |
| 82 |
| 83 base::string16 ScreenLayoutObserverTest::GetSecondDisplayName() { |
| 84 return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId( |
| 85 display_manager()->GetSecondaryDisplay().id())); |
| 86 } |
| 87 |
| 88 base::string16 ScreenLayoutObserverTest::GetMirroringDisplayName() { |
| 89 return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId( |
| 90 display_manager()->mirroring_display_id())); |
| 91 } |
| 92 |
| 91 const message_center::Notification* | 93 const message_center::Notification* |
| 92 ScreenLayoutObserverTest::GetDisplayNotification() const { | 94 ScreenLayoutObserverTest::GetDisplayNotification() const { |
| 93 const message_center::NotificationList::Notifications notifications = | 95 const message_center::NotificationList::Notifications notifications = |
| 94 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 96 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 95 for (message_center::NotificationList::Notifications::const_iterator iter = | 97 for (message_center::NotificationList::Notifications::const_iterator iter = |
| 96 notifications.begin(); | 98 notifications.begin(); |
| 97 iter != notifications.end(); ++iter) { | 99 iter != notifications.end(); ++iter) { |
| 98 if ((*iter)->id() == ScreenLayoutObserver::kNotificationId) | 100 if ((*iter)->id() == ScreenLayoutObserver::kNotificationId) |
| 99 return *iter; | 101 return *iter; |
| 100 } | 102 } |
| 101 | 103 |
| 102 return NULL; | 104 return NULL; |
| 103 } | 105 } |
| 104 | 106 |
| 105 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) { | 107 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) { |
| 106 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | 108 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); |
| 107 tray_delegate->set_should_show_display_notification(true); | 109 tray_delegate->set_should_show_display_notification(true); |
| 108 | 110 |
| 109 UpdateDisplay("400x400"); | 111 UpdateDisplay("400x400"); |
| 110 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 112 display::Display::SetInternalDisplayId(display_manager()->first_display_id()); |
| 111 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 112 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 113 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 113 | 114 |
| 114 // rotation. | 115 // rotation. |
| 115 UpdateDisplay("400x400/r"); | 116 UpdateDisplay("400x400/r"); |
| 116 EXPECT_EQ(l10n_util::GetStringFUTF16( | 117 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 117 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), | 118 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), |
| 118 l10n_util::GetStringUTF16( | 119 l10n_util::GetStringUTF16( |
| 119 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | 120 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), |
| 120 GetDisplayNotificationAdditionalText()); | 121 GetDisplayNotificationAdditionalText()); |
| 121 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 122 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Extended. | 157 // Extended. |
| 157 CloseNotification(); | 158 CloseNotification(); |
| 158 UpdateDisplay("400x400,200x200"); | 159 UpdateDisplay("400x400,200x200"); |
| 159 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | 160 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 160 GetSecondDisplayName()), | 161 GetSecondDisplayName()), |
| 161 GetDisplayNotificationText()); | 162 GetDisplayNotificationText()); |
| 162 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | 163 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); |
| 163 | 164 |
| 164 // Mirroring. | 165 // Mirroring. |
| 165 CloseNotification(); | 166 CloseNotification(); |
| 166 display_manager->SetSoftwareMirroring(true); | 167 display_manager()->SetSoftwareMirroring(true); |
| 167 UpdateDisplay("400x400,200x200"); | 168 UpdateDisplay("400x400,200x200"); |
| 168 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | 169 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, |
| 169 GetMirroringDisplayName()), | 170 GetMirroringDisplayName()), |
| 170 GetDisplayNotificationText()); | 171 GetDisplayNotificationText()); |
| 171 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | 172 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); |
| 172 | 173 |
| 173 // Back to extended. | 174 // Back to extended. |
| 174 CloseNotification(); | 175 CloseNotification(); |
| 175 display_manager->SetSoftwareMirroring(false); | 176 display_manager()->SetSoftwareMirroring(false); |
| 176 UpdateDisplay("400x400,200x200"); | 177 UpdateDisplay("400x400,200x200"); |
| 177 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | 178 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 178 GetSecondDisplayName()), | 179 GetSecondDisplayName()), |
| 179 GetDisplayNotificationText()); | 180 GetDisplayNotificationText()); |
| 180 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | 181 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); |
| 181 | 182 |
| 182 // Resize the first display. | 183 // Resize the first display. |
| 183 UpdateDisplay("400x400@1.5,200x200"); | 184 UpdateDisplay("400x400@1.5,200x200"); |
| 184 EXPECT_EQ(l10n_util::GetStringFUTF16( | 185 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 185 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 186 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 186 GetFirstDisplayName(), base::UTF8ToUTF16("600x600")), | 187 GetFirstDisplayName(), base::UTF8ToUTF16("600x600")), |
| 187 GetDisplayNotificationAdditionalText()); | 188 GetDisplayNotificationAdditionalText()); |
| 188 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 189 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 189 | 190 |
| 190 // Rotate the second. | 191 // Rotate the second. |
| 191 UpdateDisplay("400x400@1.5,200x200/r"); | 192 UpdateDisplay("400x400@1.5,200x200/r"); |
| 192 EXPECT_EQ(l10n_util::GetStringFUTF16( | 193 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 193 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), | 194 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), |
| 194 l10n_util::GetStringUTF16( | 195 l10n_util::GetStringUTF16( |
| 195 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | 196 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), |
| 196 GetDisplayNotificationAdditionalText()); | 197 GetDisplayNotificationAdditionalText()); |
| 197 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 198 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 198 | 199 |
| 199 // Enters closed lid mode. | 200 // Enters closed lid mode. |
| 200 UpdateDisplay("400x400@1.5,200x200"); | 201 UpdateDisplay("400x400@1.5,200x200"); |
| 201 display::Display::SetInternalDisplayId( | 202 display::Display::SetInternalDisplayId( |
| 202 ScreenUtil::GetSecondaryDisplay().id()); | 203 display_manager()->GetSecondaryDisplay().id()); |
| 203 UpdateDisplay("400x400@1.5"); | 204 UpdateDisplay("400x400@1.5"); |
| 204 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), | 205 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), |
| 205 GetDisplayNotificationText()); | 206 GetDisplayNotificationText()); |
| 206 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( | 207 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( |
| 207 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), | 208 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), |
| 208 GetDisplayNotificationAdditionalText()); | 209 GetDisplayNotificationAdditionalText()); |
| 209 } | 210 } |
| 210 | 211 |
| 211 // Verify that notification shows up when display is switched from dock mode to | 212 // Verify that notification shows up when display is switched from dock mode to |
| 212 // extend mode. | 213 // extend mode. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 l10n_util::GetStringUTF16( | 248 l10n_util::GetStringUTF16( |
| 248 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | 249 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), |
| 249 GetDisplayNotificationAdditionalText()); | 250 GetDisplayNotificationAdditionalText()); |
| 250 } | 251 } |
| 251 | 252 |
| 252 // Verify that no notification is shown when overscan of a screen is changed. | 253 // Verify that no notification is shown when overscan of a screen is changed. |
| 253 TEST_F(ScreenLayoutObserverTest, OverscanDisplay) { | 254 TEST_F(ScreenLayoutObserverTest, OverscanDisplay) { |
| 254 UpdateDisplay("400x400, 300x300"); | 255 UpdateDisplay("400x400, 300x300"); |
| 255 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | 256 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); |
| 256 tray_delegate->set_should_show_display_notification(true); | 257 tray_delegate->set_should_show_display_notification(true); |
| 257 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 258 display::Display::SetInternalDisplayId(display_manager()->first_display_id()); |
| 258 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
| 259 | 259 |
| 260 // /o creates the default overscan. | 260 // /o creates the default overscan. |
| 261 UpdateDisplay("400x400, 300x300/o"); | 261 UpdateDisplay("400x400, 300x300/o"); |
| 262 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 262 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 263 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | 263 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); |
| 264 | 264 |
| 265 // Reset the overscan. | 265 // Reset the overscan. |
| 266 Shell::GetInstance()->display_manager()->SetOverscanInsets( | 266 Shell::GetInstance()->display_manager()->SetOverscanInsets( |
| 267 ScreenUtil::GetSecondaryDisplay().id(), gfx::Insets()); | 267 display_manager()->GetSecondaryDisplay().id(), gfx::Insets()); |
| 268 EXPECT_TRUE(GetDisplayNotificationText().empty()); | 268 EXPECT_TRUE(GetDisplayNotificationText().empty()); |
| 269 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | 269 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace ash | 272 } // namespace ash |
| OLD | NEW |