Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ash/system/chromeos/screen_layout_observer_unittest.cc

Issue 2217713002: Remove the system menu display settings row (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/chromeos/screen_layout_observer.cc ('k') | ash/system/chromeos/tray_display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tray_display.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" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/display_manager_test_api.h" 13 #include "ash/test/display_manager_test_api.h"
14 #include "ash/test/test_system_tray_delegate.h" 14 #include "ash/test/test_system_tray_delegate.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
19 #include "ui/accessibility/ax_view_state.h" 19 #include "ui/accessibility/ax_view_state.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/display/display.h" 21 #include "ui/display/display.h"
22 #include "ui/message_center/message_center.h" 22 #include "ui/message_center/message_center.h"
23 #include "ui/message_center/notification.h" 23 #include "ui/message_center/notification.h"
24 #include "ui/message_center/notification_list.h" 24 #include "ui/message_center/notification_list.h"
25 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
26 26
27 namespace ash { 27 namespace ash {
28 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() { 29 base::string16 GetFirstDisplayName() {
58 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 30 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
59 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( 31 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId(
60 display_manager->first_display_id())); 32 display_manager->first_display_id()));
61 } 33 }
62 34
63 base::string16 GetSecondDisplayName() { 35 base::string16 GetSecondDisplayName() {
64 return base::UTF8ToUTF16( 36 return base::UTF8ToUTF16(
65 Shell::GetInstance()->display_manager()->GetDisplayNameForId( 37 Shell::GetInstance()->display_manager()->GetDisplayNameForId(
66 ScreenUtil::GetSecondaryDisplay().id())); 38 ScreenUtil::GetSecondaryDisplay().id()));
67 } 39 }
68 40
69 base::string16 GetMirroringDisplayName() { 41 base::string16 GetMirroringDisplayName() {
70 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 42 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
71 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId( 43 return base::UTF8ToUTF16(display_manager->GetDisplayNameForId(
72 display_manager->mirroring_display_id())); 44 display_manager->mirroring_display_id()));
73 } 45 }
74 46
75 class TrayDisplayTest : public ash::test::AshTestBase { 47 class ScreenLayoutObserverTest : public test::AshTestBase {
76 public: 48 public:
77 TrayDisplayTest(); 49 ScreenLayoutObserverTest();
78 ~TrayDisplayTest() override; 50 ~ScreenLayoutObserverTest() override;
79
80 void SetUp() override;
81 51
82 protected: 52 protected:
83 SystemTray* GetTray(); 53 ScreenLayoutObserver* GetScreenLayoutObserver();
84 TrayDisplay* GetTrayDisplay();
85 void CheckUpdate(); 54 void CheckUpdate();
86 55
87 void CloseNotification(); 56 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; 57 base::string16 GetDisplayNotificationText() const;
93 base::string16 GetDisplayNotificationAdditionalText() const; 58 base::string16 GetDisplayNotificationAdditionalText() const;
94 59
95 private: 60 private:
96 const message_center::Notification* GetDisplayNotification() const; 61 const message_center::Notification* GetDisplayNotification() const;
97 62
98 // Weak reference, owned by Shell. 63 DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTest);
99 SystemTray* tray_;
100
101 // Weak reference, owned by |tray_|.
102 TrayDisplay* tray_display_;
103
104 DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest);
105 }; 64 };
106 65
107 TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) {} 66 ScreenLayoutObserverTest::ScreenLayoutObserverTest() {}
108 67
109 TrayDisplayTest::~TrayDisplayTest() {} 68 ScreenLayoutObserverTest::~ScreenLayoutObserverTest() {}
110 69
111 void TrayDisplayTest::SetUp() { 70 ScreenLayoutObserver* ScreenLayoutObserverTest::GetScreenLayoutObserver() {
112 ash::test::AshTestBase::SetUp(); 71 return Shell::GetInstance()->screen_layout_observer();
113 // Populate tray_ and tray_display_.
114 CheckUpdate();
115 } 72 }
116 73
117 SystemTray* TrayDisplayTest::GetTray() { 74 void ScreenLayoutObserverTest::CloseNotification() {
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( 75 message_center::MessageCenter::Get()->RemoveNotification(
138 TrayDisplay::kNotificationId, false); 76 ScreenLayoutObserver::kNotificationId, false);
139 RunAllPendingInMessageLoop(); 77 RunAllPendingInMessageLoop();
140 } 78 }
141 79
142 bool TrayDisplayTest::IsDisplayVisibleInTray() const { 80 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationText() 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(); 81 const message_center::Notification* notification = GetDisplayNotification();
171 return notification ? notification->title() : base::string16(); 82 return notification ? notification->title() : base::string16();
172 } 83 }
173 84
174 base::string16 TrayDisplayTest::GetDisplayNotificationAdditionalText() const { 85 base::string16 ScreenLayoutObserverTest::GetDisplayNotificationAdditionalText()
86 const {
175 const message_center::Notification* notification = GetDisplayNotification(); 87 const message_center::Notification* notification = GetDisplayNotification();
176 return notification ? notification->message() : base::string16(); 88 return notification ? notification->message() : base::string16();
177 } 89 }
178 90
179 const message_center::Notification* TrayDisplayTest::GetDisplayNotification() 91 const message_center::Notification*
180 const { 92 ScreenLayoutObserverTest::GetDisplayNotification() const {
181 const message_center::NotificationList::Notifications notifications = 93 const message_center::NotificationList::Notifications notifications =
182 message_center::MessageCenter::Get()->GetVisibleNotifications(); 94 message_center::MessageCenter::Get()->GetVisibleNotifications();
183 for (message_center::NotificationList::Notifications::const_iterator iter = 95 for (message_center::NotificationList::Notifications::const_iterator iter =
184 notifications.begin(); 96 notifications.begin();
185 iter != notifications.end(); ++iter) { 97 iter != notifications.end(); ++iter) {
186 if ((*iter)->id() == TrayDisplay::kNotificationId) 98 if ((*iter)->id() == ScreenLayoutObserver::kNotificationId)
187 return *iter; 99 return *iter;
188 } 100 }
189 101
190 return NULL; 102 return NULL;
191 } 103 }
192 104
193 TEST_F(TrayDisplayTest, NoInternalDisplay) { 105 TEST_F(ScreenLayoutObserverTest, DisplayNotifications) {
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(); 106 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate();
440 tray_delegate->set_should_show_display_notification(true); 107 tray_delegate->set_should_show_display_notification(true);
441 108
442 UpdateDisplay("400x400"); 109 UpdateDisplay("400x400");
443 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 110 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
444 display::Display::SetInternalDisplayId(display_manager->first_display_id()); 111 display::Display::SetInternalDisplayId(display_manager->first_display_id());
445 EXPECT_TRUE(GetDisplayNotificationText().empty()); 112 EXPECT_TRUE(GetDisplayNotificationText().empty());
446 113
447 // rotation. 114 // rotation.
448 UpdateDisplay("400x400/r"); 115 UpdateDisplay("400x400/r");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 display::Display::SetInternalDisplayId( 201 display::Display::SetInternalDisplayId(
535 ScreenUtil::GetSecondaryDisplay().id()); 202 ScreenUtil::GetSecondaryDisplay().id());
536 UpdateDisplay("400x400@1.5"); 203 UpdateDisplay("400x400@1.5");
537 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), 204 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED),
538 GetDisplayNotificationText()); 205 GetDisplayNotificationText());
539 EXPECT_EQ(ash::SubstituteChromeOSDeviceType( 206 EXPECT_EQ(ash::SubstituteChromeOSDeviceType(
540 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), 207 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION),
541 GetDisplayNotificationAdditionalText()); 208 GetDisplayNotificationAdditionalText());
542 } 209 }
543 210
544 TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) { 211 // Verify that notification shows up when display is switched from dock mode to
212 // extend mode.
213 TEST_F(ScreenLayoutObserverTest, DisplayConfigurationChangedTwice) {
545 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); 214 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate();
546 tray_delegate->set_should_show_display_notification(true); 215 tray_delegate->set_should_show_display_notification(true);
547
548 UpdateDisplay("400x400,200x200"); 216 UpdateDisplay("400x400,200x200");
549 EXPECT_EQ(l10n_util::GetStringUTF16( 217 EXPECT_EQ(l10n_util::GetStringUTF16(
550 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), 218 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
551 GetDisplayNotificationText()); 219 GetDisplayNotificationText());
552 220
553 // OnDisplayConfigurationChanged() may be called more than once for a single 221 // OnDisplayConfigurationChanged() may be called more than once for a single
554 // update display in case of primary is swapped or recovered from dock mode. 222 // update display in case of primary is swapped or recovered from dock mode.
555 // Should not remove the notification in such case. 223 // Should not remove the notification in such case.
556 GetTrayDisplay()->OnDisplayConfigurationChanged(); 224 GetScreenLayoutObserver()->OnDisplayConfigurationChanged();
557 EXPECT_EQ(l10n_util::GetStringUTF16( 225 EXPECT_EQ(l10n_util::GetStringUTF16(
558 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), 226 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
559 GetDisplayNotificationText()); 227 GetDisplayNotificationText());
560 228
561 // Back to the single display. It SHOULD remove the notification since the 229 // Back to the single display. It SHOULD remove the notification since the
562 // information is stale. 230 // information is stale.
563 UpdateDisplay("400x400"); 231 UpdateDisplay("400x400");
564 EXPECT_TRUE(GetDisplayNotificationText().empty()); 232 EXPECT_TRUE(GetDisplayNotificationText().empty());
565 } 233 }
566 234
567 TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) { 235 // Verify the notification message content when one of the 2 displays that
236 // connected to the device is rotated.
237 TEST_F(ScreenLayoutObserverTest, UpdateAfterSuppressDisplayNotification) {
568 UpdateDisplay("400x400,200x200"); 238 UpdateDisplay("400x400,200x200");
569 239
570 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate(); 240 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate();
571 tray_delegate->set_should_show_display_notification(true); 241 tray_delegate->set_should_show_display_notification(true);
572 242
573 // rotate the second. 243 // rotate the second.
574 UpdateDisplay("400x400,200x200/r"); 244 UpdateDisplay("400x400,200x200/r");
575 EXPECT_EQ(l10n_util::GetStringFUTF16( 245 EXPECT_EQ(l10n_util::GetStringFUTF16(
576 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(), 246 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(),
577 l10n_util::GetStringUTF16( 247 l10n_util::GetStringUTF16(
578 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), 248 IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
579 GetDisplayNotificationAdditionalText()); 249 GetDisplayNotificationAdditionalText());
580 } 250 }
581 251
582 // Tests that when the only change is rotation, that it is only displayed when 252 // Verify that no notification is shown when overscan of a screen is changed.
583 // caused by user changes, and not by accelerometers. 253 TEST_F(ScreenLayoutObserverTest, OverscanDisplay) {
584 TEST_F(TrayDisplayTest, RotationOnInternalDisplay) { 254 UpdateDisplay("400x400, 300x300");
585 UpdateDisplay("400x400"); 255 test::TestSystemTrayDelegate* tray_delegate = GetSystemTrayDelegate();
256 tray_delegate->set_should_show_display_notification(true);
586 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 257 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
587 const int64_t display_id = display_manager->first_display_id(); 258 display::Display::SetInternalDisplayId(display_manager->first_display_id());
588 display::Display::SetInternalDisplayId(display_id);
589 259
590 GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); 260 // /o creates the default overscan.
591 EXPECT_FALSE(IsDisplayVisibleInTray()); 261 UpdateDisplay("400x400, 300x300/o");
262 EXPECT_TRUE(GetDisplayNotificationText().empty());
263 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
592 264
593 // Accelerometer change does not display. 265 // Reset the overscan.
594 display_manager->SetDisplayRotation( 266 Shell::GetInstance()->display_manager()->SetOverscanInsets(
595 display_id, display::Display::ROTATE_90, 267 ScreenUtil::GetSecondaryDisplay().id(), gfx::Insets());
596 display::Display::ROTATION_SOURCE_ACCELEROMETER); 268 EXPECT_TRUE(GetDisplayNotificationText().empty());
597 EXPECT_FALSE(IsDisplayVisibleInTray()); 269 EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
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 } 270 }
616 271
617 } // namespace ash 272 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/screen_layout_observer.cc ('k') | ash/system/chromeos/tray_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698