OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/tray_display.h" | |
6 | |
7 #include "ash/common/system/chromeos/devicetype_utils.h" | |
8 #include "ash/common/system/tray/system_tray.h" | |
9 #include "ash/display/display_manager.h" | |
10 #include "ash/screen_util.h" | |
11 #include "ash/shell.h" | |
12 #include "ash/test/ash_test_base.h" | |
13 #include "ash/test/display_manager_test_api.h" | |
14 #include "ash/test/test_system_tray_delegate.h" | |
15 #include "base/strings/string16.h" | |
16 #include "base/strings/string_util.h" | |
17 #include "base/strings/utf_string_conversions.h" | |
18 #include "grit/ash_strings.h" | |
19 #include "ui/accessibility/ax_view_state.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 #include "ui/display/display.h" | |
22 #include "ui/message_center/message_center.h" | |
23 #include "ui/message_center/notification.h" | |
24 #include "ui/message_center/notification_list.h" | |
25 #include "ui/views/controls/label.h" | |
26 | |
27 namespace ash { | |
28 | |
29 base::string16 GetTooltipText(const base::string16& headline, | |
30 const base::string16& name1, | |
31 const std::string& data1, | |
32 const base::string16& name2, | |
33 const std::string& data2) { | |
34 std::vector<base::string16> lines; | |
35 lines.push_back(headline); | |
36 if (data1.empty()) { | |
37 lines.push_back(name1); | |
38 } else { | |
39 lines.push_back( | |
40 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | |
41 name1, base::UTF8ToUTF16(data1))); | |
42 } | |
43 if (!name2.empty()) { | |
44 lines.push_back( | |
45 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | |
46 name2, base::UTF8ToUTF16(data2))); | |
47 } | |
48 return base::JoinString(lines, base::ASCIIToUTF16("\n")); | |
49 } | |
50 | |
51 base::string16 GetMirroredTooltipText(const base::string16& headline, | |
52 const base::string16& name, | |
53 const std::string& data) { | |
54 return GetTooltipText(headline, name, data, base::string16(), ""); | |
55 } | |
56 | |
57 base::string16 GetFirstDisplayName() { | |
58 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
59 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | |
60 display_manager->first_display_id())); | |
61 } | |
62 | |
63 base::string16 GetSecondDisplayName() { | |
64 return base::UTF8ToUTF16( | |
65 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | |
66 ScreenUtil::GetSecondaryDisplay().id())); | |
67 } | |
68 | |
69 base::string16 GetMirroringDisplayName() { | |
70 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
71 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( | |
72 display_manager->mirroring_display_id())); | |
73 } | |
74 | |
75 class TrayDisplayTest : public ash::test::AshTestBase { | |
76 public: | |
77 TrayDisplayTest(); | |
78 ~TrayDisplayTest() override; | |
79 | |
80 void SetUp() override; | |
81 | |
82 protected: | |
83 SystemTray* GetTray(); | |
84 TrayDisplay* GetTrayDisplay(); | |
85 void CheckUpdate(); | |
86 | |
87 void CloseNotification(); | |
88 bool IsDisplayVisibleInTray() const; | |
89 base::string16 GetTrayDisplayText() const; | |
90 void CheckAccessibleName() const; | |
91 base::string16 GetTrayDisplayTooltipText() const; | |
92 base::string16 GetDisplayNotificationText() const; | |
93 base::string16 GetDisplayNotificationAdditionalText() const; | |
94 | |
95 private: | |
96 const message_center::Notification* GetDisplayNotification() const; | |
97 | |
98 // Weak reference, owned by Shell. | |
99 SystemTray* tray_; | |
100 | |
101 // Weak reference, owned by |tray_|. | |
102 TrayDisplay* tray_display_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest); | |
105 }; | |
106 | |
107 TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) {} | |
108 | |
109 TrayDisplayTest::~TrayDisplayTest() {} | |
110 | |
111 void TrayDisplayTest::SetUp() { | |
112 ash::test::AshTestBase::SetUp(); | |
113 // Populate tray_ and tray_display_. | |
114 CheckUpdate(); | |
115 } | |
116 | |
117 SystemTray* TrayDisplayTest::GetTray() { | |
118 CheckUpdate(); | |
119 return tray_; | |
120 } | |
121 | |
122 TrayDisplay* TrayDisplayTest::GetTrayDisplay() { | |
123 CheckUpdate(); | |
124 return tray_display_; | |
125 } | |
126 | |
127 void TrayDisplayTest::CheckUpdate() { | |
128 SystemTray* current = GetPrimarySystemTray(); | |
129 if (tray_ != current) { | |
130 tray_ = current; | |
131 tray_display_ = new TrayDisplay(tray_); | |
132 tray_->AddTrayItem(tray_display_); | |
133 } | |
134 } | |
135 | |
136 void TrayDisplayTest::CloseNotification() { | |
137 message_center::MessageCenter::Get()->RemoveNotification( | |
138 TrayDisplay::kNotificationId, false); | |
139 RunAllPendingInMessageLoop(); | |
140 } | |
141 | |
142 bool TrayDisplayTest::IsDisplayVisibleInTray() const { | |
143 return tray_->HasSystemBubble() && tray_display_->default_view() && | |
144 tray_display_->default_view()->visible(); | |
145 } | |
146 | |
147 base::string16 TrayDisplayTest::GetTrayDisplayText() const { | |
148 return tray_display_->GetDefaultViewMessage(); | |
149 } | |
150 | |
151 void TrayDisplayTest::CheckAccessibleName() const { | |
152 ui::AXViewState state; | |
153 if (tray_display_->GetAccessibleStateForTesting(&state)) { | |
154 base::string16 expected = tray_display_->GetDefaultViewMessage(); | |
155 EXPECT_EQ(expected, state.name); | |
156 } | |
157 } | |
158 | |
159 base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() const { | |
160 if (!tray_display_->default_view()) | |
161 return base::string16(); | |
162 | |
163 base::string16 tooltip; | |
164 if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip)) | |
165 return base::string16(); | |
166 return tooltip; | |
167 } | |
168 | |
169 base::string16 TrayDisplayTest::GetDisplayNotificationText() const { | |
170 const message_center::Notification* notification = GetDisplayNotification(); | |
171 return notification ? notification->title() : base::string16(); | |
172 } | |
173 | |
174 base::string16 TrayDisplayTest::GetDisplayNotificationAdditionalText() const { | |
175 const message_center::Notification* notification = GetDisplayNotification(); | |
176 return notification ? notification->message() : base::string16(); | |
177 } | |
178 | |
179 const message_center::Notification* TrayDisplayTest::GetDisplayNotification() | |
180 const { | |
181 const message_center::NotificationList::Notifications notifications = | |
182 message_center::MessageCenter::Get()->GetVisibleNotifications(); | |
183 for (message_center::NotificationList::Notifications::const_iterator iter = | |
184 notifications.begin(); | |
185 iter != notifications.end(); ++iter) { | |
186 if ((*iter)->id() == TrayDisplay::kNotificationId) | |
187 return *iter; | |
188 } | |
189 | |
190 return NULL; | |
191 } | |
192 | |
193 TEST_F(TrayDisplayTest, NoInternalDisplay) { | |
194 UpdateDisplay("400x400"); | |
195 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
196 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
197 | |
198 UpdateDisplay("400x400,200x200"); | |
199 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
200 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
201 base::string16 expected = l10n_util::GetStringUTF16( | |
202 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | |
203 base::string16 first_name = GetFirstDisplayName(); | |
204 EXPECT_EQ(expected, GetTrayDisplayText()); | |
205 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
206 GetSecondDisplayName(), "200x200"), | |
207 GetTrayDisplayTooltipText()); | |
208 CheckAccessibleName(); | |
209 | |
210 // mirroring | |
211 Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true); | |
212 UpdateDisplay("400x400,200x200"); | |
213 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
214 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
215 expected = l10n_util::GetStringUTF16( | |
216 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); | |
217 EXPECT_EQ(expected, GetTrayDisplayText()); | |
218 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
219 GetTrayDisplayTooltipText()); | |
220 CheckAccessibleName(); | |
221 } | |
222 | |
223 TEST_F(TrayDisplayTest, InternalDisplay) { | |
224 UpdateDisplay("400x400"); | |
225 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
226 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
227 | |
228 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
229 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
230 | |
231 // Extended | |
232 UpdateDisplay("400x400,200x200"); | |
233 base::string16 expected = l10n_util::GetStringFUTF16( | |
234 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); | |
235 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
236 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
237 EXPECT_EQ(expected, GetTrayDisplayText()); | |
238 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
239 GetSecondDisplayName(), "200x200"), | |
240 GetTrayDisplayTooltipText()); | |
241 CheckAccessibleName(); | |
242 | |
243 // Mirroring | |
244 display_manager->SetSoftwareMirroring(true); | |
245 UpdateDisplay("400x400,200x200"); | |
246 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
247 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
248 | |
249 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
250 GetMirroringDisplayName()); | |
251 EXPECT_EQ(expected, GetTrayDisplayText()); | |
252 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
253 GetTrayDisplayTooltipText()); | |
254 CheckAccessibleName(); | |
255 } | |
256 | |
257 TEST_F(TrayDisplayTest, InternalDisplayResized) { | |
258 UpdateDisplay("400x400@1.5"); | |
259 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
260 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
261 | |
262 // Shows the tray_display even though there's a single-display. | |
263 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
264 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
265 base::string16 internal_info = l10n_util::GetStringFUTF16( | |
266 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, GetFirstDisplayName(), | |
267 base::UTF8ToUTF16("600x600")); | |
268 EXPECT_EQ(internal_info, GetTrayDisplayText()); | |
269 EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", | |
270 base::string16(), std::string()), | |
271 GetTrayDisplayTooltipText()); | |
272 CheckAccessibleName(); | |
273 | |
274 // Extended | |
275 UpdateDisplay("400x400@1.5,200x200"); | |
276 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
277 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
278 base::string16 expected = l10n_util::GetStringFUTF16( | |
279 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); | |
280 EXPECT_EQ(expected, GetTrayDisplayText()); | |
281 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600", | |
282 GetSecondDisplayName(), "200x200"), | |
283 GetTrayDisplayTooltipText()); | |
284 CheckAccessibleName(); | |
285 | |
286 // Mirroring | |
287 display_manager->SetSoftwareMirroring(true); | |
288 UpdateDisplay("400x400@1.5,200x200"); | |
289 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
290 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
291 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
292 GetMirroringDisplayName()); | |
293 EXPECT_EQ(expected, GetTrayDisplayText()); | |
294 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "600x600"), | |
295 GetTrayDisplayTooltipText()); | |
296 CheckAccessibleName(); | |
297 | |
298 // Closed lid mode. | |
299 display_manager->SetSoftwareMirroring(false); | |
300 UpdateDisplay("400x400@1.5,200x200"); | |
301 display::Display::SetInternalDisplayId( | |
302 ScreenUtil::GetSecondaryDisplay().id()); | |
303 UpdateDisplay("400x400@1.5"); | |
304 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
305 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
306 expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); | |
307 EXPECT_EQ(expected, GetTrayDisplayText()); | |
308 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600", | |
309 base::string16(), ""), | |
310 GetTrayDisplayTooltipText()); | |
311 CheckAccessibleName(); | |
312 | |
313 // Unified mode | |
314 display_manager->SetUnifiedDesktopEnabled(true); | |
315 UpdateDisplay("300x200,400x500"); | |
316 // Update the cache variables as the primary root window changed. | |
317 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
318 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
319 expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED); | |
320 EXPECT_EQ(expected, GetTrayDisplayText()); | |
321 } | |
322 | |
323 TEST_F(TrayDisplayTest, ExternalDisplayResized) { | |
324 UpdateDisplay("400x400"); | |
325 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
326 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
327 | |
328 // Shows the tray_display even though there's a single-display. | |
329 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
330 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
331 | |
332 // Extended | |
333 UpdateDisplay("400x400,200x200@1.5"); | |
334 const display::Display& secondary_display = ScreenUtil::GetSecondaryDisplay(); | |
335 | |
336 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
337 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
338 base::string16 expected = l10n_util::GetStringFUTF16( | |
339 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
340 l10n_util::GetStringFUTF16( | |
341 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, GetSecondDisplayName(), | |
342 base::UTF8ToUTF16(secondary_display.size().ToString()))); | |
343 EXPECT_EQ(expected, GetTrayDisplayText()); | |
344 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
345 GetSecondDisplayName(), "300x300"), | |
346 GetTrayDisplayTooltipText()); | |
347 CheckAccessibleName(); | |
348 | |
349 // Mirroring | |
350 display_manager->SetSoftwareMirroring(true); | |
351 UpdateDisplay("400x400,200x200@1.5"); | |
352 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
353 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
354 expected = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
355 GetMirroringDisplayName()); | |
356 EXPECT_EQ(expected, GetTrayDisplayText()); | |
357 EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), | |
358 GetTrayDisplayTooltipText()); | |
359 CheckAccessibleName(); | |
360 } | |
361 | |
362 TEST_F(TrayDisplayTest, OverscanDisplay) { | |
363 UpdateDisplay("400x400,300x300/o"); | |
364 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
365 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
366 | |
367 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
368 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
369 | |
370 // /o creates the default overscan, and if overscan is set, the annotation | |
371 // should be the size. | |
372 base::string16 overscan = l10n_util::GetStringUTF16( | |
373 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN); | |
374 base::string16 headline = l10n_util::GetStringFUTF16( | |
375 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
376 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | |
377 GetSecondDisplayName(), | |
378 base::UTF8ToUTF16("286x286"))); | |
379 std::string second_data = | |
380 l10n_util::GetStringFUTF8(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, | |
381 base::UTF8ToUTF16("286x286"), overscan); | |
382 EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", | |
383 GetSecondDisplayName(), second_data), | |
384 GetTrayDisplayTooltipText()); | |
385 | |
386 // reset the overscan. | |
387 display_manager->SetOverscanInsets(ScreenUtil::GetSecondaryDisplay().id(), | |
388 gfx::Insets()); | |
389 headline = l10n_util::GetStringFUTF16( | |
390 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
391 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | |
392 GetSecondDisplayName(), overscan)); | |
393 second_data = | |
394 l10n_util::GetStringFUTF8(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, | |
395 base::UTF8ToUTF16("300x300"), overscan); | |
396 EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", | |
397 GetSecondDisplayName(), second_data), | |
398 GetTrayDisplayTooltipText()); | |
399 } | |
400 | |
401 TEST_F(TrayDisplayTest, UpdateDuringDisplayConfigurationChange) { | |
402 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
403 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
404 | |
405 UpdateDisplay("400x400@1.5"); | |
406 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
407 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
408 base::string16 internal_info = l10n_util::GetStringFUTF16( | |
409 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, GetFirstDisplayName(), | |
410 base::UTF8ToUTF16("600x600")); | |
411 EXPECT_EQ(internal_info, GetTrayDisplayText()); | |
412 EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", | |
413 base::string16(), std::string()), | |
414 GetTrayDisplayTooltipText()); | |
415 CheckAccessibleName(); | |
416 | |
417 UpdateDisplay("400x400,200x200"); | |
418 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
419 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
420 base::string16 expected = l10n_util::GetStringUTF16( | |
421 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | |
422 base::string16 first_name = GetFirstDisplayName(); | |
423 EXPECT_EQ(expected, GetTrayDisplayText()); | |
424 EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", | |
425 GetSecondDisplayName(), "200x200"), | |
426 GetTrayDisplayTooltipText()); | |
427 CheckAccessibleName(); | |
428 | |
429 UpdateDisplay("400x400@1.5"); | |
430 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
431 | |
432 // Back to the default state, the display tray item should disappear. | |
433 UpdateDisplay("400x400"); | |
434 EXPECT_TRUE(GetTray()->HasSystemBubble()); | |
435 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
436 } | |
437 | |
438 TEST_F(TrayDisplayTest, DisplayNotifications) { | |
439 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | |
440 tray_delegate->set_should_show_display_notification(true); | |
441 | |
442 UpdateDisplay("400x400"); | |
443 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
444 display::Display::SetInternalDisplayId(display_manager->first_display_id()); | |
445 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
446 | |
447 // rotation. | |
448 UpdateDisplay("400x400/r"); | |
449 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
450 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), | |
451 l10n_util::GetStringUTF16( | |
452 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | |
453 GetDisplayNotificationAdditionalText()); | |
454 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
455 | |
456 CloseNotification(); | |
457 UpdateDisplay("400x400"); | |
458 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
459 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), | |
460 l10n_util::GetStringUTF16( | |
461 IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION)), | |
462 GetDisplayNotificationAdditionalText()); | |
463 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
464 | |
465 // UI-scale | |
466 CloseNotification(); | |
467 UpdateDisplay("400x400@1.5"); | |
468 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
469 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | |
470 GetFirstDisplayName(), base::UTF8ToUTF16("600x600")), | |
471 GetDisplayNotificationAdditionalText()); | |
472 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
473 | |
474 // UI-scale to 1.0 | |
475 CloseNotification(); | |
476 UpdateDisplay("400x400"); | |
477 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
478 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | |
479 GetFirstDisplayName(), base::UTF8ToUTF16("400x400")), | |
480 GetDisplayNotificationAdditionalText()); | |
481 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
482 | |
483 // No-update | |
484 CloseNotification(); | |
485 UpdateDisplay("400x400"); | |
486 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
487 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | |
488 | |
489 // Extended. | |
490 CloseNotification(); | |
491 UpdateDisplay("400x400,200x200"); | |
492 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
493 GetSecondDisplayName()), | |
494 GetDisplayNotificationText()); | |
495 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | |
496 | |
497 // Mirroring. | |
498 CloseNotification(); | |
499 display_manager->SetSoftwareMirroring(true); | |
500 UpdateDisplay("400x400,200x200"); | |
501 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
502 GetMirroringDisplayName()), | |
503 GetDisplayNotificationText()); | |
504 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | |
505 | |
506 // Back to extended. | |
507 CloseNotification(); | |
508 display_manager->SetSoftwareMirroring(false); | |
509 UpdateDisplay("400x400,200x200"); | |
510 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
511 GetSecondDisplayName()), | |
512 GetDisplayNotificationText()); | |
513 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); | |
514 | |
515 // Resize the first display. | |
516 UpdateDisplay("400x400@1.5,200x200"); | |
517 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
518 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | |
519 GetFirstDisplayName(), base::UTF8ToUTF16("600x600")), | |
520 GetDisplayNotificationAdditionalText()); | |
521 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
522 | |
523 // Rotate the second. | |
524 UpdateDisplay("400x400@1.5,200x200/r"); | |
525 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
526 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), | |
527 l10n_util::GetStringUTF16( | |
528 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | |
529 GetDisplayNotificationAdditionalText()); | |
530 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
531 | |
532 // Enters closed lid mode. | |
533 UpdateDisplay("400x400@1.5,200x200"); | |
534 display::Display::SetInternalDisplayId( | |
535 ScreenUtil::GetSecondaryDisplay().id()); | |
536 UpdateDisplay("400x400@1.5"); | |
537 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), | |
538 GetDisplayNotificationText()); | |
539 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( | |
540 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), | |
541 GetDisplayNotificationAdditionalText()); | |
542 } | |
543 | |
544 TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) { | |
545 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | |
546 tray_delegate->set_should_show_display_notification(true); | |
547 | |
548 UpdateDisplay("400x400,200x200"); | |
549 EXPECT_EQ(l10n_util::GetStringUTF16( | |
550 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), | |
551 GetDisplayNotificationText()); | |
552 | |
553 // OnDisplayConfigurationChanged() may be called more than once for a single | |
554 // update display in case of primary is swapped or recovered from dock mode. | |
555 // Should not remove the notification in such case. | |
556 GetTrayDisplay()->OnDisplayConfigurationChanged(); | |
557 EXPECT_EQ(l10n_util::GetStringUTF16( | |
558 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), | |
559 GetDisplayNotificationText()); | |
560 | |
561 // Back to the single display. It SHOULD remove the notification since the | |
562 // information is stale. | |
563 UpdateDisplay("400x400"); | |
564 EXPECT_TRUE(GetDisplayNotificationText().empty()); | |
565 } | |
566 | |
567 TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) { | |
568 UpdateDisplay("400x400,200x200"); | |
569 | |
570 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); | |
571 tray_delegate->set_should_show_display_notification(true); | |
572 | |
573 // rotate the second. | |
574 UpdateDisplay("400x400,200x200/r"); | |
575 EXPECT_EQ(l10n_util::GetStringFUTF16( | |
576 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), | |
577 l10n_util::GetStringUTF16( | |
578 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), | |
579 GetDisplayNotificationAdditionalText()); | |
580 } | |
581 | |
582 // Tests that when the only change is rotation, that it is only displayed when | |
583 // caused by user changes, and not by accelerometers. | |
584 TEST_F(TrayDisplayTest, RotationOnInternalDisplay) { | |
585 UpdateDisplay("400x400"); | |
586 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
587 const int64_t display_id = display_manager->first_display_id(); | |
588 display::Display::SetInternalDisplayId(display_id); | |
589 | |
590 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
591 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
592 | |
593 // Accelerometer change does not display. | |
594 display_manager->SetDisplayRotation( | |
595 display_id, display::Display::ROTATE_90, | |
596 display::Display::ROTATION_SOURCE_ACCELEROMETER); | |
597 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
598 | |
599 // User change does. | |
600 display_manager->SetDisplayRotation(display_id, display::Display::ROTATE_180, | |
601 display::Display::ROTATION_SOURCE_USER); | |
602 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
603 | |
604 // If a user setting matches the accelerometer, do not display if caused by | |
605 // the accelerometer. | |
606 display_manager->SetDisplayRotation( | |
607 display_id, display::Display::ROTATE_180, | |
608 display::Display::ROTATION_SOURCE_ACCELEROMETER); | |
609 EXPECT_FALSE(IsDisplayVisibleInTray()); | |
610 | |
611 // If a non-rotation setting is changed, display regardless of the source of | |
612 // rotation so that the full message is shown. | |
613 UpdateDisplay("400x400@1.5"); | |
614 EXPECT_TRUE(IsDisplayVisibleInTray()); | |
615 } | |
616 | |
617 } // namespace ash | |
OLD | NEW |