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
ash / wm / gestures / back_gesture / back_gesture_event_handler_unittest.cc [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/gestures/back_gesture/back_gesture_event_handler.h"
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/search_box_view.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/model/virtual_keyboard_model.h"
#include "ash/test/ash_test_base.h"
#include "ash/test_shell_delegate.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_divider.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_pin_util.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace/backdrop_controller.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h"
#include "chromeos/ui/base/app_types.h"
#include "chromeos/ui/base/window_properties.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/test_accelerator_target.h"
#include "ui/display/test/display_manager_test_api.h"
namespace ash {
namespace {
void StartKioskSession() {
SessionInfo info;
info.is_running_in_app_mode = true;
info.state = session_manager::SessionState::ACTIVE;
Shell::Get()->session_controller()->SetSessionInfo(info);
}
} // namespace
class BackGestureEventHandlerTest : public AshTestBase {
public:
// Distance that swiping from left edge to let the affordance achieve
// activated state.
static constexpr int kSwipingDistanceForGoingBack = 80;
explicit BackGestureEventHandlerTest(bool can_go_back = true)
: can_go_back_(can_go_back) {}
BackGestureEventHandlerTest(const BackGestureEventHandlerTest&) = delete;
BackGestureEventHandlerTest& operator=(const BackGestureEventHandlerTest&) =
delete;
~BackGestureEventHandlerTest() override = default;
void SetUp() override {
std::unique_ptr<TestShellDelegate> delegate;
if (!can_go_back_) {
delegate = std::make_unique<TestShellDelegate>();
delegate->SetCanGoBack(false);
}
AshTestBase::SetUp(std::move(delegate));
RecreateTopWindow(chromeos::AppType::BROWSER);
TabletModeControllerTestApi().EnterTabletMode();
}
void TearDown() override {
top_window_.reset();
AshTestBase::TearDown();
}
void RegisterBackPressAndRelease(ui::TestAcceleratorTarget* back_press,
ui::TestAcceleratorTarget* back_release) {
AcceleratorControllerImpl* controller =
Shell::Get()->accelerator_controller();
// Register an accelerator that looks for back presses.
ui::Accelerator accelerator_back_press(ui::VKEY_BROWSER_BACK, ui::EF_NONE);
accelerator_back_press.set_key_state(ui::Accelerator::KeyState::PRESSED);
controller->Register({accelerator_back_press}, back_press);
// Register an accelerator that looks for back releases.
ui::Accelerator accelerator_back_release(ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
accelerator_back_release.set_key_state(ui::Accelerator::KeyState::RELEASED);
controller->Register({accelerator_back_release}, back_release);
}
// Send touch event with |type| to the toplevel window event handler.
void SendTouchEvent(const gfx::Point& position, ui::EventType type) {
ui::TouchEvent event =
ui::TouchEvent(type, position, base::TimeTicks::Now(),
ui::PointerDetails(ui::EventPointerType::kTouch,
/*pointer_id=*/5, /*radius_x=*/5.0f,
/*radius_y=*/5.0, /*force=*/1.0f));
ui::Event::DispatcherApi(&event).set_target(top_window_.get());
Shell::Get()->back_gesture_event_handler()->OnTouchEvent(&event);
}
void RecreateTopWindow(chromeos::AppType app_type) {
top_window_ = CreateAppWindow(gfx::Rect(), app_type);
}
void ResetTopWindow() { top_window_.reset(); }
// Generates a scroll sequence that will create a back gesture.
void GenerateBackSequence() {
GetEventGenerator()->GestureScrollSequence(
gfx::Point(0, 100), gfx::Point(kSwipingDistanceForGoingBack + 10, 100),
base::Milliseconds(100), 3);
}
TestShellDelegate* GetShellDelegate() {
return static_cast<TestShellDelegate*>(Shell::Get()->shell_delegate());
}
void SendFullscreenEvent(WindowState* window_state) {
const WMEvent fullscreen_event(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&fullscreen_event);
}
aura::Window* top_window() { return top_window_.get(); }
private:
bool can_go_back_;
std::unique_ptr<aura::Window> top_window_;
};
class BackGestureEventHandlerTestCantGoBack
: public BackGestureEventHandlerTest {
public:
BackGestureEventHandlerTestCantGoBack()
: BackGestureEventHandlerTest(false) {}
};
TEST_F(BackGestureEventHandlerTest, SwipingFromLeftEdgeToGoBack) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
// Tests that swiping from the left less than |kSwipingDistanceForGoingBack|
// should not go to previous page.
ui::test::EventGenerator* generator = GetEventGenerator();
const gfx::Point start(0, 100);
generator->GestureScrollSequence(
start, gfx::Point(kSwipingDistanceForGoingBack - 10, 100),
base::Milliseconds(100), 3);
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
// Tests that swiping from the left more than |kSwipingDistanceForGoingBack|
// should go to previous page.
generator->GestureScrollSequence(
start, gfx::Point(kSwipingDistanceForGoingBack + 10, 100),
base::Milliseconds(100), 3);
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
TEST_F(BackGestureEventHandlerTest, FlingFromLeftEdgeToGoBack) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
// Tests that fling from the left with velocity smaller than
// |kFlingVelocityForGoingBack| should not go to previous page.
// Drag further than |touch_slop| in GestureDetector to trigger scroll
// sequence. Note, |touch_slop| equals to 15.05, which is the value of
// |max_touch_move_in_pixels_for_click_| + |kSlopEpsilon|. Generate the scroll
// sequence with short duration and only one step for FLING scroll gestures.
// X-velocity here will be 800 dips/seconds.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->GestureScrollSequence(gfx::Point(0, 0), gfx::Point(16, 0),
base::Milliseconds(20),
/*steps=*/1);
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
// Tests that fling from the left with velocity larger than
// |kFlingVelocityForGoingBack| should go to previous page. X-velocity here
// will be 1600 dips/seconds.
generator->GestureScrollSequence(gfx::Point(0, 0), gfx::Point(16, 0),
base::Milliseconds(1),
/*steps=*/1);
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
// Tests that fling from the left with velocity smaller than
// |kFlingVelocityForGoingBack| but dragged further enough to trigger
// activated affordance should still go back to previous page. X-velocity here
// will be 800 dips/seconds and drag distance is 160, which is larger than
// |kSwipingDistanceForGoingBack|.
generator->GestureScrollSequence(gfx::Point(0, 0), gfx::Point(160, 0),
base::Milliseconds(200),
/*steps=*/1);
EXPECT_EQ(2, target_back_press.accelerator_count());
EXPECT_EQ(2, target_back_release.accelerator_count());
}
TEST_F(BackGestureEventHandlerTestCantGoBack, GoBackInOverviewMode) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
ASSERT_FALSE(WindowState::Get(top_window())->IsMinimized());
ASSERT_TRUE(window_util::ShouldMinimizeTopWindowOnBack());
GenerateBackSequence();
// Should trigger window minimize instead of go back.
EXPECT_EQ(0, target_back_release.accelerator_count());
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
WindowState::Get(top_window())->Unminimize();
ASSERT_FALSE(WindowState::Get(top_window())->IsMinimized());
auto* shell = Shell::Get();
EnterOverview();
ASSERT_TRUE(shell->overview_controller()->InOverviewSession());
GenerateBackSequence();
// Should trigger go back instead of minimize the window since it is in
// overview mode.
EXPECT_EQ(1, target_back_release.accelerator_count());
// Swipe back at overview mode without opened window should still trigger
// going back.
ExitOverview();
ResetTopWindow();
EnterOverview();
GenerateBackSequence();
EXPECT_EQ(2, target_back_release.accelerator_count());
EXPECT_TRUE(shell->app_list_controller()->IsHomeScreenVisible());
}
TEST_F(BackGestureEventHandlerTest, GoBackInHomeScreenPage) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
auto* shell = Shell::Get();
// Should not go back if it is not in ACTIVE session.
ASSERT_FALSE(shell->overview_controller()->InOverviewSession());
ASSERT_FALSE(shell->app_list_controller()->IsHomeScreenVisible());
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::LOCKED);
GenerateBackSequence();
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
// Reset the top window to make sure the back behavior in home screen is not
// because of sending back event to the top window.
ResetTopWindow();
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::ACTIVE);
shell->app_list_controller()->GoHome(GetPrimaryDisplay().id());
ASSERT_TRUE(shell->app_list_controller()->IsHomeScreenVisible());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
GenerateBackSequence();
// Stay in home screen and none back event will be triggered.
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
GetEventGenerator()->GestureTapAt(GetAppListTestHelper()
->GetAppListView()
->search_box_view()
->GetBoundsInScreen()
.CenterPoint());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
GenerateBackSequence();
// Exit home screen search page and back to |kFullscreenAllApps| state. But
// this is not triggered by sending back event.
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
TEST_F(BackGestureEventHandlerTest, CancelOnScreenRotation) {
UpdateDisplay("807x407");
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::DisplayManager* display_manager = Shell::Get()->display_manager();
display::test::ScopedSetInternalDisplayId set_internal(display_manager,
display_id);
ScreenOrientationControllerTestApi test_api(
Shell::Get()->screen_orientation_controller());
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
// Set the screen orientation to LANDSCAPE_PRIMARY.
test_api.SetDisplayRotation(display::Display::ROTATE_0,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kLandscapePrimary);
gfx::Point start(0, 100);
gfx::Point update_and_end(200, 100);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
// Rotate the screen by 270 degree during drag.
test_api.SetDisplayRotation(display::Display::ROTATE_270,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kPortraitPrimary);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Left edge swipe back should be cancelled due to screen rotation, so the
// fling event with velocity larger than |kFlingVelocityForGoingBack| above
// will not trigger actual going back.
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
}
// Tests that there is no crash when destroying the window during drag the
// back gesture affordance from the left edge.
TEST_F(BackGestureEventHandlerTest, DestroyWindowDuringDrag) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
gfx::Point start(0, 100);
gfx::Point update_and_end(200, 100);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
ResetTopWindow();
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
}
// Tests back gesture while in split view mode.
TEST_F(BackGestureEventHandlerTest, DragFromSplitViewDivider) {
std::unique_ptr<aura::Window> window1 = CreateTestWindow();
std::unique_ptr<aura::Window> window2 = CreateTestWindow();
ui::TestAcceleratorTarget target_back_press, target_back_release;
gfx::Rect display_bounds =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window1.get());
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
auto* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(window1.get(), SnapPosition::kPrimary);
split_view_controller->SnapWindow(window2.get(), SnapPosition::kSecondary);
ASSERT_TRUE(split_view_controller->InSplitViewMode());
ASSERT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
gfx::Rect divider_bounds =
split_view_controller->split_view_divider()->GetDividerBoundsInScreen(
/*is_dragging=*/false);
ui::test::EventGenerator* generator = GetEventGenerator();
// Drag from the splitview divider's non-resizable area with larger than
// |kSwipingDistanceForGoingBack| distance should trigger back gesture. The
// snapped window should go to previous page and divider's position will not
// be changed.
gfx::Point start(divider_bounds.x(), 10);
gfx::Point end(start.x() + kSwipingDistanceForGoingBack + 10, 10);
EXPECT_GT(split_view_controller->GetDividerPosition(),
0.33f * display_bounds.width());
EXPECT_LE(split_view_controller->GetDividerPosition(),
0.5f * display_bounds.width());
generator->GestureScrollSequence(start, end, base::Milliseconds(100), 3);
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
EXPECT_GT(split_view_controller->GetDividerPosition(),
0.33f * display_bounds.width());
EXPECT_LE(split_view_controller->GetDividerPosition(),
0.5f * display_bounds.width());
// Drag from the divider's resizable area should trigger splitview resizing.
// Divider's position will be changed and back gesture should not be
// triggered.
start = divider_bounds.CenterPoint();
end = gfx::Point(0.67f * display_bounds.width(), start.y());
generator->GestureScrollSequence(start, end, base::Milliseconds(100), 3);
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
EXPECT_GT(split_view_controller->GetDividerPosition(),
0.5f * display_bounds.width());
EXPECT_LE(split_view_controller->GetDividerPosition(),
0.67f * display_bounds.width());
split_view_controller->EndSplitView();
}
// Tests that back gesture should always activate the snapped window in split
// view that is underneath the finger in different screen orientations. And that
// the snapped window that is underneath should go back to the previous page.
TEST_F(BackGestureEventHandlerTest, BackGestureInSplitViewMode) {
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::DisplayManager* display_manager = Shell::Get()->display_manager();
display::test::ScopedSetInternalDisplayId set_internal(display_manager,
display_id);
ScreenOrientationControllerTestApi test_api(
Shell::Get()->screen_orientation_controller());
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
std::unique_ptr<aura::Window> left_window = CreateTestWindow();
std::unique_ptr<aura::Window> right_window = CreateTestWindow();
// Start overview first and then snap window in splitview to make sure
// window activation order remains the same.
EnterOverview();
auto* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(left_window.get(), SnapPosition::kPrimary);
split_view_controller->SnapWindow(right_window.get(),
SnapPosition::kSecondary);
// Set the screen orientation to LANDSCAPE_PRIMARY.
test_api.SetDisplayRotation(display::Display::ROTATE_0,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kLandscapePrimary);
ASSERT_EQ(right_window.get(), window_util::GetActiveWindow());
gfx::Point start(0, 10);
gfx::Point update_and_end(kSwipingDistanceForGoingBack + 10, 10);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the display in LandscapePrimary further than
// |kSwipingDistanceForGoingBack| should activate the physically left snapped
// window, which is |left_window| and it should go back to the previous page.
EXPECT_EQ(left_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
gfx::Rect divider_bounds =
split_view_controller->split_view_divider()->GetDividerBoundsInScreen(
/*is_dragging=*/false);
start = gfx::Point(divider_bounds.x(), 10);
update_and_end =
gfx::Point(divider_bounds.x() + kSwipingDistanceForGoingBack + 10, 10);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the split view divider in LandscapePrimary further than
// |kSwipingDistanceForGoingBack| should activate the physically right snapped
// window, which is |right_window| and it should go back to the previous page.
EXPECT_EQ(right_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(2, target_back_press.accelerator_count());
EXPECT_EQ(2, target_back_release.accelerator_count());
// Rotate the screen by 180 degree.
test_api.SetDisplayRotation(display::Display::ROTATE_180,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kLandscapeSecondary);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the split view divider in LandscapeSecondary further than
// |kSwipingDistanceForGoingBack| should activate the physically right snapped
// window, which is |left_window| and it should go back to the previous page.
EXPECT_EQ(left_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(3, target_back_press.accelerator_count());
EXPECT_EQ(3, target_back_release.accelerator_count());
start = gfx::Point(0, 10);
update_and_end = gfx::Point(kSwipingDistanceForGoingBack + 10, 10);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the display in LandscapeSecondary further than
// |kSwipingDistanceForGoingBack| should activate the physically left snapped
// window, which is |right_window| and it should go back to the previous page.
EXPECT_EQ(right_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(4, target_back_press.accelerator_count());
EXPECT_EQ(4, target_back_release.accelerator_count());
// Rotate the screen by 270 degree.
test_api.SetDisplayRotation(display::Display::ROTATE_270,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kPortraitPrimary);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the top half of the display in PortraitPrimary
// further than |kSwipingDistanceForGoingBack| should activate the physically
// top snapped window, which is |right_window|, and it should go back to the
// previous page.
EXPECT_EQ(left_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(5, target_back_press.accelerator_count());
EXPECT_EQ(5, target_back_release.accelerator_count());
divider_bounds =
split_view_controller->split_view_divider()->GetDividerBoundsInScreen(
false);
start = gfx::Point(0, divider_bounds.bottom() + 10);
update_and_end = gfx::Point(kSwipingDistanceForGoingBack + 10, start.y());
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the bottom half of the display in PortraitPrimary
// further than |kSwipingDistanceForGoingBack| should activate the physically
// bottom snapped window, which is |right_window|, and it should go back to
// the previous page.
EXPECT_EQ(right_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(6, target_back_press.accelerator_count());
EXPECT_EQ(6, target_back_release.accelerator_count());
// Rotate the screen by 90 degree.
test_api.SetDisplayRotation(display::Display::ROTATE_90,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
chromeos::OrientationType::kPortraitSecondary);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the bottom half of the display in
// PortraitSecondary further than |kSwipingDistanceForGoingBack| should
// activate the physically bottom snapped window, which is |left_window|, and
// it should go back to the previous page.
EXPECT_EQ(left_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(7, target_back_press.accelerator_count());
EXPECT_EQ(7, target_back_release.accelerator_count());
start = gfx::Point(0, 10);
update_and_end = gfx::Point(kSwipingDistanceForGoingBack + 10, 10);
SendTouchEvent(start, ui::EventType::kTouchPressed);
SendTouchEvent(update_and_end, ui::EventType::kTouchMoved);
SendTouchEvent(update_and_end, ui::EventType::kTouchReleased);
// Swiping from the left of the top half of the display in PortraitSecondary
// further than |kSwipingDistanceForGoingBack| should activate the physically
// top snapped window, which is |right_window| and it should go back to the
// previous page.
EXPECT_EQ(right_window.get(), window_util::GetActiveWindow());
EXPECT_EQ(8, target_back_press.accelerator_count());
EXPECT_EQ(8, target_back_release.accelerator_count());
}
// Tests the back gesture behavior on a non-ARC fullscreened window.
TEST_F(BackGestureEventHandlerTest, FullscreenedWindow) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
WindowState* window_state = WindowState::Get(top_window());
SendFullscreenEvent(window_state);
EXPECT_TRUE(window_state->IsFullscreen());
GenerateBackSequence();
// First back gesture should let the window exit fullscreen mode instead of
// triggering go back.
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GenerateBackSequence();
// Second back gesture should trigger go back.
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
// Tests the back gesture behavior in the Kiosk session.
TEST_F(BackGestureEventHandlerTest, KioskSession) {
StartKioskSession();
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
// Make the test window fullscreen to emulate a real Kiosk session, since in
// the Kiosk session an app window is always fullscreen.
WindowState* window_state = WindowState::Get(top_window());
SendFullscreenEvent(window_state);
EXPECT_TRUE(window_state->IsFullscreen());
GenerateBackSequence();
// First back gesture should not let the window exit fullscreen mode, as we do
// it with a fullscreen window oppened in a user session.
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GenerateBackSequence();
// Second back gesture should not minimize the window, as we do it with a
// fullscreen window oppened in a user session.
EXPECT_FALSE(window_util::ShouldMinimizeTopWindowOnBack());
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
}
// Tests the back gesture behavior on a ARC fullscreened window.
TEST_F(BackGestureEventHandlerTest, ARCFullscreenedWindow) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
RecreateTopWindow(chromeos::AppType::ARC_APP);
WindowState* window_state = WindowState::Get(top_window());
SendFullscreenEvent(window_state);
ASSERT_TRUE(window_state->IsFullscreen());
auto shelf_visible_hotseat_extended = [this]() -> bool {
auto* shelf = Shelf::ForWindow(top_window());
const bool shelf_visible = shelf->GetVisibilityState() == SHELF_VISIBLE;
const bool hotseat_extended =
shelf->hotseat_widget()->state() == HotseatState::kExtended;
return shelf_visible && hotseat_extended;
};
GenerateBackSequence();
// First back gesture should show the shelf instead of triggering go back. The
// app should remain fullscreened.
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
EXPECT_TRUE(shelf_visible_hotseat_extended());
// Tapping on a point on the screen should hide the shelf and hotseat.
GetEventGenerator()->GestureTapAt(gfx::Point(100, 100));
EXPECT_FALSE(shelf_visible_hotseat_extended());
// Send another back gesture to bring up the shelf and hotseat.
GenerateBackSequence();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
EXPECT_TRUE(shelf_visible_hotseat_extended());
GenerateBackSequence();
// Second back gesture in a row should trigger go back. Fullscreen will be
// dependent on how the app choses to handle the back event.
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
// Tests the back gesture behavior when a Chrome OS IME is visible.
TEST_F(BackGestureEventHandlerTest, BackGestureWithCrosKeyboardTest) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
KeyboardController* keyboard_controller = KeyboardController::Get();
keyboard_controller->SetEnableFlag(
keyboard::KeyboardEnableFlag::kExtensionEnabled);
// The keyboard needs to be in a loaded state before being shown.
ASSERT_TRUE(keyboard::test::WaitUntilLoaded());
keyboard_controller->ShowKeyboard();
EXPECT_TRUE(keyboard_controller->IsKeyboardVisible());
GenerateBackSequence();
// First back gesture should hide the virtual keyboard.
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GenerateBackSequence();
// Second back gesture should trigger go back.
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
// Tests that the back gesture works properly on the split view divider bar both
// inside and outside of cros virtual keyboard.
TEST_F(BackGestureEventHandlerTest,
BackGestureWithCrosKeyboardInSplitViewTest) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
std::unique_ptr<aura::Window> left_window = CreateTestWindow();
std::unique_ptr<aura::Window> right_window = CreateTestWindow();
auto* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(left_window.get(), SnapPosition::kPrimary);
split_view_controller->SnapWindow(right_window.get(),
SnapPosition::kSecondary);
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
KeyboardController* keyboard_controller = KeyboardController::Get();
keyboard_controller->SetEnableFlag(
keyboard::KeyboardEnableFlag::kExtensionEnabled);
// The keyboard needs to be in a loaded state before being shown.
ASSERT_TRUE(keyboard::test::WaitUntilLoaded());
keyboard_controller->ShowKeyboard();
EXPECT_TRUE(keyboard_controller->IsKeyboardVisible());
// Get the keyboard bounds:
keyboard::KeyboardUIController* keyboard_ui_controller =
keyboard::KeyboardUIController::Get();
EXPECT_TRUE(keyboard_ui_controller->IsKeyboardVisible());
gfx::Rect keyboard_bounds = keyboard_ui_controller->GetVisualBoundsInScreen();
// Start dragging from a position that is right outside the divider bar bounds
// and outside the VK bounds.
gfx::Rect divider_bounds =
split_view_controller->split_view_divider()->GetDividerBoundsInScreen(
false);
gfx::Point start = gfx::Point(divider_bounds.CenterPoint().x(), 10);
EXPECT_FALSE(keyboard_bounds.Contains(start));
gfx::Point end =
gfx::Point(start.x() + kSwipingDistanceForGoingBack + 10, start.y());
GetEventGenerator()->GestureScrollSequence(start, end,
base::Milliseconds(100), 3);
// Virtual keyboard should be closed.
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
// Start dragging from the split view divider bar position that is inside the
// VK bounds.
keyboard_controller->ShowKeyboard();
EXPECT_TRUE(keyboard_controller->IsKeyboardVisible());
start = gfx::Point(divider_bounds.CenterPoint().x(),
keyboard_bounds.CenterPoint().y());
EXPECT_TRUE(keyboard_bounds.Contains(start));
end = gfx::Point(start.x() + kSwipingDistanceForGoingBack + 10, start.y());
GetEventGenerator()->GestureScrollSequence(start, end,
base::Milliseconds(100), 3);
// Nothing should happen.
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
EXPECT_TRUE(keyboard_controller->IsKeyboardVisible());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
}
// Tests the back gesture behavior when an Android IME is visible. Due to the
// way the Android IME is implemented, a lot of this test is fake behavior, but
// it will help catch regressions.
TEST_F(BackGestureEventHandlerTest, BackGestureWithAndroidKeyboardTest) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
WindowState* window_state = WindowState::Get(top_window());
ASSERT_FALSE(window_state->IsMinimized());
VirtualKeyboardModel* keyboard =
Shell::Get()->system_tray_model()->virtual_keyboard();
ASSERT_TRUE(keyboard);
// Fakes showing the keyboard.
keyboard->OnArcInputMethodBoundsChanged(gfx::Rect(400, 400));
EXPECT_TRUE(keyboard->arc_keyboard_visible());
// Unfortunately we cannot hook this all the wall up to see if the Android IME
// is hidden, but we can check that back key events are generated and the top
// window is not minimized.
GenerateBackSequence();
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
EXPECT_FALSE(window_state->IsMinimized());
}
// Tests that the back gesture works properly on the split view divider bar both
// inside and outside of Android virtual keyboard.
TEST_F(BackGestureEventHandlerTest,
BackGestureWithAndroidKeyboardInSplitViewTest) {
UpdateDisplay("800x600");
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
std::unique_ptr<aura::Window> left_window = CreateTestWindow();
std::unique_ptr<aura::Window> right_window = CreateTestWindow();
auto* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(left_window.get(), SnapPosition::kPrimary);
split_view_controller->SnapWindow(right_window.get(),
SnapPosition::kSecondary);
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
VirtualKeyboardModel* keyboard =
Shell::Get()->system_tray_model()->virtual_keyboard();
ASSERT_TRUE(keyboard);
// Fakes showing the keyboard.
gfx::Rect keyboard_bounds =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
left_window.get());
keyboard_bounds.set_y(keyboard_bounds.bottom() - 200);
keyboard_bounds.set_height(200);
keyboard->OnArcInputMethodBoundsChanged(keyboard_bounds);
EXPECT_TRUE(keyboard->arc_keyboard_visible());
// Start dragging from the split view divider bar position that is outside the
// VK bounds.
gfx::Rect divider_bounds =
split_view_controller->split_view_divider()->GetDividerBoundsInScreen(
false);
gfx::Point start = gfx::Point(divider_bounds.CenterPoint().x(), 10);
EXPECT_FALSE(keyboard_bounds.Contains(start));
gfx::Point end =
gfx::Point(start.x() + kSwipingDistanceForGoingBack + 10, start.y());
GetEventGenerator()->GestureScrollSequence(start, end,
base::Milliseconds(100), 3);
// Virtual keyboard should be closed. But Unfortunately we cannot hook
// this all the wall up to see if the Android IME is hidden, but we can check
// that back key events are generated and we're still in both snapped split
// view state.
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
// Start dragging from the split view divider bar position that is inside the
// VK bounds.
target_back_press.ResetCounts();
target_back_release.ResetCounts();
keyboard->OnArcInputMethodBoundsChanged(keyboard_bounds);
EXPECT_TRUE(keyboard->arc_keyboard_visible());
start = gfx::Point(divider_bounds.CenterPoint().x(),
keyboard_bounds.CenterPoint().y());
EXPECT_TRUE(keyboard_bounds.Contains(start));
end = gfx::Point(start.x() + kSwipingDistanceForGoingBack + 10, start.y());
GetEventGenerator()->GestureScrollSequence(start, end,
base::Milliseconds(100), 3);
// Nothing should happen.
EXPECT_EQ(SplitViewController::State::kBothSnapped,
split_view_controller->state());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
}
TEST_F(BackGestureEventHandlerTest, IgnoreSecondFinger) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
const gfx::Point start_point(0, 100);
const gfx::Point end_point(200, 100);
// Scenario 1:
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
// Without releasing the first finger, now press and release the second
// finger.
generator->PressTouchId(1);
generator->ReleaseTouchId(1);
// Then release the first finger. Back should be able to be performed.
generator->ReleaseTouchId(0);
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
// Scenario 2:
wm::ActivateWindow(top_window());
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
// Without releasing the first finger, now press the second finger.
generator->PressTouchId(1);
// Release the first finger and then the second finger.
generator->ReleaseTouchId(0);
generator->ReleaseTouchId(1);
// Test that back should still be able to be performed.
EXPECT_EQ(2, target_back_press.accelerator_count());
EXPECT_EQ(2, target_back_release.accelerator_count());
// Scenario 3:
wm::ActivateWindow(top_window());
GetShellDelegate()->SetShouldWaitForTouchAck(
/*should_wait_for_touch_ack=*/true);
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
// Without releasing the first finger, now press and release the second
// finger.
generator->PressTouchId(1);
generator->ReleaseTouchId(1);
// Then release the first finger. Back should be able to be performed.
generator->ReleaseTouchId(0);
EXPECT_EQ(3, target_back_press.accelerator_count());
EXPECT_EQ(3, target_back_release.accelerator_count());
// Scenario 4:
wm::ActivateWindow(top_window());
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
// Without releasing the first finger, now press the second finger.
generator->PressTouchId(1);
// Release the first finger and then the second finger.
generator->ReleaseTouchId(0);
generator->ReleaseTouchId(1);
// Test that back should still be able to be performed.
EXPECT_EQ(4, target_back_press.accelerator_count());
EXPECT_EQ(4, target_back_release.accelerator_count());
}
TEST_F(BackGestureEventHandlerTest, CancelledEventOnSecondFinger) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
const gfx::Point start_point(0, 100);
const gfx::Point end_point(200, 100);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
// Without releasing the first finger, now press the second finger.
generator->PressTouchId(1);
// Then release the first finger. Back should be able to be performed.
generator->ReleaseTouchId(0);
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
generator->ReleaseTouchId(1);
// Manually dispatch a ui::EventType::kTouchCancelled event to the second
// finger to simulate what's happending in real world.
ui::TouchEvent event = ui::TouchEvent(
ui::EventType::kTouchCancelled, start_point, base::TimeTicks::Now(),
ui::PointerDetails(ui::EventPointerType::kTouch,
/*pointer_id=*/1, /*radius_x=*/5.0f,
/*radius_y=*/5.0, /*force=*/1.0f));
ui::Event::DispatcherApi(&event).set_target(top_window());
Shell::Get()->back_gesture_event_handler()->OnTouchEvent(&event);
wm::ActivateWindow(top_window());
generator->PressTouchId(0, std::make_optional(start_point));
generator->MoveTouch(end_point);
generator->ReleaseTouchId(0);
// Test that back should still be able to be performed.
EXPECT_EQ(2, target_back_press.accelerator_count());
EXPECT_EQ(2, target_back_release.accelerator_count());
}
// Tests that swiping on the backdrop to minimize a non-resizable app will not
// cause a crash. Regression test for http://crbug.com/1064618.
TEST_F(BackGestureEventHandlerTestCantGoBack, NonResizableApp) {
// Make the top window non-resizable and set its bounds so that the backdrop
// will take the gesture events.
top_window()->SetProperty(aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorCanMinimize);
WindowState* window_state = WindowState::Get(top_window());
window_state->Restore();
SetBoundsWMEvent bounds_event(gfx::Rect(200, 100, 300, 300));
window_state->OnWMEvent(&bounds_event);
ASSERT_FALSE(window_state->IsMinimized());
// Check that the backdrop is visible.
WorkspaceController* workspace_controller =
GetWorkspaceControllerForContext(top_window());
WorkspaceLayoutManager* layout_manager =
workspace_controller->layout_manager();
BackdropController* backdrop_controller =
layout_manager->backdrop_controller();
aura::Window* backdrop_window = backdrop_controller->backdrop_window();
ASSERT_TRUE(backdrop_window);
ASSERT_TRUE(backdrop_window->IsVisible());
// Generate a back seqeuence. There should be no crash.
GenerateBackSequence();
EXPECT_TRUE(window_state->IsMinimized());
}
TEST_F(BackGestureEventHandlerTestCantGoBack, NonAppAndSystemApps) {
RecreateTopWindow(chromeos::AppType::NON_APP);
GenerateBackSequence();
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
RecreateTopWindow(chromeos::AppType::SYSTEM_APP);
GenerateBackSequence();
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
}
// Tests that the back gesture will force minimize even non minimizeable apps.
TEST_F(BackGestureEventHandlerTestCantGoBack, NonMinimizeableApp) {
// Make the top window non minimizeable.
top_window()->SetProperty(aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorNone);
GenerateBackSequence();
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
}
TEST_F(BackGestureEventHandlerTestCantGoBack, LockedFullscreen) {
RecreateTopWindow(chromeos::AppType::SYSTEM_APP);
PinWindow(top_window(), /*trusted=*/true);
GenerateBackSequence();
ASSERT_FALSE(WindowState::Get(top_window())->IsMinimized());
// Verify that the back gesture will minimize the window once it is unpinned.
UnpinWindow(top_window());
GenerateBackSequence();
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
}
TEST_F(BackGestureEventHandlerTestCantGoBack, PinnedWindow) {
RecreateTopWindow(chromeos::AppType::SYSTEM_APP);
PinWindow(top_window(), /*trusted=*/false);
GenerateBackSequence();
EXPECT_TRUE(WindowState::Get(top_window())->IsMinimized());
}
} // namespace ash