forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccelerator_controller_unittest.cc
2851 lines (2473 loc) · 118 KB
/
accelerator_controller_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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012 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/accelerators/accelerator_controller_impl.h"
#include <utility>
#include "ash/accelerators/accelerator_confirmation_dialog.h"
#include "ash/accelerators/accelerator_history_impl.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/accelerators/pre_target_accelerator_handler.h"
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/accessibility/test_accessibility_controller_client.h"
#include "ash/app_list/app_list_metrics.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/ime/ime_controller_impl.h"
#include "ash/ime/mode_indicator_observer.h"
#include "ash/ime/test_ime_controller_client.h"
#include "ash/magnifier/docked_magnifier_controller_impl.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/capture_mode_test_api.h"
#include "ash/public/cpp/ime_info.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/test/shell_test_api.h"
#include "ash/session/session_controller_impl.h"
#include "ash/session/test_session_controller_client.h"
#include "ash/shell.h"
#include "ash/system/brightness_control_delegate.h"
#include "ash/system/keyboard_brightness_control_delegate.h"
#include "ash/system/power/power_button_controller_test_api.h"
#include "ash/test/ash_test_base.h"
#include "ash/test_media_client.h"
#include "ash/test_screenshot_delegate.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_item.h"
#include "ash/wm/overview/overview_test_util.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/test_session_state_animator.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_writer.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/test/test_media_controller.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/base/accelerators/media_keys_util.h"
#include "ui/base/accelerators/test_accelerator_target.h"
#include "ui/base/ime/chromeos/fake_ime_keyboard.h"
#include "ui/base/ime/chromeos/ime_keyboard.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager_test_api.h"
#include "ui/events/event.h"
#include "ui/events/event_sink.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/test/event_generator.h"
#include "ui/message_center/message_center.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/accelerator_filter.h"
namespace ash {
using ::chromeos::WindowStateType;
using media_session::mojom::MediaSessionAction;
namespace {
struct PrefToAcceleratorEntry {
const char* pref_name;
// If |notification_id| has been set to nullptr, then no notification is
// expected.
const char* notification_id;
const char* histogram_id;
const ui::Accelerator accelerator;
};
const PrefToAcceleratorEntry kAccessibilityAcceleratorMap[] = {
{
prefs::kAccessibilityHighContrastEnabled,
kHighContrastToggleAccelNotificationId,
kAccessibilityHighContrastShortcut,
ui::Accelerator(ui::VKEY_H, ui::EF_COMMAND_DOWN | ui::EF_CONTROL_DOWN),
},
{prefs::kDockedMagnifierEnabled, kDockedMagnifierToggleAccelNotificationId,
kAccessibilityDockedMagnifierShortcut,
ui::Accelerator(ui::VKEY_D, ui::EF_COMMAND_DOWN | ui::EF_CONTROL_DOWN)},
{
prefs::kAccessibilitySpokenFeedbackEnabled,
nullptr,
kAccessibilitySpokenFeedbackShortcut,
ui::Accelerator(ui::VKEY_Z, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN),
},
{prefs::kAccessibilityScreenMagnifierEnabled,
kFullscreenMagnifierToggleAccelNotificationId,
kAccessibilityScreenMagnifierShortcut,
ui::Accelerator(ui::VKEY_M, ui::EF_COMMAND_DOWN | ui::EF_CONTROL_DOWN)},
};
void AddTestImes() {
ImeInfo ime1;
ime1.id = "id1";
ImeInfo ime2;
ime2.id = "id2";
std::vector<ImeInfo> available_imes;
available_imes.push_back(std::move(ime1));
available_imes.push_back(std::move(ime2));
Shell::Get()->ime_controller()->RefreshIme("id1", std::move(available_imes),
std::vector<ImeMenuItem>());
}
ui::Accelerator CreateReleaseAccelerator(ui::KeyboardCode key_code,
int modifiers) {
ui::Accelerator accelerator(key_code, modifiers);
accelerator.set_key_state(ui::Accelerator::KeyState::RELEASED);
return accelerator;
}
class DummyBrightnessControlDelegate : public BrightnessControlDelegate {
public:
DummyBrightnessControlDelegate()
: handle_brightness_down_count_(0), handle_brightness_up_count_(0) {}
~DummyBrightnessControlDelegate() override = default;
void HandleBrightnessDown(const ui::Accelerator& accelerator) override {
++handle_brightness_down_count_;
last_accelerator_ = accelerator;
}
void HandleBrightnessUp(const ui::Accelerator& accelerator) override {
++handle_brightness_up_count_;
last_accelerator_ = accelerator;
}
void SetBrightnessPercent(double percent, bool gradual) override {}
void GetBrightnessPercent(
base::OnceCallback<void(base::Optional<double>)> callback) override {
std::move(callback).Run(100.0);
}
int handle_brightness_down_count() const {
return handle_brightness_down_count_;
}
int handle_brightness_up_count() const { return handle_brightness_up_count_; }
const ui::Accelerator& last_accelerator() const { return last_accelerator_; }
private:
int handle_brightness_down_count_;
int handle_brightness_up_count_;
ui::Accelerator last_accelerator_;
DISALLOW_COPY_AND_ASSIGN(DummyBrightnessControlDelegate);
};
class DummyKeyboardBrightnessControlDelegate
: public KeyboardBrightnessControlDelegate {
public:
DummyKeyboardBrightnessControlDelegate()
: handle_keyboard_brightness_down_count_(0),
handle_keyboard_brightness_up_count_(0) {}
~DummyKeyboardBrightnessControlDelegate() override = default;
void HandleKeyboardBrightnessDown(
const ui::Accelerator& accelerator) override {
++handle_keyboard_brightness_down_count_;
last_accelerator_ = accelerator;
}
void HandleKeyboardBrightnessUp(const ui::Accelerator& accelerator) override {
++handle_keyboard_brightness_up_count_;
last_accelerator_ = accelerator;
}
int handle_keyboard_brightness_down_count() const {
return handle_keyboard_brightness_down_count_;
}
int handle_keyboard_brightness_up_count() const {
return handle_keyboard_brightness_up_count_;
}
const ui::Accelerator& last_accelerator() const { return last_accelerator_; }
private:
int handle_keyboard_brightness_down_count_;
int handle_keyboard_brightness_up_count_;
ui::Accelerator last_accelerator_;
DISALLOW_COPY_AND_ASSIGN(DummyKeyboardBrightnessControlDelegate);
};
} // namespace
class AcceleratorControllerTest : public AshTestBase {
public:
AcceleratorControllerTest() = default;
~AcceleratorControllerTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
controller_ = Shell::Get()->accelerator_controller();
test_api_ =
std::make_unique<AcceleratorControllerImpl::TestApi>(controller_);
}
protected:
static bool ProcessInController(const ui::Accelerator& accelerator) {
AcceleratorControllerImpl* controller =
Shell::Get()->accelerator_controller();
if (accelerator.key_state() == ui::Accelerator::KeyState::RELEASED) {
// If the |accelerator| should trigger on release, then we store the
// pressed version of it first in history then the released one to
// simulate what happens in reality.
ui::Accelerator pressed_accelerator = accelerator;
pressed_accelerator.set_key_state(ui::Accelerator::KeyState::PRESSED);
controller->accelerator_history()->StoreCurrentAccelerator(
pressed_accelerator);
}
controller->accelerator_history()->StoreCurrentAccelerator(accelerator);
return controller->Process(accelerator);
}
bool ContainsHighContrastNotification() const {
return nullptr != message_center()->FindVisibleNotificationById(
kHighContrastToggleAccelNotificationId);
}
bool ContainsDockedMagnifierNotification() const {
return nullptr != message_center()->FindVisibleNotificationById(
kDockedMagnifierToggleAccelNotificationId);
}
bool ContainsFullscreenMagnifierNotification() const {
return nullptr != message_center()->FindVisibleNotificationById(
kFullscreenMagnifierToggleAccelNotificationId);
}
bool IsConfirmationDialogOpen() {
return !!(test_api_->GetConfirmationDialog());
}
void AcceptConfirmationDialog() {
DCHECK(test_api_->GetConfirmationDialog());
test_api_->GetConfirmationDialog()->AcceptDialog();
}
void CancelConfirmationDialog() {
DCHECK(test_api_->GetConfirmationDialog());
test_api_->GetConfirmationDialog()->CancelDialog();
}
void TriggerRotateScreenShortcut() {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
if (IsConfirmationDialogOpen()) {
AcceptConfirmationDialog();
base::RunLoop().RunUntilIdle();
}
}
void RemoveAllNotifications() const {
message_center()->RemoveAllNotifications(
false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
}
static const ui::Accelerator& GetPreviousAccelerator() {
return Shell::Get()
->accelerator_controller()
->accelerator_history()
->previous_accelerator();
}
static const ui::Accelerator& GetCurrentAccelerator() {
return Shell::Get()
->accelerator_controller()
->accelerator_history()
->current_accelerator();
}
// Several functions to access ExitWarningHandler (as friend).
static void StubForTest(ExitWarningHandler* ewh) {
ewh->stub_timer_for_test_ = true;
}
static void Reset(ExitWarningHandler* ewh) {
ewh->state_ = ExitWarningHandler::IDLE;
}
static void SimulateTimerExpired(ExitWarningHandler* ewh) {
ewh->TimerAction();
}
static bool is_ui_shown(ExitWarningHandler* ewh) { return !!ewh->widget_; }
static bool is_idle(ExitWarningHandler* ewh) {
return ewh->state_ == ExitWarningHandler::IDLE;
}
static bool is_exiting(ExitWarningHandler* ewh) {
return ewh->state_ == ExitWarningHandler::EXITING;
}
message_center::MessageCenter* message_center() const {
return message_center::MessageCenter::Get();
}
void SetBrightnessControlDelegate(
std::unique_ptr<BrightnessControlDelegate> delegate) {
Shell::Get()->brightness_control_delegate_ = std::move(delegate);
}
void SetKeyboardBrightnessControlDelegate(
std::unique_ptr<KeyboardBrightnessControlDelegate> delegate) {
Shell::Get()->keyboard_brightness_control_delegate_ = std::move(delegate);
}
bool WriteJsonFile(const base::FilePath& file_path,
const std::string& json_string) const {
if (!base::DirectoryExists(file_path.DirName()))
base::CreateDirectory(file_path.DirName());
int data_size = static_cast<int>(json_string.size());
int bytes_written =
base::WriteFile(file_path, json_string.data(), data_size);
if (bytes_written != data_size) {
LOG(ERROR) << " Wrote " << bytes_written << " byte(s) instead of "
<< data_size << " to " << file_path.value();
return false;
}
return true;
}
AcceleratorControllerImpl* controller_ = nullptr; // Not owned.
std::unique_ptr<AcceleratorControllerImpl::TestApi> test_api_;
private:
DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
};
// Double press of exit shortcut => exiting
TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) {
ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
ui::Accelerator release(press);
release.set_key_state(ui::Accelerator::KeyState::RELEASED);
ExitWarningHandler* ewh = controller_->GetExitWarningHandlerForTest();
ASSERT_TRUE(ewh);
StubForTest(ewh);
EXPECT_TRUE(is_idle(ewh));
EXPECT_FALSE(is_ui_shown(ewh));
EXPECT_TRUE(ProcessInController(press));
EXPECT_FALSE(ProcessInController(release));
EXPECT_FALSE(is_idle(ewh));
EXPECT_TRUE(is_ui_shown(ewh));
EXPECT_TRUE(ProcessInController(press)); // second press before timer.
EXPECT_FALSE(ProcessInController(release));
SimulateTimerExpired(ewh);
EXPECT_TRUE(is_exiting(ewh));
EXPECT_FALSE(is_ui_shown(ewh));
Reset(ewh);
}
// Single press of exit shortcut before timer => idle
TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestSinglePress) {
ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
ui::Accelerator release(press);
release.set_key_state(ui::Accelerator::KeyState::RELEASED);
ExitWarningHandler* ewh = controller_->GetExitWarningHandlerForTest();
ASSERT_TRUE(ewh);
StubForTest(ewh);
EXPECT_TRUE(is_idle(ewh));
EXPECT_FALSE(is_ui_shown(ewh));
EXPECT_TRUE(ProcessInController(press));
EXPECT_FALSE(ProcessInController(release));
EXPECT_FALSE(is_idle(ewh));
EXPECT_TRUE(is_ui_shown(ewh));
SimulateTimerExpired(ewh);
EXPECT_TRUE(is_idle(ewh));
EXPECT_FALSE(is_ui_shown(ewh));
Reset(ewh);
}
// Shutdown ash with exit warning bubble open should not crash.
TEST_F(AcceleratorControllerTest, LingeringExitWarningBubble) {
ExitWarningHandler* ewh = controller_->GetExitWarningHandlerForTest();
ASSERT_TRUE(ewh);
StubForTest(ewh);
// Trigger once to show the bubble.
ewh->HandleAccelerator();
EXPECT_FALSE(is_idle(ewh));
EXPECT_TRUE(is_ui_shown(ewh));
// Exit ash and there should be no crash
}
TEST_F(AcceleratorControllerTest, Register) {
ui::TestAcceleratorTarget target;
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
const ui::Accelerator accelerator_d(ui::VKEY_D, ui::EF_NONE);
controller_->Register(
{accelerator_a, accelerator_b, accelerator_c, accelerator_d}, &target);
// The registered accelerators are processed.
EXPECT_TRUE(ProcessInController(accelerator_a));
EXPECT_TRUE(ProcessInController(accelerator_b));
EXPECT_TRUE(ProcessInController(accelerator_c));
EXPECT_TRUE(ProcessInController(accelerator_d));
EXPECT_EQ(4, target.accelerator_count());
}
TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
ui::TestAcceleratorTarget target1;
controller_->Register({accelerator_a}, &target1);
ui::TestAcceleratorTarget target2;
controller_->Register({accelerator_a}, &target2);
// If multiple targets are registered with the same accelerator, the target
// registered later processes the accelerator.
EXPECT_TRUE(ProcessInController(accelerator_a));
EXPECT_EQ(0, target1.accelerator_count());
EXPECT_EQ(1, target2.accelerator_count());
}
TEST_F(AcceleratorControllerTest, Unregister) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
ui::TestAcceleratorTarget target;
controller_->Register({accelerator_a, accelerator_b}, &target);
// Unregistering a different accelerator does not affect the other
// accelerator.
controller_->Unregister(accelerator_b, &target);
EXPECT_TRUE(ProcessInController(accelerator_a));
EXPECT_EQ(1, target.accelerator_count());
// The unregistered accelerator is no longer processed.
target.ResetCounts();
controller_->Unregister(accelerator_a, &target);
EXPECT_FALSE(ProcessInController(accelerator_a));
EXPECT_EQ(0, target.accelerator_count());
}
TEST_F(AcceleratorControllerTest, UnregisterAll) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
ui::TestAcceleratorTarget target1;
controller_->Register({accelerator_a, accelerator_b}, &target1);
const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
ui::TestAcceleratorTarget target2;
controller_->Register({accelerator_c}, &target2);
controller_->UnregisterAll(&target1);
// All the accelerators registered for |target1| are no longer processed.
EXPECT_FALSE(ProcessInController(accelerator_a));
EXPECT_FALSE(ProcessInController(accelerator_b));
EXPECT_EQ(0, target1.accelerator_count());
// UnregisterAll with a different target does not affect the other target.
EXPECT_TRUE(ProcessInController(accelerator_c));
EXPECT_EQ(1, target2.accelerator_count());
}
TEST_F(AcceleratorControllerTest, Process) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
ui::TestAcceleratorTarget target1;
controller_->Register({accelerator_a}, &target1);
// The registered accelerator is processed.
EXPECT_TRUE(ProcessInController(accelerator_a));
EXPECT_EQ(1, target1.accelerator_count());
// The non-registered accelerator is not processed.
const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
EXPECT_FALSE(ProcessInController(accelerator_b));
}
TEST_F(AcceleratorControllerTest, IsRegistered) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
ui::TestAcceleratorTarget target;
controller_->Register({accelerator_a}, &target);
EXPECT_TRUE(controller_->IsRegistered(accelerator_a));
EXPECT_FALSE(controller_->IsRegistered(accelerator_shift_a));
controller_->UnregisterAll(&target);
EXPECT_FALSE(controller_->IsRegistered(accelerator_a));
}
TEST_F(AcceleratorControllerTest, WindowSnap) {
std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
WindowState* window_state = WindowState::Get(window.get());
window_state->Activate();
{
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT, {});
gfx::Rect expected_bounds =
GetDefaultLeftSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
{
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT, {});
gfx::Rect expected_bounds =
GetDefaultRightSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
{
gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent();
controller_->PerformActionIfEnabled(TOGGLE_MAXIMIZED, {});
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString());
controller_->PerformActionIfEnabled(TOGGLE_MAXIMIZED, {});
EXPECT_FALSE(window_state->IsMaximized());
// Window gets restored to its restore bounds since side-maximized state
// is treated as a "maximized" state.
EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
controller_->PerformActionIfEnabled(TOGGLE_MAXIMIZED, {});
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT, {});
EXPECT_FALSE(window_state->IsMaximized());
controller_->PerformActionIfEnabled(TOGGLE_MAXIMIZED, {});
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT, {});
EXPECT_FALSE(window_state->IsMaximized());
controller_->PerformActionIfEnabled(TOGGLE_MAXIMIZED, {});
EXPECT_TRUE(window_state->IsMaximized());
controller_->PerformActionIfEnabled(WINDOW_MINIMIZE, {});
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_TRUE(window_state->IsMinimized());
window_state->Restore();
window_state->Activate();
}
{
controller_->PerformActionIfEnabled(WINDOW_MINIMIZE, {});
EXPECT_TRUE(window_state->IsMinimized());
}
}
// Tests that window snapping works.
TEST_F(AcceleratorControllerTest, TestRepeatedSnap) {
std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
WindowState* window_state = WindowState::Get(window.get());
window_state->Activate();
// Snap right.
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT, {});
gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent();
gfx::Rect expected_bounds =
GetDefaultRightSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
EXPECT_TRUE(window_state->IsSnapped());
// Snap right again ->> becomes normal.
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT, {});
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
// Snap right.
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT, {});
EXPECT_TRUE(window_state->IsSnapped());
// Snap left.
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT, {});
EXPECT_TRUE(window_state->IsSnapped());
expected_bounds = GetDefaultLeftSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
// Snap left again ->> becomes normal.
controller_->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT, {});
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
}
namespace {
class AcceleratorControllerTestWithClamshellSplitView
: public AcceleratorControllerTest {
public:
AcceleratorControllerTestWithClamshellSplitView() = default;
AcceleratorControllerTestWithClamshellSplitView(
const AcceleratorControllerTestWithClamshellSplitView&) = delete;
AcceleratorControllerTestWithClamshellSplitView& operator=(
const AcceleratorControllerTestWithClamshellSplitView&) = delete;
~AcceleratorControllerTestWithClamshellSplitView() override = default;
protected:
// Note: These functions assume the default display resolution 800x600.
void EnterOverviewAndDragToSnapLeft(aura::Window* window) {
EnterOverviewAndDragTo(window, gfx::Point(0, 300));
}
void EnterOverviewAndDragToSnapRight(aura::Window* window) {
EnterOverviewAndDragTo(window, gfx::Point(799, 300));
}
private:
void EnterOverviewAndDragTo(aura::Window* window,
const gfx::Point& destination) {
DCHECK(!Shell::Get()->overview_controller()->InOverviewSession());
ToggleOverview();
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(gfx::ToRoundedPoint(
GetOverviewItemForWindow(window)->target_bounds().CenterPoint()));
generator->DragMouseTo(destination);
}
};
TEST_F(AcceleratorControllerTestWithClamshellSplitView, WindowSnapUma) {
base::UserActionTester user_action_tester;
base::HistogramTester histogram_tester;
std::unique_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(10, 10, 20, 20)));
// Some test cases use clamshell split view, for which we need a second window
// so overview will be nonempty. Otherwise split view will end when it starts.
std::unique_ptr<aura::Window> window2(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
base::HistogramBase::Count left_clamshell_no_overview = 0;
base::HistogramBase::Count left_clamshell_overview = 0;
base::HistogramBase::Count left_tablet = 0;
base::HistogramBase::Count right_clamshell_no_overview = 0;
base::HistogramBase::Count right_clamshell_overview = 0;
base::HistogramBase::Count right_tablet = 0;
// Performs |action|, checks that |window1| is in |target_window1_state_type|,
// and verifies metrics. Output of failed expectations includes |description|.
const auto test = [&](const char* description, AcceleratorAction action,
WindowStateType target_window1_state_type) {
SCOPED_TRACE(description);
controller_->PerformActionIfEnabled(action, {});
EXPECT_EQ(target_window1_state_type,
WindowState::Get(window1.get())->GetStateType());
EXPECT_EQ(
left_clamshell_no_overview + left_clamshell_overview + left_tablet,
user_action_tester.GetActionCount("Accel_Window_Snap_Left"));
EXPECT_EQ(
right_clamshell_no_overview + right_clamshell_overview + right_tablet,
user_action_tester.GetActionCount("Accel_Window_Snap_Right"));
histogram_tester.ExpectBucketCount(
kAccelWindowSnap,
WindowSnapAcceleratorAction::kCycleLeftSnapInClamshellNoOverview,
left_clamshell_no_overview);
histogram_tester.ExpectBucketCount(
kAccelWindowSnap,
WindowSnapAcceleratorAction::kCycleLeftSnapInClamshellOverview,
left_clamshell_overview);
histogram_tester.ExpectBucketCount(
kAccelWindowSnap, WindowSnapAcceleratorAction::kCycleLeftSnapInTablet,
left_tablet);
histogram_tester.ExpectBucketCount(
kAccelWindowSnap,
WindowSnapAcceleratorAction::kCycleRightSnapInClamshellNoOverview,
right_clamshell_no_overview);
histogram_tester.ExpectBucketCount(
kAccelWindowSnap,
WindowSnapAcceleratorAction::kCycleRightSnapInClamshellOverview,
right_clamshell_overview);
histogram_tester.ExpectBucketCount(
kAccelWindowSnap, WindowSnapAcceleratorAction::kCycleRightSnapInTablet,
right_tablet);
};
// Alt+[, clamshell, no overview
wm::ActivateWindow(window1.get());
left_clamshell_no_overview = 1;
test("Snap left, clamshell, no overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kLeftSnapped);
left_clamshell_no_overview = 2;
test("Unsnap left, clamshell, no overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kNormal);
// Alt+[, clamshell, overview
EnterOverviewAndDragToSnapRight(window1.get());
left_clamshell_overview = 1;
test("Snap left, clamshell, overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kLeftSnapped);
left_clamshell_overview = 2;
test("Unsnap left, clamshell, overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kNormal);
// Alt+], clamshell, no overview
right_clamshell_no_overview = 1;
test("Snap right, clamshell, no overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kRightSnapped);
right_clamshell_no_overview = 2;
test("Unsnap right, clamshell, no overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kNormal);
// Alt+], clamshell, overview
EnterOverviewAndDragToSnapLeft(window1.get());
right_clamshell_overview = 1;
test("Snap right, clamshell, overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kRightSnapped);
right_clamshell_overview = 2;
test("Unsnap right, clamshell, overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kNormal);
// Alt+[, tablet, no overview
ShellTestApi().SetTabletModeEnabledForTest(true);
left_tablet = 1;
test("Snap left, tablet, no overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kLeftSnapped);
ToggleOverview();
left_tablet = 2;
test("Unsnap left, tablet, no overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kMaximized);
// Alt+[, tablet, overview
EnterOverviewAndDragToSnapRight(window1.get());
left_tablet = 3;
test("Snap left, tablet, overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kLeftSnapped);
left_tablet = 4;
test("Unsnap left, tablet, overview", WINDOW_CYCLE_SNAP_LEFT,
WindowStateType::kMaximized);
// Alt+], tablet, no overview
right_tablet = 1;
test("Snap right, tablet, no overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kRightSnapped);
ToggleOverview();
right_tablet = 2;
test("Unsnap right, tablet, no overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kMaximized);
// Alt+], tablet, overview
EnterOverviewAndDragToSnapLeft(window1.get());
right_tablet = 3;
test("Snap right, tablet, overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kRightSnapped);
right_tablet = 4;
test("Unsnap right, tablet, overview", WINDOW_CYCLE_SNAP_RIGHT,
WindowStateType::kMaximized);
}
} // namespace
TEST_F(AcceleratorControllerTest, RotateScreen) {
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
display::Display::Rotation initial_rotation =
GetActiveDisplayRotation(display.id());
ui::test::EventGenerator* generator = GetEventGenerator();
AccessibilityControllerImpl* accessibility_controller =
Shell::Get()->accessibility_controller();
EXPECT_FALSE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
generator->PressKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
// Dialog should be open.
EXPECT_TRUE(IsConfirmationDialogOpen());
// Cancel on the dialog should have no effect.
CancelConfirmationDialog();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
display::Display::Rotation rotation_after_cancel =
GetActiveDisplayRotation(display.id());
// Screen rotation should not have been triggered.
EXPECT_EQ(initial_rotation, rotation_after_cancel);
// Use short cut again.
generator->PressKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
EXPECT_TRUE(IsConfirmationDialogOpen());
AcceptConfirmationDialog();
base::RunLoop().RunUntilIdle();
// Dialog should be closed.
EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_TRUE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
display::Display::Rotation rotation_after_accept =
GetActiveDisplayRotation(display.id());
// |new_rotation| is determined by the AcceleratorController.
EXPECT_NE(initial_rotation, rotation_after_accept);
}
// Tests that using the keyboard shortcut to rotate the display while the device
// is in physical tablet state behaves like a request to lock the user
// orientation to the next rotation of the internal display, and disables auto-
// rotation.
TEST_F(AcceleratorControllerTest, RotateScreenInPhysicalTabletState) {
display::test::DisplayManagerTestApi(display_manager())
.SetFirstDisplayAsInternalDisplay();
ShellTestApi().SetTabletModeEnabledForTest(true);
auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
auto* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
EXPECT_TRUE(tablet_mode_controller->is_in_tablet_physical_state());
EXPECT_FALSE(screen_orientation_controller->user_rotation_locked());
EXPECT_FALSE(screen_orientation_controller->rotation_locked());
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
EXPECT_TRUE(screen_orientation_controller->user_rotation_locked());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_EQ(OrientationLockType::kPortraitSecondary,
screen_orientation_controller->GetCurrentOrientation());
// When the device is no longer used as a tablet, the original rotation will
// be restored.
ShellTestApi().SetTabletModeEnabledForTest(false);
EXPECT_FALSE(tablet_mode_controller->is_in_tablet_physical_state());
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
// User rotation lock remains in place to be restored again when the device
// goes to physical tablet state again.
EXPECT_TRUE(screen_orientation_controller->user_rotation_locked());
EXPECT_FALSE(screen_orientation_controller->rotation_locked());
}
// Tests the behavior of the shortcut when the active window requests to lock
// the rotation to a particular orientation.
TEST_F(AcceleratorControllerTest, RotateScreenWithWindowLockingOrientation) {
display::test::DisplayManagerTestApi(display_manager())
.SetFirstDisplayAsInternalDisplay();
ShellTestApi().SetTabletModeEnabledForTest(true);
auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
auto* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
EXPECT_TRUE(tablet_mode_controller->is_in_tablet_physical_state());
EXPECT_FALSE(screen_orientation_controller->user_rotation_locked());
auto win0 = CreateAppWindow(gfx::Rect{100, 300});
auto win1 = CreateAppWindow(gfx::Rect{200, 200});
screen_orientation_controller->LockOrientationForWindow(
win0.get(), OrientationLockType::kPortraitPrimary);
screen_orientation_controller->LockOrientationForWindow(
win1.get(), OrientationLockType::kLandscape);
// `win0` requests to lock the orientation to only portrait-primary. The
// shortcut therefore won't be able to change the current rotation at all.
wm::ActivateWindow(win0.get());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_FALSE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kPortraitPrimary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
// Nothing happens; user rotation is still not locked, but the rotation is
// app-locked.
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_FALSE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kPortraitPrimary,
screen_orientation_controller->GetCurrentOrientation());
// Activate `win1` which allows any landscape orientations (either primary or
// secondary). The shortcut will switch between the two allowed orientations
// only.
wm::ActivateWindow(win1.get());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_FALSE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
// User rotation will now be locked.
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kLandscapeSecondary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
// Hook a mouse device, exiting tablet mode to clamshell mode (but remaining
// in a tablet physical state). Expect that the shortcut changes the user
// rotation lock in all directions regardless of which window is active, even
// those that requested window rotation locks.
TabletModeControllerTestApi().AttachExternalMouse();
EXPECT_TRUE(tablet_mode_controller->is_in_tablet_physical_state());
EXPECT_FALSE(tablet_mode_controller->InTabletMode());
wm::ActivateWindow(win0.get());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(screen_orientation_controller->user_rotation_locked());
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
EXPECT_EQ(OrientationLockType::kPortraitSecondary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
EXPECT_EQ(OrientationLockType::kLandscapeSecondary,
screen_orientation_controller->GetCurrentOrientation());
wm::ActivateWindow(win1.get());
TriggerRotateScreenShortcut();
EXPECT_EQ(OrientationLockType::kPortraitPrimary,
screen_orientation_controller->GetCurrentOrientation());
TriggerRotateScreenShortcut();
EXPECT_EQ(OrientationLockType::kLandscapePrimary,
screen_orientation_controller->GetCurrentOrientation());
}
TEST_F(AcceleratorControllerTest, AutoRepeat) {
ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN);
ui::TestAcceleratorTarget target_a;
controller_->Register({accelerator_a}, &target_a);
ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN);
ui::TestAcceleratorTarget target_b;
controller_->Register({accelerator_b}, &target_b);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
generator->ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
EXPECT_EQ(1, target_a.accelerator_count());
EXPECT_EQ(0, target_a.accelerator_repeat_count());
// Long press should generate one
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT);
EXPECT_EQ(2, target_a.accelerator_non_repeat_count());
EXPECT_EQ(1, target_a.accelerator_repeat_count());
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT);
EXPECT_EQ(2, target_a.accelerator_non_repeat_count());
EXPECT_EQ(2, target_a.accelerator_repeat_count());
generator->ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
EXPECT_EQ(2, target_a.accelerator_non_repeat_count());
EXPECT_EQ(2, target_a.accelerator_repeat_count());
// Long press was intercepted by another key press.
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT);
generator->PressKey(ui::VKEY_B, ui::EF_CONTROL_DOWN);
generator->ReleaseKey(ui::VKEY_B, ui::EF_CONTROL_DOWN);
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
generator->PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT);
generator->ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
EXPECT_EQ(1, target_b.accelerator_non_repeat_count());
EXPECT_EQ(0, target_b.accelerator_repeat_count());
EXPECT_EQ(4, target_a.accelerator_non_repeat_count());
EXPECT_EQ(4, target_a.accelerator_repeat_count());
}
TEST_F(AcceleratorControllerTest, Previous) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE);
generator->ReleaseKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE);
EXPECT_EQ(ui::VKEY_VOLUME_MUTE, GetPreviousAccelerator().key_code());
EXPECT_EQ(ui::EF_NONE, GetPreviousAccelerator().modifiers());
generator->PressKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN);
generator->ReleaseKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN);
EXPECT_EQ(ui::VKEY_TAB, GetPreviousAccelerator().key_code());
EXPECT_EQ(ui::EF_CONTROL_DOWN, GetPreviousAccelerator().modifiers());
}
TEST_F(AcceleratorControllerTest, DontRepeatToggleFullscreen) {
const AcceleratorData accelerators[] = {
{true, ui::VKEY_J, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN},
{true, ui::VKEY_K, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN},
};
test_api_->RegisterAccelerators(accelerators, base::size(accelerators));
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(5, 5, 20, 20);
views::Widget* widget = new views::Widget;
params.context = GetContext();
widget->Init(std::move(params));
widget->Show();
widget->Activate();
widget->GetNativeView()->SetProperty(
aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorCanMaximize);
ui::test::EventGenerator* generator = GetEventGenerator();