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::SetDisplayNotificationsDisabledForTest(false); |
| 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 return tray_display_->GetDefaultViewMessage(); |
| 107 } |
| 108 |
| 109 base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() { |
| 110 if (!tray_display_->default_view()) |
| 111 return base::string16(); |
| 112 |
| 113 base::string16 tooltip; |
| 114 if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip)) |
| 115 return base::string16(); |
| 116 return tooltip; |
| 117 } |
| 118 |
| 119 base::string16 TrayDisplayTest::GetDisplayNotificationText() { |
| 120 return tray_display_->current_message(); |
| 121 } |
| 122 |
| 123 TEST_F(TrayDisplayTest, NoInternalDisplay) { |
| 124 UpdateDisplay("400x400"); |
| 125 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 126 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 127 |
| 128 UpdateDisplay("400x400,200x200"); |
| 129 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 130 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 131 base::string16 expected = l10n_util::GetStringUTF16( |
| 132 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); |
| 133 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 134 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 135 |
| 136 // mirroring |
| 137 Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true); |
| 138 UpdateDisplay("400x400,200x200"); |
| 139 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 140 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 141 expected = l10n_util::GetStringUTF16( |
| 142 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); |
| 143 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 144 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 145 } |
| 146 |
| 147 TEST_F(TrayDisplayTest, InternalDisplay) { |
| 148 UpdateDisplay("400x400"); |
| 149 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 150 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 151 |
| 152 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 153 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 154 |
| 155 // Extended |
| 156 UpdateDisplay("400x400,200x200"); |
| 157 string16 expected = l10n_util::GetStringFUTF16( |
| 158 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); |
| 159 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 160 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 161 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 162 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 163 |
| 164 // Mirroring |
| 165 display_manager->SetSoftwareMirroring(true); |
| 166 UpdateDisplay("400x400,200x200"); |
| 167 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 168 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 169 |
| 170 expected = l10n_util::GetStringFUTF16( |
| 171 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 172 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 173 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 174 |
| 175 // TODO(mukai): add test case for docked mode here. |
| 176 } |
| 177 |
| 178 TEST_F(TrayDisplayTest, InternalDisplayResized) { |
| 179 UpdateDisplay("400x400@1.5"); |
| 180 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 181 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 182 |
| 183 // Shows the tray_display even though there's a single-display. |
| 184 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 185 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 186 base::string16 internal_info = l10n_util::GetStringFUTF16( |
| 187 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, |
| 188 GetFirstDisplayName(), |
| 189 UTF8ToUTF16("600x600")); |
| 190 EXPECT_EQ(internal_info, GetTrayDisplayText()); |
| 191 EXPECT_EQ(GetTooltipText2(internal_info), GetTrayDisplayTooltipText()); |
| 192 |
| 193 // Extended |
| 194 UpdateDisplay("400x400@1.5,200x200"); |
| 195 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 196 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 197 base::string16 expected = l10n_util::GetStringFUTF16( |
| 198 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); |
| 199 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 200 EXPECT_EQ(GetTooltipText(expected, internal_info), |
| 201 GetTrayDisplayTooltipText()); |
| 202 |
| 203 // Mirroring |
| 204 display_manager->SetSoftwareMirroring(true); |
| 205 UpdateDisplay("400x400@1.5,200x200"); |
| 206 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 207 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 208 expected = l10n_util::GetStringFUTF16( |
| 209 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 210 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 211 EXPECT_EQ(GetTooltipText(expected, internal_info), |
| 212 GetTrayDisplayTooltipText()); |
| 213 } |
| 214 |
| 215 TEST_F(TrayDisplayTest, ExternalDisplayResized) { |
| 216 UpdateDisplay("400x400"); |
| 217 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 218 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 219 |
| 220 // Shows the tray_display even though there's a single-display. |
| 221 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 222 EXPECT_FALSE(IsDisplayVisibleInTray()); |
| 223 |
| 224 // Extended |
| 225 UpdateDisplay("400x400,200x200@1.5"); |
| 226 const gfx::Display& secondary_display = ScreenAsh::GetSecondaryDisplay(); |
| 227 base::string16 secondary_annotation = UTF8ToUTF16( |
| 228 " (" + secondary_display.size().ToString() + ")"); |
| 229 |
| 230 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 231 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 232 base::string16 expected = l10n_util::GetStringFUTF16( |
| 233 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 234 GetSecondDisplayName() + secondary_annotation); |
| 235 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 236 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 237 |
| 238 // Mirroring: in mirroring, it's not possible to lookup the DisplayInfo. |
| 239 display_manager->SetSoftwareMirroring(true); |
| 240 UpdateDisplay("400x400,200x200@1.5"); |
| 241 tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 242 EXPECT_TRUE(IsDisplayVisibleInTray()); |
| 243 expected = l10n_util::GetStringFUTF16( |
| 244 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); |
| 245 EXPECT_EQ(expected, GetTrayDisplayText()); |
| 246 EXPECT_EQ(GetTooltipText1(expected), GetTrayDisplayTooltipText()); |
| 247 } |
| 248 |
| 249 TEST_F(TrayDisplayTest, DisplayNotifications) { |
| 250 UpdateDisplay("400x400"); |
| 251 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 252 gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); |
| 253 EXPECT_FALSE(tray()->HasNotificationBubble()); |
| 254 |
| 255 // rotation. |
| 256 UpdateDisplay("400x400/r"); |
| 257 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 258 base::string16 rotation_message = l10n_util::GetStringFUTF16( |
| 259 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName()); |
| 260 EXPECT_EQ(rotation_message, GetDisplayNotificationText()); |
| 261 |
| 262 CloseNotification(); |
| 263 UpdateDisplay("400x400"); |
| 264 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 265 EXPECT_EQ(rotation_message, GetDisplayNotificationText()); |
| 266 |
| 267 // UI-scale |
| 268 CloseNotification(); |
| 269 UpdateDisplay("400x400@1.5"); |
| 270 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 271 EXPECT_EQ( |
| 272 l10n_util::GetStringFUTF16( |
| 273 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 274 GetFirstDisplayName(), UTF8ToUTF16("600x600")), |
| 275 GetDisplayNotificationText()); |
| 276 |
| 277 // UI-scale to 1.0 |
| 278 CloseNotification(); |
| 279 UpdateDisplay("400x400"); |
| 280 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 281 EXPECT_EQ( |
| 282 l10n_util::GetStringFUTF16( |
| 283 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 284 GetFirstDisplayName(), UTF8ToUTF16("400x400")), |
| 285 GetDisplayNotificationText()); |
| 286 |
| 287 // No-update |
| 288 CloseNotification(); |
| 289 UpdateDisplay("400x400"); |
| 290 EXPECT_FALSE(tray()->HasNotificationBubble()); |
| 291 |
| 292 // Extended. |
| 293 CloseNotification(); |
| 294 UpdateDisplay("400x400,200x200"); |
| 295 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 296 EXPECT_EQ( |
| 297 l10n_util::GetStringFUTF16( |
| 298 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), |
| 299 GetDisplayNotificationText()); |
| 300 |
| 301 // Mirroring. |
| 302 CloseNotification(); |
| 303 display_manager->SetSoftwareMirroring(true); |
| 304 UpdateDisplay("400x400,200x200"); |
| 305 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 306 EXPECT_EQ( |
| 307 l10n_util::GetStringFUTF16( |
| 308 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()), |
| 309 GetDisplayNotificationText()); |
| 310 |
| 311 // Back to extended. |
| 312 CloseNotification(); |
| 313 display_manager->SetSoftwareMirroring(false); |
| 314 UpdateDisplay("400x400,200x200"); |
| 315 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 316 EXPECT_EQ( |
| 317 l10n_util::GetStringFUTF16( |
| 318 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), |
| 319 GetDisplayNotificationText()); |
| 320 |
| 321 // Resize the first display. |
| 322 UpdateDisplay("400x400@1.5,200x200"); |
| 323 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 324 EXPECT_EQ( |
| 325 l10n_util::GetStringFUTF16( |
| 326 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 327 GetFirstDisplayName(), UTF8ToUTF16("600x600")), |
| 328 GetDisplayNotificationText()); |
| 329 |
| 330 // rotate the second. |
| 331 UpdateDisplay("400x400@1.5,200x200/r"); |
| 332 EXPECT_TRUE(tray()->HasNotificationBubble()); |
| 333 EXPECT_EQ( |
| 334 l10n_util::GetStringFUTF16( |
| 335 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName()), |
| 336 GetDisplayNotificationText()); |
| 337 } |
| 338 |
| 339 } // namespace internal |
| 340 } // namespace ash |
OLD | NEW |