OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "grit/ash_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/gfx/display.h" |
| 18 #include "ui/views/controls/label.h" |
| 19 |
| 20 namespace ash { |
| 21 namespace internal { |
| 22 |
| 23 base::string16 GetTooltipText(const base::string16& line1, |
| 24 const base::string16& line2) { |
| 25 return line1 + ASCIIToUTF16("\n") + line2; |
| 26 } |
| 27 |
| 28 base::string16 GetTooltipText1(const base::string16& line1) { |
| 29 return GetTooltipText(line1, base::string16()); |
| 30 } |
| 31 |
| 32 base::string16 GetTooltipText2(const base::string16& line2) { |
| 33 return GetTooltipText(base::string16(), line2); |
| 34 } |
| 35 |
| 36 base::string16 GetFirstDisplayName() { |
| 37 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 38 return UTF8ToUTF16(display_manager->GetDisplayNameForId( |
| 39 display_manager->first_display_id())); |
| 40 } |
| 41 |
| 42 base::string16 GetSecondDisplayName() { |
| 43 return UTF8ToUTF16( |
| 44 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
| 45 ScreenAsh::GetSecondaryDisplay().id())); |
| 46 } |
| 47 |
| 48 base::string16 GetMirroredDisplayName() { |
| 49 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 50 return UTF8ToUTF16(display_manager->GetDisplayNameForId( |
| 51 display_manager->mirrored_display().id())); |
| 52 } |
| 53 |
| 54 class TrayDisplayTest : public ash::test::AshTestBase { |
| 55 public: |
| 56 TrayDisplayTest(); |
| 57 virtual ~TrayDisplayTest(); |
| 58 |
| 59 virtual void SetUp() OVERRIDE; |
| 60 |
| 61 protected: |
| 62 SystemTray* tray() { return tray_; } |
| 63 |
| 64 void CloseNotification(); |
| 65 bool IsDisplayVisibleInTray(); |
| 66 base::string16 GetTrayDisplayText(); |
| 67 base::string16 GetTrayDisplayTooltipText(); |
| 68 base::string16 GetDisplayNotificationText(); |
| 69 |
| 70 private: |
| 71 // Weak reference, owned by Shell. |
| 72 SystemTray* tray_; |
| 73 |
| 74 // Weak reference, owned by |tray_|. |
| 75 TrayDisplay* tray_display_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest); |
| 78 }; |
| 79 |
| 80 TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) { |
| 81 } |
| 82 |
| 83 TrayDisplayTest::~TrayDisplayTest() { |
| 84 } |
| 85 |
| 86 void TrayDisplayTest::SetUp() { |
| 87 ash::test::AshTestBase::SetUp(); |
| 88 tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray(); |
| 89 tray_display_ = new TrayDisplay(tray_); |
| 90 tray_->AddTrayItem(tray_display_); |
| 91 TrayDisplay::SetDisplayNotificationsEnabledForTest(true); |
| 92 } |
| 93 |
| 94 void TrayDisplayTest::CloseNotification() { |
| 95 tray()->CloseNotificationBubbleForTest(); |
| 96 tray_display_->HideNotificationView(); |
| 97 RunAllPendingInMessageLoop(); |
| 98 } |
| 99 |
| 100 bool TrayDisplayTest::IsDisplayVisibleInTray() { |
| 101 return tray_display_->default_view() && |
| 102 tray_display_->default_view()->visible(); |
| 103 } |
| 104 |
| 105 base::string16 TrayDisplayTest::GetTrayDisplayText() { |
| 106 if (!tray_display_->default_view()) |
| 107 return base::string16(); |
| 108 return tray_display_->default_view()->label()->text(); |
| 109 } |
| 110 |
| 111 base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() { |
| 112 if (!tray_display_->default_view()) |
| 113 return base::string16(); |
| 114 |
| 115 base::string16 tooltip; |
| 116 if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip)) |
| 117 return base::string16(); |
| 118 return tooltip; |
| 119 } |
| 120 |
| 121 base::string16 TrayDisplayTest::GetDisplayNotificationText() { |
| 122 return tray_display_->current_message(); |
| 123 } |
| 124 |
| 125 TEST_F(TrayDisplayTest, NoInternalDisplay) { |
| 126 UpdateDisplay("400x400"); |
| 127 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 128 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 129 |
| 130 UpdateDisplay("400x400,200x200"); |
| 131 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 132 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 133 base::string16 expected = l10n_util::GetStringUTF16( |
| 134 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); |
| 135 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 136 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 137 |
| 138 // mirroring |
| 139 Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true); |
| 140 UpdateDisplay("400x400,200x200"); |
| 141 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 142 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 143 expected = l10n_util::GetStringUTF16( |
| 144 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); |
| 145 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 146 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 147 } |
| 148 |
| 149 TEST_F(TrayDisplayTest, InternalDisplay) { |
| 150 UpdateDisplay("400x400"); |
| 151 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 152 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 153 |
| 154 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 155 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 156 |
| 157 // Extended |
| 158 UpdateDisplay("400x400,200x200"); |
| 159 string16 expected = l10n_util::GetStringFUTF16( |
| 160 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); |
| 161 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 162 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 163 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 164 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 165 |
| 166 // Mirroring |
| 167 display_manager->SetSoftwareMirroring(true); |
| 168 UpdateDisplay("400x400,200x200"); |
| 169 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 170 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 171 |
| 172 expected = l10n_util::GetStringFUTF16( |
| 173 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 174 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 175 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 176 |
| 177 // TODO(mukai): add test case for docked mode here. |
| 178 } |
| 179 |
| 180 TEST_F(TrayDisplayTest, InternalDisplayResized) { |
| 181 UpdateDisplay("400x400@1.5"); |
| 182 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 183 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 184 |
| 185 // Shows the tray_display even though there's a single-display. |
| 186 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 187 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 188 base::string16 internal_info = l10n_util::GetStringFUTF16( |
| 189 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, |
| 190 GetFirstDisplayName(), |
| 191 UTF8ToUTF16("600x600")); |
| 192 EXPECT_EQ(internal_info, GetTrayDisplayText()); |
| 193 EXPECT_EQ(GetTooltipText2(internal_info), GetTrayDisplayTooltipText()); |
| 194 |
| 195 // Extended |
| 196 UpdateDisplay("400x400@1.5,200x200"); |
| 197 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 198 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 199 base::string16 expected = l10n_util::GetStringFUTF16( |
| 200 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); |
| 201 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 202 EXPECT_EQ(GetTooltipText(expected, internal_info), |
| 203 GetTrayDisplayTooltipText()); |
| 204 |
| 205 // Mirroring |
| 206 display_manager->SetSoftwareMirroring(true); |
| 207 UpdateDisplay("400x400@1.5,200x200"); |
| 208 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 209 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 210 expected = l10n_util::GetStringFUTF16( |
| 211 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 212 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 213 EXPECT_EQ(GetTooltipText(expected, internal_info), |
| 214 GetTrayDisplayTooltipText()); |
| 215 } |
| 216 |
| 217 TEST_F(TrayDisplayTest, ExternalDisplayResized) { |
| 218 UpdateDisplay("400x400"); |
| 219 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 220 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 221 |
| 222 // Shows the tray_display even though there's a single-display. |
| 223 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 224 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 225 |
| 226 // Extended |
| 227 UpdateDisplay("400x400,200x200@1.5"); |
| 228 const gfx::Display& secondary_display = ScreenAsh::GetSecondaryDisplay(); |
| 229 base::string16 secondary_annotation = UTF8ToUTF16( |
| 230 " (" + secondary_display.size().ToString() + ")"); |
| 231 |
| 232 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 233 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 234 base::string16 expected = l10n_util::GetStringFUTF16( |
| 235 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 236 GetSecondDisplayName() + secondary_annotation); |
| 237 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 238 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 239 |
| 240 // Mirroring: in mirroring, it's not possible to lookup the DisplayInfo. |
| 241 display_manager->SetSoftwareMirroring(true); |
| 242 UpdateDisplay("400x400,200x200@1.5"); |
| 243 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 244 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 245 expected = l10n_util::GetStringFUTF16( |
| 246 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 247 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 248 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 249 } |
| 250 |
| 251 TEST_F(TrayDisplayTest, DisplayNotifications) { |
| 252 UpdateDisplay("400x400"); |
| 253 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 254 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 255 EXPECT_FALSE(tray()->HasNotificationBubble()); |
| 256 |
| 257 // rotation. |
| 258 UpdateDisplay("400x400/r"); |
| 259 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 260 base::string16 rotation_message = l10n_util::GetStringFUTF16( |
| 261 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName()); |
| 262 EXPECT_EQ(rotation_message, GetDisplayNotificationText()); |
| 263 |
| 264 CloseNotification(); |
| 265 UpdateDisplay("400x400"); |
| 266 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 267 EXPECT_EQ(rotation_message, GetDisplayNotificationText()); |
| 268 |
| 269 // UI-scale |
| 270 CloseNotification(); |
| 271 UpdateDisplay("400x400@1.5"); |
| 272 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 273 EXPECT_EQ( |
| 274 l10n_util::GetStringFUTF16( |
| 275 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 276 GetFirstDisplayName(), UTF8ToUTF16("600x600")), |
| 277 GetDisplayNotificationText()); |
| 278 |
| 279 // UI-scale to 1.0 |
| 280 CloseNotification(); |
| 281 UpdateDisplay("400x400"); |
| 282 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 283 EXPECT_EQ( |
| 284 l10n_util::GetStringFUTF16( |
| 285 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 286 GetFirstDisplayName(), UTF8ToUTF16("400x400")), |
| 287 GetDisplayNotificationText()); |
| 288 |
| 289 // No-update |
| 290 CloseNotification(); |
| 291 UpdateDisplay("400x400"); |
| 292 EXPECT_FALSE(tray()->HasNotificationBubble()); |
| 293 |
| 294 // Extended. |
| 295 CloseNotification(); |
| 296 UpdateDisplay("400x400,200x200"); |
| 297 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 298 EXPECT_EQ( |
| 299 l10n_util::GetStringFUTF16( |
| 300 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), |
| 301 GetDisplayNotificationText()); |
| 302 |
| 303 // Mirroring. |
| 304 CloseNotification(); |
| 305 display_manager->SetSoftwareMirroring(true); |
| 306 UpdateDisplay("400x400,200x200"); |
| 307 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 308 EXPECT_EQ( |
| 309 l10n_util::GetStringFUTF16( |
| 310 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()), |
| 311 GetDisplayNotificationText()); |
| 312 |
| 313 // Back to extended. |
| 314 CloseNotification(); |
| 315 display_manager->SetSoftwareMirroring(false); |
| 316 UpdateDisplay("400x400,200x200"); |
| 317 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 318 EXPECT_EQ( |
| 319 l10n_util::GetStringFUTF16( |
| 320 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), |
| 321 GetDisplayNotificationText()); |
| 322 |
| 323 // Resize the first display. |
| 324 UpdateDisplay("400x400@1.5,200x200"); |
| 325 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 326 EXPECT_EQ( |
| 327 l10n_util::GetStringFUTF16( |
| 328 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 329 GetFirstDisplayName(), UTF8ToUTF16("600x600")), |
| 330 GetDisplayNotificationText()); |
| 331 |
| 332 // rotate the second. |
| 333 UpdateDisplay("400x400@1.5,200x200/r"); |
| 334 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 335 EXPECT_EQ( |
| 336 l10n_util::GetStringFUTF16( |
| 337 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName()), |
| 338 GetDisplayNotificationText()); |
| 339 } |
| 340 |
| 341 } // namespace internal |
| 342 } // namespace ash |
OLD | NEW |