forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen_layout_observer_unittest.cc
728 lines (625 loc) · 29 KB
/
screen_layout_observer_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/screen_layout_observer.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/web_notification/web_notification_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/devicetype_utils.h"
#include "ui/display/display.h"
#include "ui/display/display_layout_builder.h"
#include "ui/display/display_switches.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/manager/display_manager_utilities.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification_list.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/views/controls/label.h"
namespace ash {
class ScreenLayoutObserverTest : public AshTestBase {
public:
ScreenLayoutObserverTest();
~ScreenLayoutObserverTest() override;
protected:
void SetUp() override {
AshTestBase::SetUp();
WebNotificationTray::DisableAnimationsForTest(true);
}
void TearDown() override {
WebNotificationTray::DisableAnimationsForTest(false);
AshTestBase::TearDown();
}
ScreenLayoutObserver* GetScreenLayoutObserver();
void CheckUpdate();
void CloseNotification();
void ClickNotification();
base::string16 GetDisplayNotificationText() const;
base::string16 GetDisplayNotificationAdditionalText() const;
base::string16 GetFirstDisplayName();
base::string16 GetSecondDisplayName();
base::string16 GetMirroringDisplayNames();
base::string16 GetUnifiedDisplayName();
private:
const message_center::Notification* GetDisplayNotification() const;
DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTest);
};
ScreenLayoutObserverTest::ScreenLayoutObserverTest() = default;
ScreenLayoutObserverTest::~ScreenLayoutObserverTest() = default;
ScreenLayoutObserver* ScreenLayoutObserverTest::GetScreenLayoutObserver() {
return Shell::Get()->screen_layout_observer();
}
void ScreenLayoutObserverTest::CloseNotification() {
message_center::MessageCenter::Get()->RemoveNotification(
ScreenLayoutObserver::kNotificationId, false);
RunAllPendingInMessageLoop();
}
void ScreenLayoutObserverTest::ClickNotification() {
const message_center::Notification* notification = GetDisplayNotification();
notification->delegate()->Click(base::nullopt, base::nullopt);
}
base::string16 ScreenLayoutObserverTest::GetDisplayNotificationText() const {
const message_center::Notification* notification = GetDisplayNotification();
return notification ? notification->title() : base::string16();
}
base::string16 ScreenLayoutObserverTest::GetDisplayNotificationAdditionalText()
const {
const message_center::Notification* notification = GetDisplayNotification();
return notification ? notification->message() : base::string16();
}
base::string16 ScreenLayoutObserverTest::GetFirstDisplayName() {
return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(
display_manager()->first_display_id()));
}
base::string16 ScreenLayoutObserverTest::GetSecondDisplayName() {
return base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(
display_manager()->GetSecondaryDisplay().id()));
}
base::string16 ScreenLayoutObserverTest::GetMirroringDisplayNames() {
DCHECK(display_manager()->IsInMirrorMode());
base::string16 display_names;
for (auto& id : display_manager()->GetMirroringDestinationDisplayIdList()) {
if (!display_names.empty())
display_names.append(base::UTF8ToUTF16(","));
display_names.append(
base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(id)));
}
return display_names;
}
base::string16 ScreenLayoutObserverTest::GetUnifiedDisplayName() {
return base::UTF8ToUTF16(
display_manager()->GetDisplayNameForId(display::kUnifiedDisplayId));
}
const message_center::Notification*
ScreenLayoutObserverTest::GetDisplayNotification() const {
const message_center::NotificationList::Notifications notifications =
message_center::MessageCenter::Get()->GetVisibleNotifications();
for (const auto* notification : notifications) {
if (notification->id() == ScreenLayoutObserver::kNotificationId)
return notification;
}
return nullptr;
}
class ScreenLayoutObserverTestMultiMirroring
: public ScreenLayoutObserverTest,
public testing::WithParamInterface<bool> {
public:
ScreenLayoutObserverTestMultiMirroring() = default;
~ScreenLayoutObserverTestMultiMirroring() override = default;
protected:
void SetUp() override {
bool should_disable_multi_mirroring = GetParam();
if (should_disable_multi_mirroring) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kDisableMultiMirroring);
}
ScreenLayoutObserverTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(ScreenLayoutObserverTestMultiMirroring);
};
// Instantiate the boolean which is used to enable/disable multi-mirroring in
// the parameterized tests.
INSTANTIATE_TEST_CASE_P(,
ScreenLayoutObserverTestMultiMirroring,
testing::Bool());
TEST_P(ScreenLayoutObserverTestMultiMirroring, DisplayNotifications) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400");
display::Display::SetInternalDisplayId(display_manager()->first_display_id());
EXPECT_TRUE(GetDisplayNotificationText().empty());
// rotation.
UpdateDisplay("400x400/r");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
GetDisplayNotificationAdditionalText());
EXPECT_TRUE(GetDisplayNotificationText().empty());
CloseNotification();
UpdateDisplay("400x400");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION)),
GetDisplayNotificationAdditionalText());
EXPECT_TRUE(GetDisplayNotificationText().empty());
// UI-scale
CloseNotification();
UpdateDisplay("400x400@1.5");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
GetFirstDisplayName(), base::UTF8ToUTF16("600x600")),
GetDisplayNotificationAdditionalText());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TITLE),
GetDisplayNotificationText());
// UI-scale to 1.0
CloseNotification();
UpdateDisplay("400x400");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
GetFirstDisplayName(), base::UTF8ToUTF16("400x400")),
GetDisplayNotificationAdditionalText());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TITLE),
GetDisplayNotificationText());
// No-update
CloseNotification();
UpdateDisplay("400x400");
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Extended.
CloseNotification();
UpdateDisplay("400x400,200x200");
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
GetSecondDisplayName()),
GetDisplayNotificationText());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
const int64_t first_display_id =
display::Screen::GetScreen()->GetPrimaryDisplay().id();
const int64_t second_display_id = first_display_id + 1;
display::ManagedDisplayInfo first_display_info =
display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 500, 500));
display::ManagedDisplayInfo second_display_info =
display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 500, 500));
std::vector<display::ManagedDisplayInfo> display_info_list;
display_info_list.emplace_back(first_display_info);
display_info_list.emplace_back(second_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
// Turn on mirror mode.
CloseNotification();
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Disconnect a display to end mirror mode.
CloseNotification();
display_info_list.erase(display_info_list.end() - 1);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Restore mirror mode.
CloseNotification();
display_info_list.emplace_back(second_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Turn off mirror mode.
CloseNotification();
display_manager()->SetMirrorMode(display::MirrorMode::kOff, base::nullopt);
if (display_manager()->is_multi_mirroring_enabled()) {
EXPECT_EQ(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
} else {
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
GetSecondDisplayName()),
GetDisplayNotificationText());
}
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Resize the first display.
UpdateDisplay("400x400@1.5,200x200");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
GetFirstDisplayName(), base::UTF8ToUTF16("600x600")),
GetDisplayNotificationAdditionalText());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TITLE),
GetDisplayNotificationText());
// Rotate the second.
UpdateDisplay("400x400@1.5,200x200/r");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
GetDisplayNotificationAdditionalText());
EXPECT_TRUE(GetDisplayNotificationText().empty());
// Enters closed lid mode.
UpdateDisplay("400x400@1.5,200x200");
display::Display::SetInternalDisplayId(
display_manager()->GetSecondaryDisplay().id());
UpdateDisplay("400x400@1.5");
EXPECT_TRUE(GetDisplayNotificationText().empty());
}
// Zooming in Unified Mode results in display size changes rather than changes
// in the UI scales, in which case, we still want to show a notification when
// the source of change is not the settings ui.
TEST_F(ScreenLayoutObserverTest, ZoomingInUnifiedModeNotification) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
// Enter unified mode.
display_manager()->SetUnifiedDesktopEnabled(true);
// Using keyboard shortcuts to change the zoom should result in a
// notification.
CloseNotification();
EXPECT_TRUE(display_manager()->ZoomInternalDisplay(false /* up */));
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
GetUnifiedDisplayName(), base::UTF8ToUTF16("400x200")),
GetDisplayNotificationAdditionalText());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TITLE),
GetDisplayNotificationText());
CloseNotification();
EXPECT_TRUE(display_manager()->ZoomInternalDisplay(true /* up */));
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
GetUnifiedDisplayName(), base::UTF8ToUTF16("800x400")),
GetDisplayNotificationAdditionalText());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TITLE),
GetDisplayNotificationText());
// However, when the source is the settings UI, the ScreenLayoutObserver does
// not produce a notification for resolution changes in Unified Mode. These
// are handled by the ResolutionNotificationController instead.
CloseNotification();
Shell::Get()->screen_layout_observer()->SetDisplayChangedFromSettingsUI(
display::kUnifiedDisplayId);
EXPECT_TRUE(display_manager()->ZoomInternalDisplay(false /* up */));
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
EXPECT_TRUE(GetDisplayNotificationText().empty());
}
// Verify that notification shows up when display is switched from dock mode to
// extend mode.
TEST_F(ScreenLayoutObserverTest, DisplayConfigurationChangedTwice) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
GetDisplayNotificationText());
// OnDisplayConfigurationChanged() may be called more than once for a single
// update display in case of primary is swapped or recovered from dock mode.
// Should not remove the notification in such case.
GetScreenLayoutObserver()->OnDisplayConfigurationChanged();
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
GetDisplayNotificationText());
// Back to the single display. It should show that a display was removed.
UpdateDisplay("400x400");
EXPECT_TRUE(base::StartsWith(
GetDisplayNotificationText(),
l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
base::UTF8ToUTF16("")),
base::CompareCase::SENSITIVE));
}
// Verify the notification message content when one of the 2 displays that
// connected to the device is rotated.
TEST_F(ScreenLayoutObserverTest, UpdateAfterSuppressDisplayNotification) {
UpdateDisplay("400x400,200x200");
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
// Rotate the second.
UpdateDisplay("400x400,200x200/r");
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetSecondDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
GetDisplayNotificationAdditionalText());
}
// Verify that no notification is shown when overscan of a screen is changed.
TEST_F(ScreenLayoutObserverTest, OverscanDisplay) {
UpdateDisplay("400x400, 300x300");
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
display::Display::SetInternalDisplayId(display_manager()->first_display_id());
// /o creates the default overscan.
UpdateDisplay("400x400, 300x300/o");
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// Reset the overscan.
Shell::Get()->display_manager()->SetOverscanInsets(
display_manager()->GetSecondaryDisplay().id(), gfx::Insets());
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
}
// Tests that exiting mirror mode by closing the lid shows the correct "exiting
// mirror mode" message.
TEST_F(ScreenLayoutObserverTest, ExitMirrorModeBecauseOfDockedModeMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
display::Display::SetInternalDisplayId(
display_manager()->GetSecondaryDisplay().id());
// Mirroring.
UpdateDisplay("400x400,200x200");
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Docked.
CloseNotification();
display::Display::SetInternalDisplayId(display_manager()->first_display_id());
UpdateDisplay("200x200");
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
}
// TODO(crbug.com/774795) Remove this test when multi mirroring is enabled by
// default.
// Tests that exiting mirror mode because of adding a third display shows the
// correct "3+ displays mirror mode is not supported" message.
TEST_P(ScreenLayoutObserverTestMultiMirroring,
ExitMirrorModeBecauseOfThirdDisplayMessage) {
if (display_manager()->is_multi_mirroring_enabled()) {
// This test is not neccessary when mirroring across 3+ displays is
// supported.
return;
}
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
display::Display::SetInternalDisplayId(
display_manager()->GetSecondaryDisplay().id());
// Mirroring.
UpdateDisplay("400x400,200x200");
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Adding a third display. Mirror mode for 3+ displays is not supported.
CloseNotification();
UpdateDisplay("400x400,200x200,100x100");
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED),
GetDisplayNotificationText());
}
// Special case: tests that exiting mirror mode by removing a display shows the
// correct message.
TEST_F(ScreenLayoutObserverTest,
ExitMirrorModeNoInternalDisplayBecauseOfDisplayRemovedMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
display::Display::SetInternalDisplayId(
display_manager()->GetSecondaryDisplay().id());
// Mirroring.
UpdateDisplay("400x400,200x200");
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Removing one of the displays. We show that we exited mirror mode.
CloseNotification();
UpdateDisplay("400x400");
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
}
// Tests notification messages shown when adding and removing displays in
// extended mode.
TEST_F(ScreenLayoutObserverTest, AddingRemovingDisplayExtendedModeMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400");
EXPECT_TRUE(GetDisplayNotificationText().empty());
// Adding a display in extended mode.
UpdateDisplay("400x400,200x200");
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
GetDisplayNotificationText());
// Removing a display.
CloseNotification();
UpdateDisplay("400x400");
EXPECT_TRUE(base::StartsWith(
GetDisplayNotificationText(),
l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_REMOVED,
base::UTF8ToUTF16("")),
base::CompareCase::SENSITIVE));
}
// Tests notification messages shown when entering and exiting unified desktop
// mode.
TEST_F(ScreenLayoutObserverTest, EnteringExitingUnifiedModeMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400");
EXPECT_TRUE(GetDisplayNotificationText().empty());
// Adding a display in extended mode.
UpdateDisplay("400x400,200x200");
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
GetDisplayNotificationText());
// Enter unified mode.
display_manager()->SetUnifiedDesktopEnabled(true);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
GetDisplayNotificationText());
// Exit unified mode.
display_manager()->SetUnifiedDesktopEnabled(false);
EXPECT_EQ(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
GetDisplayNotificationText());
// Enter unified mode again and exit via closing the lid. The message "Exiting
// unified mode" should be shown.
display_manager()->SetUnifiedDesktopEnabled(true);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED),
GetDisplayNotificationText());
// Close the lid.
display::Display::SetInternalDisplayId(display_manager()->first_display_id());
UpdateDisplay("200x200");
display_manager()->SetUnifiedDesktopEnabled(false);
EXPECT_EQ(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED_EXITING),
GetDisplayNotificationText());
}
// Special case: Tests notification messages shown when entering docked mode
// by closing the lid and the internal display is the secondary display.
TEST_F(ScreenLayoutObserverTest, DockedModeWithExternalPrimaryDisplayMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400,200x200");
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL),
GetDisplayNotificationText());
CloseNotification();
const int64_t primary_id = display_manager()->GetDisplayAt(0).id();
const int64_t internal_secondary_id = display_manager()->GetDisplayAt(1).id();
display::Display::SetInternalDisplayId(internal_secondary_id);
display::DisplayLayoutBuilder builder(primary_id);
builder.AddDisplayPlacement(internal_secondary_id, primary_id,
display::DisplayPlacement::LEFT, 0);
display_manager()->SetLayoutForCurrentDisplays(builder.Build());
EXPECT_TRUE(GetDisplayNotificationText().empty());
// Close the lid. We go to docked mode, but we show no notifications.
UpdateDisplay("400x400");
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
}
// Tests that rotation notifications are only shown when the rotation source is
// a user action. The accelerometer source nevber produces any notifications.
TEST_F(ScreenLayoutObserverTest, RotationNotification) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
UpdateDisplay("400x400");
const int64_t primary_id =
display_manager()->GetPrimaryDisplayCandidate().id();
// The accelerometer source.
display_manager()->SetDisplayRotation(
primary_id, display::Display::ROTATE_90,
display::Display::RotationSource::ACCELEROMETER);
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
// The user source.
display_manager()->SetDisplayRotation(primary_id,
display::Display::ROTATE_180,
display::Display::RotationSource::USER);
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_180)),
GetDisplayNotificationAdditionalText());
// The active source.
display_manager()->SetDisplayRotation(
primary_id, display::Display::ROTATE_270,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_270)),
GetDisplayNotificationAdditionalText());
// Switch to Tablet
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// The accelerometer source.
display_manager()->SetDisplayRotation(
primary_id, display::Display::ROTATE_90,
display::Display::RotationSource::ACCELEROMETER);
EXPECT_TRUE(GetDisplayNotificationText().empty());
// The user source.
display_manager()->SetDisplayRotation(primary_id,
display::Display::ROTATE_180,
display::Display::RotationSource::USER);
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_180)),
GetDisplayNotificationAdditionalText());
// The active source.
display_manager()->SetDisplayRotation(
primary_id, display::Display::ROTATE_270,
display::Display::RotationSource::ACTIVE);
EXPECT_TRUE(GetDisplayNotificationText().empty());
}
TEST_F(ScreenLayoutObserverTest, MirrorModeAddOrRemoveDisplayMessage) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
const int64_t internal_display_id =
display::test::DisplayManagerTestApi(display_manager())
.SetFirstDisplayAsInternalDisplay();
constexpr int first_display_id = 11;
constexpr int second_display_id = 12;
display::ManagedDisplayInfo first_display_info =
display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 500, 500));
display::ManagedDisplayInfo second_display_info =
display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 500, 500));
std::vector<display::ManagedDisplayInfo> display_info_list;
display_info_list.push_back(display::CreateDisplayInfo(
internal_display_id, gfx::Rect(0, 0, 100, 100)));
display_info_list.push_back(first_display_info);
display_info_list.push_back(second_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
// Mirroring across 3 displays.
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Mirror mode persists when a display is removed.
CloseNotification();
display_info_list.erase(display_info_list.end() - 1);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(display_manager()->IsInMirrorMode());
// Turn off mirror mode.
CloseNotification();
display_manager()->SetMirrorMode(display::MirrorMode::kOff, base::nullopt);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
// Turn on mirror mode.
CloseNotification();
display_manager()->SetMirrorMode(display::MirrorMode::kNormal, base::nullopt);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Mirror mode ends when only one display is left.
CloseNotification();
display_info_list.erase(display_info_list.end() - 1);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRROR_EXIT),
GetDisplayNotificationText());
// Mirror mode is restored when the display is reconncted.
CloseNotification();
display_info_list.push_back(first_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
GetMirroringDisplayNames()),
GetDisplayNotificationText());
// Add the other display, the mirror mode persists.
CloseNotification();
display_info_list.push_back(second_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_TRUE(GetDisplayNotificationText().empty());
EXPECT_TRUE(display_manager()->IsInMirrorMode());
}
TEST_F(ScreenLayoutObserverTest, ClickNotification) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);
// Create notification.
UpdateDisplay("400x400/r");
EXPECT_FALSE(GetDisplayNotificationAdditionalText().empty());
// Click notification.
ClickNotification();
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
}
} // namespace ash