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