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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
ash / wm / tablet_mode / tablet_mode_window_manager_unittest.cc [blame]
// Copyright 2014 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/tablet_mode/tablet_mode_window_manager.h"
#include <string>
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/public/cpp/overview_test_api.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_prefs.h"
#include "ash/public/cpp/test/shell_test_api.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h"
#include "ash/session/test_session_controller_client.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_metrics.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_constants.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_divider.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/switchable_windows.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_observer.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/work_area_insets.h"
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chromeos/ui/base/window_state_type.h"
#include "chromeos/ui/frame/caption_buttons/snap_controller.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/hit_test.h"
#include "ui/base/mojom/window_show_state.mojom.h"
#include "ui/compositor/layer.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/ime_util_chromeos.h"
#include "ui/wm/core/transient_window_manager.h"
#include "ui/wm/core/window_util.h"
namespace ash {
using ::chromeos::WindowStateType;
// A helper function to set the shelf auto-hide preference. This has the same
// effect as the user toggling the shelf context menu option.
void SetShelfAutoHideBehaviorPref(int64_t display_id,
ShelfAutoHideBehavior behavior) {
PrefService* prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
if (!prefs)
return;
SetShelfAutoHideBehaviorPref(prefs, display_id, behavior);
}
class TabletModeWindowManagerTest : public AshTestBase {
public:
TabletModeWindowManagerTest() = default;
TabletModeWindowManagerTest(const TabletModeWindowManagerTest&) = delete;
TabletModeWindowManagerTest& operator=(const TabletModeWindowManagerTest&) =
delete;
~TabletModeWindowManagerTest() override = default;
// Initialize parameters for test windows. If |can_maximize| is not
// set, |max_size| is the upper limiting size for the window,
// whereas an empty size means that there is no limit.
struct InitParams {
explicit InitParams(aura::client::WindowType t) : type(t) {}
aura::client::WindowType type = aura::client::WINDOW_TYPE_NORMAL;
gfx::Rect bounds;
gfx::Size max_size;
bool can_maximize = true;
bool can_resize = true;
bool show_on_creation = true;
};
// Creates a window which has a fixed size.
aura::Window* CreateFixedSizeNonMaximizableWindow(
aura::client::WindowType type,
const gfx::Rect& bounds) {
InitParams params(type);
params.bounds = bounds;
params.can_maximize = false;
params.can_resize = false;
return CreateWindowInWatchedContainer(params);
}
// Creates a window which can not be maximized, but resized. |max_size|
// denotes the maximal possible size, if the size is empty, the window has no
// upper limit. Note: This function will only work with a single root window.
aura::Window* CreateNonMaximizableWindow(aura::client::WindowType type,
const gfx::Rect& bounds,
const gfx::Size& max_size) {
InitParams params(type);
params.bounds = bounds;
params.max_size = max_size;
params.can_maximize = false;
return CreateWindowInWatchedContainer(params);
}
// Creates a maximizable and resizable window.
aura::Window* CreateWindow(aura::client::WindowType type,
const gfx::Rect bounds) {
InitParams params(type);
params.bounds = bounds;
return CreateWindowInWatchedContainer(params);
}
// Creates a window which also has a widget.
aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) {
views::Widget* widget =
views::Widget::CreateWindowWithContext(nullptr, GetContext(), bounds);
widget->Show();
// Note: The widget will get deleted with the window.
return widget->GetNativeWindow();
}
// Create the tablet mode window manager.
TabletModeWindowManager* CreateTabletModeWindowManager() {
EXPECT_FALSE(TabletModeControllerTestApi().tablet_mode_window_manager());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
return TabletModeControllerTestApi().tablet_mode_window_manager();
}
// Destroy the tablet mode window manager.
void DestroyTabletModeWindowManager() {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_FALSE(TabletModeControllerTestApi().tablet_mode_window_manager());
}
// Resize our desktop.
void ResizeDesktop(int width_delta) {
gfx::Size size =
display::Screen::GetScreen()
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow())
.size();
size.Enlarge(0, width_delta);
UpdateDisplay(size.ToString());
}
// Create a window in one of the containers which are watched by the
// TabletModeWindowManager. Note that this only works with one root window.
aura::Window* CreateWindowInWatchedContainer(const InitParams& params) {
aura::test::TestWindowDelegate* delegate = NULL;
if (!params.can_maximize) {
delegate = aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
delegate->set_window_component(HTCAPTION);
if (!params.max_size.IsEmpty())
delegate->set_maximum_size(params.max_size);
}
aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType(
delegate, params.type, 0, params.bounds, NULL, params.show_on_creation);
int32_t behavior = aura::client::kResizeBehaviorNone |
aura::client::kResizeBehaviorCanFullscreen;
behavior |= params.can_resize ? aura::client::kResizeBehaviorCanResize : 0;
behavior |=
params.can_maximize ? aura::client::kResizeBehaviorCanMaximize : 0;
window->SetProperty(aura::client::kResizeBehaviorKey, behavior);
aura::Window* container =
GetSwitchableContainersForRoot(Shell::GetPrimaryRootWindow(),
/*active_desk_only=*/true)[0];
container->AddChild(window);
return window;
}
SplitViewController* split_view_controller() {
return SplitViewController::Get(Shell::GetPrimaryRootWindow());
}
};
// Test that creating the object and destroying it without any windows should
// not cause any problems.
TEST_F(TabletModeWindowManagerTest, SimpleStart) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
DestroyTabletModeWindowManager();
}
// Test that existing windows will handled properly when going into tablet
// mode.
TEST_F(TabletModeWindowManagerTest, PreCreateWindows) {
// Bounds for windows we know can be controlled.
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(10, 60, 200, 50);
gfx::Rect rect3(20, 140, 100, 100);
// Bounds for anything else.
gfx::Rect rect(80, 90, 100, 110);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2));
std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect3));
std::unique_ptr<aura::Window> w4(
CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect));
std::unique_ptr<aura::Window> w5(
CreateWindow(aura::client::WINDOW_TYPE_MENU, rect));
std::unique_ptr<aura::Window> w6(
CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect));
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
// Create the manager and make sure that all qualifying windows were detected
// and changed.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_TRUE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString());
EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString());
// All other windows should not have been touched.
EXPECT_FALSE(WindowState::Get(w4.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w5.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w6.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
// Destroy the manager again and check that the windows return to their
// previous state.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
}
// The same test as the above but while a system modal dialog is shown.
TEST_F(TabletModeWindowManagerTest, GoingToMaximizedWithModalDialogPresent) {
// Bounds for windows we know can be controlled.
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(10, 60, 200, 50);
gfx::Rect rect3(20, 140, 100, 100);
// Bounds for anything else.
gfx::Rect rect(80, 90, 100, 110);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2));
std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect3));
std::unique_ptr<aura::Window> w4(
CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect));
std::unique_ptr<aura::Window> w5(
CreateWindow(aura::client::WINDOW_TYPE_MENU, rect));
std::unique_ptr<aura::Window> w6(
CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect));
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
// Enable system modal dialog, and make sure both shelves are still hidden.
ShellTestApi().SimulateModalWindowOpenForTest(true);
EXPECT_TRUE(Shell::IsSystemModalWindowOpen());
// Create the manager and make sure that all qualifying windows were detected
// and changed.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_TRUE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString());
EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString());
// All other windows should not have been touched.
EXPECT_FALSE(WindowState::Get(w4.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w5.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w6.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
// Destroy the manager again and check that the windows return to their
// previous state.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
}
// Test that non-maximizable windows get properly handled when going into
// tablet mode.
TEST_F(TabletModeWindowManagerTest,
PreCreateNonMaximizableButResizableWindows) {
// The window bounds.
gfx::Rect rect(10, 10, 200, 50);
gfx::Size max_size(300, 200);
gfx::Size empty_size;
std::unique_ptr<aura::Window> unlimited_window(CreateNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect, empty_size));
std::unique_ptr<aura::Window> limited_window(CreateNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect, max_size));
std::unique_ptr<aura::Window> fixed_window(
CreateFixedSizeNonMaximizableWindow(aura::client::WINDOW_TYPE_NORMAL,
rect));
EXPECT_FALSE(WindowState::Get(unlimited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(limited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(fixed_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
// Create the manager and make sure that all qualifying windows were detected
// and changed.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
// The unlimited window should have the size of the workspace / parent window.
EXPECT_FALSE(WindowState::Get(unlimited_window.get())->IsMaximized());
EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
const gfx::Size workspace_size_tablet_mode =
screen_util::GetMaximizedWindowBoundsInParent(unlimited_window.get())
.size();
EXPECT_EQ(workspace_size_tablet_mode.ToString(),
unlimited_window->bounds().size().ToString());
// The limited window should have the size of the upper possible bounds.
EXPECT_FALSE(WindowState::Get(limited_window.get())->IsMaximized());
EXPECT_NE(rect.origin().ToString(),
limited_window->bounds().origin().ToString());
EXPECT_EQ(max_size.ToString(), limited_window->bounds().size().ToString());
// The fixed size window should have the size of the original window.
EXPECT_FALSE(WindowState::Get(fixed_window.get())->IsMaximized());
EXPECT_NE(rect.origin().ToString(),
fixed_window->bounds().origin().ToString());
EXPECT_EQ(rect.size().ToString(), fixed_window->bounds().size().ToString());
// Destroy the manager again and check that the windows return to their
// previous state.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(unlimited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(limited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(fixed_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
}
// Test that creating windows while a maximizer exists picks them properly up.
TEST_F(TabletModeWindowManagerTest, CreateWindows) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
// Create the windows and see that the window manager picks them up.
// Rects for windows we know can be controlled.
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(10, 60, 200, 50);
gfx::Rect rect3(20, 140, 100, 100);
// One rect for anything else.
gfx::Rect rect(80, 90, 100, 110);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2));
std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect3));
std::unique_ptr<aura::Window> w4(
CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect));
std::unique_ptr<aura::Window> w5(
CreateWindow(aura::client::WINDOW_TYPE_MENU, rect));
std::unique_ptr<aura::Window> w6(
CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect));
EXPECT_TRUE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_TRUE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
// Make sure that the position of the unresizable window is in the middle of
// the screen.
gfx::Size work_area_size =
screen_util::GetDisplayWorkAreaBoundsInParent(w3.get()).size();
gfx::Point center =
gfx::Point((work_area_size.width() - rect3.size().width()) / 2,
(work_area_size.height() - rect3.size().height()) / 2);
gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size());
EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString());
// All other windows should not have been touched.
EXPECT_FALSE(WindowState::Get(w4.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w5.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w6.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
// After the tablet mode was disabled all windows fall back into the mode
// they were created for.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
}
// Test that a window which got created while the tablet mode window manager
// is active gets restored to a usable (non tiny) size upon switching back.
TEST_F(TabletModeWindowManagerTest,
CreateWindowInTabletModeRestoresToUsefulSize) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
// We pass in an empty rectangle to simulate a window creation with no
// particular size.
gfx::Rect empty_rect(0, 0, 0, 0);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, empty_rect));
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
EXPECT_NE(empty_rect.ToString(), window->bounds().ToString());
gfx::Rect maximized_size = window->bounds();
const gfx::Insets tablet_insets =
WorkAreaInsets::ForWindow(window.get())->user_work_area_insets();
// Destroy the tablet mode and check that the resulting size of the window
// is remaining as it is (but not maximized).
DestroyTabletModeWindowManager();
// Account for work-area updates when leaving tablet mode.
const gfx::Insets clamshell_insets =
WorkAreaInsets::ForWindow(window.get())->user_work_area_insets();
const gfx::Insets offset_difference = clamshell_insets - tablet_insets;
maximized_size.Inset(offset_difference);
EXPECT_FALSE(WindowState::Get(window.get())->IsMaximized());
EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString());
}
// Test that non-maximizable windows get properly handled when created in
// tablet mode.
TEST_F(TabletModeWindowManagerTest, CreateNonMaximizableButResizableWindows) {
// Create the manager and make sure that all qualifying windows were detected
// and changed.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
gfx::Rect rect(10, 10, 200, 50);
gfx::Size max_size(300, 200);
gfx::Size empty_size;
std::unique_ptr<aura::Window> unlimited_window(CreateNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect, empty_size));
std::unique_ptr<aura::Window> limited_window(CreateNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect, max_size));
std::unique_ptr<aura::Window> fixed_window(
CreateFixedSizeNonMaximizableWindow(aura::client::WINDOW_TYPE_NORMAL,
rect));
gfx::Size workspace_size =
screen_util::GetMaximizedWindowBoundsInParent(unlimited_window.get())
.size();
// All windows should be sized now as big as possible and be centered.
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
// The unlimited window should have the size of the workspace / parent window.
EXPECT_FALSE(WindowState::Get(unlimited_window.get())->IsMaximized());
EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
EXPECT_EQ(workspace_size.ToString(),
unlimited_window->bounds().size().ToString());
// The limited window should have the size of the upper possible bounds.
EXPECT_FALSE(WindowState::Get(limited_window.get())->IsMaximized());
EXPECT_NE(rect.origin().ToString(),
limited_window->bounds().origin().ToString());
EXPECT_EQ(max_size.ToString(), limited_window->bounds().size().ToString());
// The fixed size window should have the size of the original window.
EXPECT_FALSE(WindowState::Get(fixed_window.get())->IsMaximized());
EXPECT_NE(rect.origin().ToString(),
fixed_window->bounds().origin().ToString());
EXPECT_EQ(rect.size().ToString(), fixed_window->bounds().size().ToString());
// Destroy the manager again and check that the windows return to their
// creation state.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(unlimited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(limited_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
EXPECT_FALSE(WindowState::Get(fixed_window.get())->IsMaximized());
EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
}
// Create a string which consists of the bounds and the state for comparison.
std::string GetPlacementString(const gfx::Rect& bounds,
ui::mojom::WindowShowState state) {
return bounds.ToString() + ' ' +
base::NumberToString(static_cast<int>(state));
}
// Retrieves the window's restore state override - if any - and returns it as a
// string.
std::string GetPlacementOverride(aura::Window* window) {
gfx::Rect* bounds = window->GetProperty(kRestoreBoundsOverrideKey);
if (!bounds)
return std::string();
const auto type = window->GetProperty(kRestoreWindowStateTypeOverrideKey);
return GetPlacementString(*bounds, ToWindowShowState(type));
}
// Test that the restore state will be kept at its original value for
// session restoration purposes.
TEST_F(TabletModeWindowManagerTest, TestRestoreIntegrety) {
gfx::Rect bounds(10, 10, 200, 50);
std::unique_ptr<aura::Window> normal_window(CreateWindowWithWidget(bounds));
std::unique_ptr<aura::Window> maximized_window(
CreateWindowWithWidget(bounds));
WindowState::Get(maximized_window.get())->Maximize();
EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
// With the maximization the override states should be returned in its
// pre-maximized state.
EXPECT_EQ(GetPlacementString(bounds, ui::mojom::WindowShowState::kDefault),
GetPlacementOverride(normal_window.get()));
EXPECT_EQ(GetPlacementString(bounds, ui::mojom::WindowShowState::kMaximized),
GetPlacementOverride(maximized_window.get()));
// Changing a window's state now does not change the returned result.
WindowState::Get(maximized_window.get())->Minimize();
EXPECT_EQ(GetPlacementString(bounds, ui::mojom::WindowShowState::kMaximized),
GetPlacementOverride(maximized_window.get()));
// Destroy the manager again and check that the overrides get reset.
DestroyTabletModeWindowManager();
EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
// Changing a window's state now does not bring the overrides back.
WindowState::Get(maximized_window.get())->Restore();
gfx::Rect new_bounds(10, 10, 200, 50);
maximized_window->SetBounds(new_bounds);
EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
}
// Test that windows which got created before the maximizer was created can be
// destroyed while the maximizer is still running.
TEST_F(TabletModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
TabletModeWindowManager* manager = NULL;
{
// Bounds for windows we know can be controlled.
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(10, 60, 200, 50);
gfx::Rect rect3(20, 140, 100, 100);
// Bounds for anything else.
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2));
std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect3));
// Create the manager and make sure that all qualifying windows were
// detected and changed.
manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
}
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
DestroyTabletModeWindowManager();
}
// Test that windows which got created while the maximizer was running can get
// destroyed before the maximizer gets destroyed.
TEST_F(TabletModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
{
// Bounds for windows we know can be controlled.
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(10, 60, 200, 50);
gfx::Rect rect3(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2));
std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect3));
// Check that the windows got automatically maximized as well.
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_TRUE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w3.get())->IsMaximized());
}
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
DestroyTabletModeWindowManager();
}
// Test that windows which were maximized stay maximized.
TEST_F(TabletModeWindowManagerTest, MaximizedShouldRemainMaximized) {
// Bounds for windows we know can be controlled.
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState::Get(window.get())->Maximize();
// Create the manager and make sure that the window gets detected.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
// Destroy the manager again and check that the window will remain maximized.
DestroyTabletModeWindowManager();
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
WindowState::Get(window.get())->Restore();
EXPECT_EQ(rect.ToString(), window->bounds().ToString());
}
// Test that minimized windows do neither get maximized nor restored upon
// entering tablet mode and get restored to their previous state after
// leaving.
TEST_F(TabletModeWindowManagerTest, MinimizedWindowBehavior) {
// Bounds for windows we know can be controlled.
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> initially_minimized_window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> initially_normal_window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> initially_maximized_window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState::Get(initially_minimized_window.get())->Minimize();
WindowState::Get(initially_maximized_window.get())->Maximize();
// Create the manager and make sure that the window gets detected.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(
WindowState::Get(initially_minimized_window.get())->IsMinimized());
EXPECT_TRUE(WindowState::Get(initially_normal_window.get())->IsMaximized());
EXPECT_TRUE(
WindowState::Get(initially_maximized_window.get())->IsMaximized());
// Now minimize the second window to check that upon leaving the window
// will get restored to its minimized state.
WindowState::Get(initially_normal_window.get())->Minimize();
WindowState::Get(initially_maximized_window.get())->Minimize();
EXPECT_TRUE(
WindowState::Get(initially_minimized_window.get())->IsMinimized());
EXPECT_TRUE(WindowState::Get(initially_normal_window.get())->IsMinimized());
EXPECT_TRUE(
WindowState::Get(initially_maximized_window.get())->IsMinimized());
// Destroy the manager again and check that the window will get minimized.
DestroyTabletModeWindowManager();
EXPECT_TRUE(
WindowState::Get(initially_minimized_window.get())->IsMinimized());
EXPECT_FALSE(WindowState::Get(initially_normal_window.get())->IsMinimized());
EXPECT_TRUE(
WindowState::Get(initially_maximized_window.get())->IsMaximized());
}
// Check that resizing the desktop does reposition unmaximizable, unresizable &
// managed windows.
TEST_F(TabletModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
UpdateDisplay("500x400");
// This window will move because it does not fit the new bounds.
gfx::Rect rect(20, 300, 100, 100);
std::unique_ptr<aura::Window> window1(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
EXPECT_EQ(rect.ToString(), window1->bounds().ToString());
// This window will not move because it does fit the new bounds.
gfx::Rect rect2(20, 140, 100, 100);
std::unique_ptr<aura::Window> window2(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect2));
// Turning on the manager will reposition (but not resize) the window.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
gfx::Rect moved_bounds(window1->bounds());
EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
// Simulating a desktop resize should move the window again.
UpdateDisplay("400x300");
gfx::Rect new_moved_bounds(window1->bounds());
EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
// Turning off the mode should not restore to the initial coordinates since
// the new resolution is smaller and the window was on the edge.
DestroyTabletModeWindowManager();
EXPECT_NE(rect.ToString(), window1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), window2->bounds().ToString());
}
// Check that windows return to original location if desktop size changes to
// something else and back while in tablet mode.
TEST_F(TabletModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> window(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
// Turning on the manager will reposition (but not resize) the window.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
gfx::Rect moved_bounds(window->bounds());
EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
// Simulating a desktop resize should move the window again.
ResizeDesktop(-10);
gfx::Rect new_moved_bounds(window->bounds());
EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
// Then resize back to the original desktop size which should move windows
// to their original location after leaving the tablet mode.
ResizeDesktop(10);
DestroyTabletModeWindowManager();
EXPECT_EQ(rect.ToString(), window->bounds().ToString());
}
// Check that enabling of the tablet mode does not have an impact on the MRU
// order of windows.
TEST_F(TabletModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> w2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> w3(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> w4(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> w5(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
// The windows should be in the reverse order of creation in the MRU list.
{
aura::Window::Windows windows =
Shell::Get()->mru_window_tracker()->BuildMruWindowList(kAllDesks);
EXPECT_EQ(w1.get(), windows[4]);
EXPECT_EQ(w2.get(), windows[3]);
EXPECT_EQ(w3.get(), windows[2]);
EXPECT_EQ(w4.get(), windows[1]);
EXPECT_EQ(w5.get(), windows[0]);
}
// Activating the window manager should keep the order.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(5, manager->GetNumberOfManagedWindows());
{
aura::Window::Windows windows =
Shell::Get()->mru_window_tracker()->BuildMruWindowList(kAllDesks);
// We do not test maximization here again since that was done already.
EXPECT_EQ(w1.get(), windows[4]);
EXPECT_EQ(w2.get(), windows[3]);
EXPECT_EQ(w3.get(), windows[2]);
EXPECT_EQ(w4.get(), windows[1]);
EXPECT_EQ(w5.get(), windows[0]);
}
// Destroying should still keep the order.
DestroyTabletModeWindowManager();
{
aura::Window::Windows windows =
Shell::Get()->mru_window_tracker()->BuildMruWindowList(kAllDesks);
// We do not test maximization here again since that was done already.
EXPECT_EQ(w1.get(), windows[4]);
EXPECT_EQ(w2.get(), windows[3]);
EXPECT_EQ(w3.get(), windows[2]);
EXPECT_EQ(w4.get(), windows[1]);
EXPECT_EQ(w5.get(), windows[0]);
}
}
// Check that a restore state change does always restore to maximized.
TEST_F(TabletModeWindowManagerTest, IgnoreRestoreStateChages) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
CreateTabletModeWindowManager();
EXPECT_TRUE(window_state->IsMaximized());
window_state->Minimize();
EXPECT_TRUE(window_state->IsMinimized());
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
DestroyTabletModeWindowManager();
}
// Check that minimize and restore do the right thing.
TEST_F(TabletModeWindowManagerTest, TestMinimize) {
gfx::Rect rect(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
EXPECT_EQ(rect.ToString(), window->bounds().ToString());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_FALSE(window_state->IsMinimized());
EXPECT_TRUE(window->IsVisible());
window_state->Minimize();
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_TRUE(window_state->IsMinimized());
EXPECT_FALSE(window->IsVisible());
window_state->Maximize();
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_FALSE(window_state->IsMinimized());
EXPECT_TRUE(window->IsVisible());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_FALSE(window_state->IsMinimized());
EXPECT_TRUE(window->IsVisible());
}
// Tests that minimized window can restore to pre-minimized show state after
// entering and leaving tablet mode (https://crbug.com/783310).
TEST_F(TabletModeWindowManagerTest, MinimizedEnterAndLeaveTabletMode) {
gfx::Rect rect(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
window_state->Minimize();
EXPECT_TRUE(window_state->IsMinimized());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_TRUE(window_state->IsMinimized());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_TRUE(window_state->IsMinimized());
window_state->Unminimize();
EXPECT_FALSE(window_state->IsMinimized());
window_state->Minimize();
EXPECT_TRUE(window_state->IsMinimized());
}
// Tests that pre-minimized window show state is persistent after entering and
// leaving tablet mode, that is not cleared in tablet mode.
TEST_F(TabletModeWindowManagerTest, PersistPreMinimizedShowState) {
gfx::Rect rect(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
window_state->Maximize();
window_state->Minimize();
EXPECT_EQ(ui::mojom::WindowShowState::kMaximized,
window->GetProperty(aura::client::kRestoreShowStateKey));
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
window_state->Unminimize();
// Check that pre-minimized window show state is not cleared due to
// unminimizing in tablet mode.
EXPECT_EQ(ui::mojom::WindowShowState::kMaximized,
window->GetProperty(aura::client::kRestoreShowStateKey));
window_state->Minimize();
EXPECT_EQ(ui::mojom::WindowShowState::kMaximized,
window->GetProperty(aura::client::kRestoreShowStateKey));
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
window_state->Unminimize();
EXPECT_TRUE(window_state->IsMaximized());
}
// Tests unminimizing in tablet mode and then exiting tablet mode should have
// pre-minimized window show state.
TEST_F(TabletModeWindowManagerTest, UnminimizeInTabletMode) {
// Tests restoring to maximized show state.
gfx::Rect rect(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
window_state->Maximize();
window_state->Minimize();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
window_state->Unminimize();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_TRUE(window_state->IsMaximized());
// Tests restoring to normal show state.
window_state->Restore();
EXPECT_EQ(gfx::Rect(10, 10, 100, 100), window->GetBoundsInScreen());
window_state->Minimize();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
window_state->Unminimize();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_EQ(gfx::Rect(10, 10, 100, 100), window->GetBoundsInScreen());
}
// Tests that if we minimize a snapped window, it is snapped upon unminimizing.
TEST_F(TabletModeWindowManagerTest, UnminimizeSnapInTabletMode) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
std::unique_ptr<aura::Window> window = CreateAppWindow();
auto* window_state = WindowState::Get(window.get());
WindowSnapWMEvent event(WM_EVENT_SNAP_PRIMARY);
window_state->OnWMEvent(&event);
ASSERT_TRUE(window_state->IsSnapped());
window_state->Minimize();
window_state->Unminimize();
EXPECT_TRUE(window_state->IsSnapped());
}
// Check that a full screen window remains full screen upon entering maximize
// mode. Furthermore, checks that this window is not full screen upon exiting
// tablet mode if it was un-full-screened while in tablet mode.
TEST_F(TabletModeWindowManagerTest, KeepFullScreenModeOn) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
Shelf* shelf = GetPrimaryShelf();
// Allow the shelf to hide and set the pref.
SetShelfAutoHideBehaviorPref(GetPrimaryDisplay().id(),
ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event);
// With full screen, the shelf should get hidden.
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
CreateTabletModeWindowManager();
// The Full screen mode should continue to be on.
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
// When exiting fullscreen, tablet mode should still be enabled, and the shelf
// state should return to SHELF_AUTO_HIDE.
window_state->OnWMEvent(&event);
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
// The shelf auto-hide preference should be restored when exiting tablet mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
}
// Similar to the fullscreen mode, the pinned mode should be kept as well.
TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case1) {
// Scenario: in the default state, pin a window, enter to the tablet mode,
// then unpin.
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_FALSE(window_state->IsPinned());
// Pin the window.
{
WMEvent event(WM_EVENT_PIN);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Enter tablet mode. The pinned mode should continue to be on.
CreateTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Then unpin.
window_state->Restore();
EXPECT_FALSE(window_state->IsPinned());
// Exit tablet mode. The window should not be back to the pinned mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
}
TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case2) {
// Scenario: in the tablet mode, pin a window, exit tablet mode, then unpin.
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_FALSE(window_state->IsPinned());
// Enter tablet mode.
CreateTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
// Pin the window.
{
WMEvent event(WM_EVENT_PIN);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Exit tablet mode. The pinned mode should continue to be on.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Then unpin.
window_state->Restore();
EXPECT_FALSE(window_state->IsPinned());
// Enter tablet mode again for verification. The window should not be back to
// the pinned mode.
CreateTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
// Exit tablet mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
}
TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case3) {
// Scenario: in the default state, pin a window, enter to the tablet mode,
// exit from the tablet mode, then unpin.
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_FALSE(window_state->IsPinned());
// Pin the window.
{
WMEvent event(WM_EVENT_PIN);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Enter tablet mode. The pinned mode should continue to be on.
CreateTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Exit tablet mode. The pinned mode should continue to be on, too.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Then unpin.
window_state->Restore();
EXPECT_FALSE(window_state->IsPinned());
// Enter tablet mode again for verification. The window should not be back to
// the pinned mode.
CreateTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
// Exit tablet mode.
DestroyTabletModeWindowManager();
}
TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case4) {
// Scenario: in tablet mode, pin a window, exit tablet mode, enter tablet mode
// again, then unpin.
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_FALSE(window_state->IsPinned());
// Enter tablet mode.
CreateTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
// Pin the window.
{
WMEvent event(WM_EVENT_PIN);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Exit tablet mode. The pinned mode should continue to be on.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Enter tablet mode again. The pinned mode should continue to be on, too.
CreateTabletModeWindowManager();
EXPECT_TRUE(window_state->IsPinned());
// Then unpin.
window_state->Restore();
EXPECT_FALSE(window_state->IsPinned());
// Exit tablet mode. The window should not be back to the pinned mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
}
TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case5) {
std::unique_ptr<aura::Window> w1(CreateWindow(
aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(20, 140, 100, 100)));
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_FALSE(window_state->IsPinned());
CreateTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
// Pin the window.
{
WMEvent event(WM_EVENT_PIN);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Trigger ADDED_TO_WORKSPACE event.
{
WMEvent event(WM_EVENT_ADDED_TO_WORKSPACE);
window_state->OnWMEvent(&event);
}
EXPECT_TRUE(window_state->IsPinned());
// Then unpin.
window_state->Restore();
EXPECT_FALSE(window_state->IsPinned());
// Exit tablet mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsPinned());
}
// Verifies that if a window is un-full-screened while in tablet mode,
// other changes to that window's state (such as minimizing it) are
// preserved upon exiting tablet mode.
TEST_F(TabletModeWindowManagerTest, MinimizePreservedAfterLeavingFullscreen) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
Shelf* shelf = GetPrimaryShelf();
// Allow the shelf to hide and enter full screen.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event);
ASSERT_FALSE(window_state->IsMinimized());
// Enter tablet mode, exit full screen, and then minimize the window.
CreateTabletModeWindowManager();
window_state->OnWMEvent(&event);
window_state->Minimize();
ASSERT_TRUE(window_state->IsMinimized());
// The window should remain minimized when exiting tablet mode.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsMinimized());
}
// Tests that the auto-hide behavior is not affected when entering/exiting
// tablet mode.
TEST_F(TabletModeWindowManagerTest, DoNotDisableAutoHideBehaviorOnTabletMode) {
Shelf* shelf = GetPrimaryShelf();
SetShelfAutoHideBehaviorPref(GetPrimaryDisplay().id(),
ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(ShelfAutoHideBehavior::kAlways, shelf->auto_hide_behavior());
CreateTabletModeWindowManager();
EXPECT_EQ(ShelfAutoHideBehavior::kAlways, shelf->auto_hide_behavior());
DestroyTabletModeWindowManager();
EXPECT_EQ(ShelfAutoHideBehavior::kAlways, shelf->auto_hide_behavior());
}
// Check that full screen mode can be turned on in tablet mode and remains
// upon coming back.
TEST_F(TabletModeWindowManagerTest, AllowFullScreenMode) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
Shelf* shelf = GetPrimaryShelf();
// Allow the shelf to hide and set the pref.
SetShelfAutoHideBehaviorPref(GetPrimaryDisplay().id(),
ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
CreateTabletModeWindowManager();
// Fullscreen should stay off, and the shelf behavior is unmodified.
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
// After going into fullscreen mode, the shelf should be hidden.
WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event);
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
// With the destruction of the manager we should remain in full screen.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
}
// Check that the full screen mode will stay active when the tablet mode is
// ended.
TEST_F(TabletModeWindowManagerTest,
FullScreenModeRemainsWhenCreatedInTabletMode) {
CreateTabletModeWindowManager();
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
WMEvent event_full_screen(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event_full_screen);
EXPECT_TRUE(window_state->IsFullscreen());
// After the tablet mode manager is ended, full screen will remain.
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
}
// Check that the full screen mode will stay active throughout a maximzied mode
// session.
TEST_F(TabletModeWindowManagerTest,
FullScreenModeRemainsThroughTabletModeSwitch) {
gfx::Rect rect(20, 140, 100, 100);
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(w1.get());
WMEvent event_full_screen(WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event_full_screen);
EXPECT_TRUE(window_state->IsFullscreen());
CreateTabletModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
DestroyTabletModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
}
// Check that an empty window does not get restored to a tiny size.
TEST_F(TabletModeWindowManagerTest,
CreateAndMaximizeInTabletModeShouldRetoreToGoodSizeGoingToDefault) {
CreateTabletModeWindowManager();
gfx::Rect rect;
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
w1->Show();
WindowState* window_state = WindowState::Get(w1.get());
EXPECT_TRUE(window_state->IsMaximized());
// There is a calling order in which the restore bounds can get set to an
// empty rectangle. We simulate this here.
window_state->SetRestoreBoundsInScreen(rect);
EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());
// Setting the window to a new size will physically not change the window,
// but the restore size should get updated so that a restore later on will
// return to this size.
gfx::Rect requested_bounds(10, 20, 50, 70);
w1->SetBounds(requested_bounds);
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(requested_bounds.ToString(),
window_state->GetRestoreBoundsInScreen().ToString());
DestroyTabletModeWindowManager();
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
}
// Check that non maximizable windows cannot be dragged by the user.
TEST_F(TabletModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
gfx::Rect rect(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
EXPECT_EQ(rect.ToString(), window->bounds().ToString());
// 1. Move the mouse over the caption and check that dragging the window does
// change the location.
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.MoveMouseTo(gfx::Point(rect.x() + 2, rect.y() + 2));
generator.PressLeftButton();
generator.MoveMouseBy(10, 5);
base::RunLoop().RunUntilIdle();
generator.ReleaseLeftButton();
gfx::Point first_dragged_origin = window->bounds().origin();
EXPECT_EQ(rect.x() + 10, first_dragged_origin.x());
EXPECT_EQ(rect.y() + 5, first_dragged_origin.y());
// 2. Check that turning on the manager will stop allowing the window from
// dragging.
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
gfx::Rect center_bounds(window->bounds());
EXPECT_NE(rect.origin().ToString(), center_bounds.origin().ToString());
generator.MoveMouseTo(
gfx::Point(center_bounds.x() + 1, center_bounds.y() + 1));
generator.PressLeftButton();
generator.MoveMouseBy(10, 5);
base::RunLoop().RunUntilIdle();
generator.ReleaseLeftButton();
EXPECT_EQ(center_bounds.x(), window->bounds().x());
EXPECT_EQ(center_bounds.y(), window->bounds().y());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
// 3. Releasing the mazimize manager again will restore the window to its
// previous bounds and
generator.MoveMouseTo(
gfx::Point(first_dragged_origin.x() + 1, first_dragged_origin.y() + 1));
generator.PressLeftButton();
generator.MoveMouseBy(10, 5);
base::RunLoop().RunUntilIdle();
generator.ReleaseLeftButton();
EXPECT_EQ(first_dragged_origin.x() + 10, window->bounds().x());
EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y());
}
// Tests that windows with the always-on-top property are not managed by
// the TabletModeWindowManager while tablet mode is engaged (i.e.,
// they remain free-floating).
TEST_F(TabletModeWindowManagerTest, AlwaysOnTopWindows) {
gfx::Rect rect1(10, 10, 200, 50);
gfx::Rect rect2(20, 140, 100, 100);
// Create two windows with the always-on-top property.
std::unique_ptr<aura::Window> w1(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1));
std::unique_ptr<aura::Window> w2(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect2));
w1->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
w2->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
// Enter tablet mode. Neither window should be managed because they have
// the always-on-top property set, which means that none of their properties
// should change.
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
// Remove the always-on-top property from both windows while in maximize
// mode. The windows should become managed, which means they should be
// maximized/centered and no longer be draggable.
w1->SetProperty(aura::client::kZOrderingKey, ui::ZOrderLevel::kNormal);
w2->SetProperty(aura::client::kZOrderingKey, ui::ZOrderLevel::kNormal);
EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_NE(rect1.origin().ToString(), w1->bounds().origin().ToString());
EXPECT_NE(rect1.size().ToString(), w1->bounds().size().ToString());
EXPECT_NE(rect2.origin().ToString(), w2->bounds().origin().ToString());
EXPECT_EQ(rect2.size().ToString(), w2->bounds().size().ToString());
// Applying the always-on-top property to both windows while in maximize
// mode should cause both windows to return to their original size,
// position, and state.
w1->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
w2->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
// The always-on-top windows should not change when leaving tablet mode.
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(w1.get())->IsMaximized());
EXPECT_FALSE(WindowState::Get(w2.get())->IsMaximized());
EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
}
// Tests that windows that can control maximized bounds are not maximized
// and not tracked.
TEST_F(TabletModeWindowManagerTest, DontMaximizeClientManagedWindows) {
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState::Get(window.get())->set_allow_set_bounds_direct(true);
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(window.get())->IsMaximized());
EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
}
// Verify that if tablet mode is started in the lock screen, windows will still
// be maximized after leaving the lock screen.
TEST_F(TabletModeWindowManagerTest, CreateManagerInLockScreen) {
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
ASSERT_FALSE(WindowState::Get(window.get())->IsMaximized());
// Create the tablet mode window manager while inside the lock screen.
GetSessionControllerClient()->RequestLockScreen();
CreateTabletModeWindowManager();
GetSessionControllerClient()->UnlockScreen();
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
DestroyTabletModeWindowManager();
EXPECT_FALSE(WindowState::Get(window.get())->IsMaximized());
}
namespace {
class TestObserver : public WindowStateObserver {
public:
TestObserver() = default;
TestObserver(const TestObserver&) = delete;
TestObserver& operator=(const TestObserver&) = delete;
~TestObserver() override = default;
// WindowStateObserver:
void OnPreWindowStateTypeChange(WindowState* window_state,
WindowStateType old_type) override {
pre_count_++;
last_old_state_ = old_type;
}
void OnPostWindowStateTypeChange(WindowState* window_state,
WindowStateType old_type) override {
post_count_++;
post_layer_visibility_ = window_state->window()->layer()->visible();
EXPECT_EQ(last_old_state_, old_type);
}
int GetPreCountAndReset() {
int r = pre_count_;
pre_count_ = 0;
return r;
}
int GetPostCountAndReset() {
int r = post_count_;
post_count_ = 0;
return r;
}
bool GetPostLayerVisibilityAndReset() {
bool r = post_layer_visibility_;
post_layer_visibility_ = false;
return r;
}
WindowStateType GetLastOldStateAndReset() {
WindowStateType r = last_old_state_;
last_old_state_ = WindowStateType::kDefault;
return r;
}
private:
int pre_count_ = 0;
int post_count_ = 0;
bool post_layer_visibility_ = false;
WindowStateType last_old_state_ = WindowStateType::kDefault;
};
} // namespace
TEST_F(TabletModeWindowManagerTest, StateTypeChange) {
TestObserver observer;
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
CreateTabletModeWindowManager();
WindowState* window_state = WindowState::Get(window.get());
window_state->AddObserver(&observer);
window->Show();
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(0, observer.GetPreCountAndReset());
EXPECT_EQ(0, observer.GetPostCountAndReset());
// Window is already in tablet mode.
WMEvent maximize_event(WM_EVENT_MAXIMIZE);
window_state->OnWMEvent(&maximize_event);
EXPECT_EQ(0, observer.GetPreCountAndReset());
EXPECT_EQ(0, observer.GetPostCountAndReset());
WMEvent fullscreen_event(WM_EVENT_FULLSCREEN);
window_state->OnWMEvent(&fullscreen_event);
EXPECT_EQ(1, observer.GetPreCountAndReset());
EXPECT_EQ(1, observer.GetPostCountAndReset());
EXPECT_EQ(WindowStateType::kMaximized, observer.GetLastOldStateAndReset());
window_state->OnWMEvent(&maximize_event);
EXPECT_EQ(1, observer.GetPreCountAndReset());
EXPECT_EQ(1, observer.GetPostCountAndReset());
EXPECT_EQ(WindowStateType::kFullscreen, observer.GetLastOldStateAndReset());
WMEvent minimize_event(WM_EVENT_MINIMIZE);
window_state->OnWMEvent(&minimize_event);
EXPECT_EQ(1, observer.GetPreCountAndReset());
EXPECT_EQ(1, observer.GetPostCountAndReset());
EXPECT_EQ(WindowStateType::kMaximized, observer.GetLastOldStateAndReset());
WMEvent restore_event(WM_EVENT_NORMAL);
window_state->OnWMEvent(&restore_event);
EXPECT_EQ(1, observer.GetPreCountAndReset());
EXPECT_EQ(1, observer.GetPostCountAndReset());
EXPECT_EQ(WindowStateType::kMinimized, observer.GetLastOldStateAndReset());
EXPECT_EQ(true, observer.GetPostLayerVisibilityAndReset());
window_state->RemoveObserver(&observer);
DestroyTabletModeWindowManager();
}
// Test that the restore state will be kept at its original value for
// session restoration purposes.
TEST_F(TabletModeWindowManagerTest, SetPropertyOnUnmanagedWindow) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
InitParams params(aura::client::WINDOW_TYPE_NORMAL);
params.bounds = gfx::Rect(10, 10, 100, 100);
params.show_on_creation = false;
std::unique_ptr<aura::Window> window(CreateWindowInWatchedContainer(params));
WindowState::Get(window.get())->set_allow_set_bounds_direct(true);
window->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
window->Show();
}
// Test that the minimized window bounds doesn't change until it's unminimized.
TEST_F(TabletModeWindowManagerTest, DontChangeBoundsForMinimizedWindow) {
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
window_state->Minimize();
EXPECT_TRUE(window_state->IsMinimized());
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
ASSERT_TRUE(manager);
EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
EXPECT_TRUE(window_state->IsMinimized());
EXPECT_EQ(window->bounds(), rect);
EnterOverview();
EXPECT_EQ(window->bounds(), rect);
// Exit overview mode will update all windows' bounds. However, if the window
// is minimized, the bounds will not be updated.
ExitOverview();
EXPECT_EQ(window->bounds(), rect);
}
// Make sure that transient children should not be maximized.
TEST_F(TabletModeWindowManagerTest, DontMaximizeTransientChild) {
gfx::Rect rect(0, 0, 200, 200);
std::unique_ptr<aura::Window> parent(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
std::unique_ptr<aura::Window> child(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
::wm::TransientWindowManager::GetOrCreate(parent.get())
->AddTransientChild(child.get());
ASSERT_TRUE(CreateTabletModeWindowManager());
EXPECT_TRUE(WindowState::Get(parent.get())->IsMaximized());
EXPECT_NE(rect.size(), parent->bounds().size());
EXPECT_FALSE(WindowState::Get(child.get())->IsMaximized());
EXPECT_EQ(rect.size(), child->bounds().size());
}
TEST_F(TabletModeWindowManagerTest, AllowNormalWindowBoundsChangeByVK) {
UpdateDisplay("1200x800");
gfx::Rect rect(0, 0, 1200, 600);
std::unique_ptr<aura::Window> window(CreateFixedSizeNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect));
ASSERT_TRUE(CreateTabletModeWindowManager());
WindowState* window_state = WindowState::Get(window.get());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(WindowStateType::kNormal, window_state->GetStateType());
gfx::Rect window_bounds = window->bounds();
// Simulate VK up.
wm::EnsureWindowNotInRect(window.get(), gfx::Rect(0, 600, 1200, 200));
EXPECT_NE(window->bounds(), window_bounds);
// Simulate VK dismissal.
wm::RestoreWindowBoundsOnClientFocusLost(window.get());
EXPECT_EQ(window->bounds(), window_bounds);
}
// Test clamshell mode <-> tablet mode transition.
// TODO(b/327269057): Refactor this to `SplitViewController|SnapGroup`.
TEST_F(TabletModeWindowManagerTest, ClamshellTabletTransitionTest) {
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
// 1. Clamshell -> tablet. If overview is active, it should still be kept
// active after transition.
OverviewController* overview_controller = OverviewController::Get();
EXPECT_TRUE(EnterOverview());
EXPECT_TRUE(overview_controller->InOverviewSession());
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
EXPECT_TRUE(manager);
EXPECT_TRUE(overview_controller->InOverviewSession());
// 2. Tablet -> Clamshell. If overview is active, it should still be kept
// active after transition.
DestroyTabletModeWindowManager();
EXPECT_TRUE(overview_controller->InOverviewSession());
// 3. Clamshell -> tablet. If overview is inactive, it should still be kept
// inactive after transition. All windows will be maximized.
EXPECT_TRUE(ExitOverview());
EXPECT_FALSE(overview_controller->InOverviewSession());
CreateTabletModeWindowManager();
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
// 4. Tablet -> Clamshell. The window should be restored to its old state.
DestroyTabletModeWindowManager();
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(WindowState::Get(window.get())->IsMaximized());
// 5. Clamshell -> Tablet. If the window is snapped, it will be carried over
// to splitview in tablet mode.
const WindowSnapWMEvent event(WM_EVENT_SNAP_PRIMARY);
WindowState::Get(window.get())->OnWMEvent(&event);
EXPECT_TRUE(WindowState::Get(window.get())->IsSnapped());
// After transition, we should be in single split screen.
CreateTabletModeWindowManager();
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(WindowState::Get(window.get())->IsSnapped());
// 6. Tablet -> Clamshell. Since there is only 1 window, splitview and
// overview will be both ended. The window will be kept snapped.
DestroyTabletModeWindowManager();
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(WindowState::Get(window.get())->IsSnapped());
// Create another normal state window to test additional scenarios.
std::unique_ptr<aura::Window> window2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
wm::ActivateWindow(window2.get());
// 7. Clamshell -> Tablet. Since top window is not a snapped window, all
// windows will be maximized.
CreateTabletModeWindowManager();
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
EXPECT_TRUE(WindowState::Get(window2.get())->IsMaximized());
// 8. Tablet -> Clamshell. If tablet splitscreen is active with two snapped
// windows, the two windows will remain snapped in clamshell mode.
split_view_controller()->SnapWindow(window.get(), SnapPosition::kPrimary);
split_view_controller()->SnapWindow(window2.get(), SnapPosition::kSecondary);
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_FALSE(overview_controller->InOverviewSession());
DestroyTabletModeWindowManager();
EXPECT_TRUE(WindowState::Get(window.get())->IsSnapped());
EXPECT_TRUE(WindowState::Get(window2.get())->IsSnapped());
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
EXPECT_FALSE(overview_controller->InOverviewSession());
// 9. Clamshell -> Tablet. If two window are snapped to two sides of the
// screen, they will carry over to splitscreen in tablet mode.
CreateTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_TRUE(WindowState::Get(window.get())->IsSnapped());
EXPECT_TRUE(WindowState::Get(window2.get())->IsSnapped());
// 10. Tablet -> Clamshell. If overview and splitview are both active, after
// transition, they will remain both active.
EnterOverview();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession());
DestroyTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession());
// 11. Clamshell -> Tablet. The same as 10.
CreateTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession());
}
// Test the divider position value during tablet <-> clamshell transition.
TEST_F(TabletModeWindowManagerTest,
ClamshellTabletTransitionDividerPositionTest) {
UpdateDisplay("1200x800");
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
OverviewController* overview_controller = OverviewController::Get();
// First test 1 window case.
const WindowSnapWMEvent left_snap_event(WM_EVENT_SNAP_PRIMARY);
WindowState::Get(window.get())->OnWMEvent(&left_snap_event);
const gfx::Rect left_snapped_bounds =
gfx::Rect(1200 / 2, 800 - ShelfConfig::Get()->shelf_size());
EXPECT_EQ(window->bounds().width(), left_snapped_bounds.width());
// Change its bounds horizontally a bit and then enter tablet mode.
window->SetBounds(gfx::Rect(400, left_snapped_bounds.height()));
CreateTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window.get()));
// Check the window is moved to 1/3 snapped position.
EXPECT_EQ(window->bounds().width(),
std::round(1200 * chromeos::kOneThirdSnapRatio) -
kSplitviewDividerShortSideLength / 2);
// Exit tablet mode and verify the window stays near the same position.
DestroyTabletModeWindowManager();
EXPECT_NEAR(window->bounds().width(),
std::round(1200 * chromeos::kOneThirdSnapRatio),
kSplitviewDividerShortSideLength / 2);
// Now test the 2 windows case.
std::unique_ptr<aura::Window> window2(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState::Get(window.get())->OnWMEvent(&left_snap_event);
const WindowSnapWMEvent right_snap_event(WM_EVENT_SNAP_SECONDARY);
WindowState::Get(window2.get())->OnWMEvent(&right_snap_event);
// Change their bounds horizontally and then enter tablet mode.
window->SetBounds(gfx::Rect(400, left_snapped_bounds.height()));
window2->SetBounds(gfx::Rect(400, 0, 800, left_snapped_bounds.height()));
CreateTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window.get()));
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get()));
// Check |window| and |window2| is moved to 1/3 snapped position.
EXPECT_EQ(window->bounds().width(),
std::round(1200 * chromeos::kOneThirdSnapRatio) -
kSplitviewDividerShortSideLength / 2);
EXPECT_EQ(window2->bounds().width(),
1200 - window->bounds().width() - kSplitviewDividerShortSideLength);
// Exit tablet mode and verify the windows stay near the same position.
DestroyTabletModeWindowManager();
EXPECT_NEAR(window->bounds().width(),
std::round(1200 * chromeos::kOneThirdSnapRatio),
kSplitviewDividerShortSideLength / 2);
EXPECT_NEAR(window2->bounds().width(), 1200 - window->bounds().width(),
kSplitviewDividerShortSideLength / 2);
}
// Tests partial split clamshell <-> tablet transition.
TEST_F(TabletModeWindowManagerTest, PartialClamshellTabletTransitionTest) {
// 1. Create a window and snap to primary 2/3.
auto window1 = CreateTestWindow();
OverviewController* overview_controller = OverviewController::Get();
const WindowSnapWMEvent snap_primary_two_third(WM_EVENT_SNAP_PRIMARY,
chromeos::kTwoThirdSnapRatio);
WindowState::Get(window1.get())->OnWMEvent(&snap_primary_two_third);
// Enter tablet mode and verify that overview opens and the window and
// divider are at 2/3.
CreateTabletModeWindowManager();
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window1.get()));
const gfx::Rect work_area_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
int divider_origin_x = split_view_controller()
->split_view_divider()
->GetDividerBoundsInScreen(
/*is_dragging=*/false)
.x();
int divider_delta = kSplitviewDividerShortSideLength / 2;
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio),
window1->bounds().width() + divider_delta);
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio),
divider_origin_x + divider_delta);
// Exit tablet mode and verify the window stays in the same position.
DestroyTabletModeWindowManager();
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio),
window1->bounds().width());
// 2. Create another window and snap to secondary at 1/3.
auto window2 = CreateTestWindow();
const WindowSnapWMEvent snap_secondary_one_third(
WM_EVENT_SNAP_SECONDARY, chromeos::kOneThirdSnapRatio);
WindowState::Get(window2.get())->OnWMEvent(&snap_secondary_one_third);
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kOneThirdSnapRatio),
window2->bounds().width());
// Enter tablet mode and verify the windows are in splitview and the window
// bounds and divider are at 2/3.
CreateTabletModeWindowManager();
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window1.get()));
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get()));
divider_origin_x = split_view_controller()
->split_view_divider()
->GetDividerBoundsInScreen(
/*is_dragging=*/false)
.x();
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio),
window1->bounds().width() + divider_delta);
EXPECT_EQ(std::round(work_area_bounds.width() * chromeos::kOneThirdSnapRatio),
window2->bounds().width() + divider_delta);
EXPECT_EQ(
std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio) -
divider_delta,
divider_origin_x);
// Exit tablet mode and verify the windows are still at 2/3, with allowance
// for the divider width since it is only there in tablet mode.
DestroyTabletModeWindowManager();
if (!display::Screen::GetScreen()->InTabletMode()) {
EXPECT_NEAR(
std::round(work_area_bounds.width() * chromeos::kTwoThirdSnapRatio),
window1->bounds().width(), divider_delta);
EXPECT_NEAR(
std::round(work_area_bounds.width() * chromeos::kOneThirdSnapRatio),
window2->bounds().width(), divider_delta);
} else {
EXPECT_EQ(
std::round(work_area_bounds.width() * chromeos::kOneThirdSnapRatio),
window2->bounds().width() + divider_delta);
}
}
// Test that when switching from clamshell mode to tablet mode, if overview mode
// is active, home launcher is hidden. And after overview mode is dismissed,
// home launcher will be shown again.
TEST_F(TabletModeWindowManagerTest, HomeLauncherVisibilityTest) {
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
// Clamshell -> Tablet mode transition. If overview is active, it will remain
// in overview.
OverviewController* overview_controller = OverviewController::Get();
EXPECT_TRUE(EnterOverview());
EXPECT_TRUE(overview_controller->InOverviewSession());
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
EXPECT_TRUE(manager);
EXPECT_TRUE(overview_controller->InOverviewSession());
ShellTestApi().WaitForOverviewAnimationState(
OverviewAnimationState::kEnterAnimationComplete);
aura::Window* home_screen_window =
Shell::Get()->app_list_controller()->GetHomeScreenWindow();
EXPECT_FALSE(home_screen_window->TargetVisibility());
base::HistogramTester tester;
tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kHotseatHiddenDueToInteractionOutsideOfShelf, 0);
// Tap at window to leave the overview mode.
GetEventGenerator()->GestureTapAt(window->GetBoundsInScreen().CenterPoint());
ShellTestApi().WaitForOverviewAnimationState(
OverviewAnimationState::kExitAnimationComplete);
tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kHotseatHiddenDueToInteractionOutsideOfShelf, 0);
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_TRUE(home_screen_window->TargetVisibility());
}
// Test the basic restore behavior in tablet mode. Different with the restore
// behavior in clamshell mode, a window can not be restored to kNormal window
// state if it's maximizable.
TEST_F(TabletModeWindowManagerTest, BasicRestoreBehaviors) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
EXPECT_TRUE(manager);
gfx::Rect rect(10, 10, 200, 50);
std::unique_ptr<aura::Window> window(
CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect));
WindowState* window_state = WindowState::Get(window.get());
EXPECT_TRUE(window_state->IsMaximized());
// Restoring a maximized window in tablet mode will still keep it in maximized
// state.
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
// Transition to kPrimarySnapped window state.
const WindowSnapWMEvent snap_left(WM_EVENT_SNAP_PRIMARY);
window_state->OnWMEvent(&snap_left);
// Restoring a snapped window in tablet mode will change the window back to
// maximized window state.
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
// Transition to kFullscreen window state.
const WMEvent fullscreen_event(WM_EVENT_FULLSCREEN);
window_state->OnWMEvent(&fullscreen_event);
// Restoring a fullscreen window in tablet mode will change the window back to
// maximized window state.
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
// Transition to kMinimized window state.
const WMEvent minimized_event(WM_EVENT_MINIMIZE);
window_state->OnWMEvent(&minimized_event);
window_state->Restore();
EXPECT_TRUE(window_state->IsMaximized());
// Transition to kPrimarySnapped first and then to kFullscreen and then try to
// restore it.
window_state->OnWMEvent(&snap_left);
window_state->OnWMEvent(&fullscreen_event);
window_state->Restore();
EXPECT_TRUE(window_state->IsSnapped());
// Minimize and then restore it will still restore the window back to snapped
// window state.
window_state->OnWMEvent(&minimized_event);
window_state->Restore();
EXPECT_TRUE(window_state->IsSnapped());
}
TEST_F(TabletModeWindowManagerTest, NonMaximizableWindowRestore) {
TabletModeWindowManager* manager = CreateTabletModeWindowManager();
EXPECT_TRUE(manager);
gfx::Rect rect(10, 10, 200, 50);
gfx::Size max_size(300, 200);
std::unique_ptr<aura::Window> window(CreateNonMaximizableWindow(
aura::client::WINDOW_TYPE_NORMAL, rect, max_size));
WindowState* window_state = WindowState::Get(window.get());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(window_state->GetStateType(), WindowStateType::kNormal);
const WMEvent maximize_event(WM_EVENT_MAXIMIZE);
window_state->OnWMEvent(&maximize_event);
EXPECT_EQ(window_state->GetStateType(), WindowStateType::kNormal);
const WMEvent fullscreen_event(WM_EVENT_FULLSCREEN);
window_state->OnWMEvent(&fullscreen_event);
EXPECT_EQ(window_state->GetStateType(), WindowStateType::kFullscreen);
window_state->Restore();
EXPECT_EQ(window_state->GetStateType(), WindowStateType::kNormal);
// Restoring a kNormal window will keep it in the same kNormal state.
window_state->Restore();
EXPECT_EQ(window_state->GetStateType(), WindowStateType::kNormal);
}
} // namespace ash