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
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/base/view_event_test_base.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/test/test_browser_thread.h"
#include "ui/aura/env.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/window.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/test/ui_controls.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/widget/widget.h"
#if defined(OS_WIN)
#include "ui/aura/window_tree_host.h"
#endif
using base::ASCIIToUTF16;
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
using content::BrowserThread;
using content::OpenURLParams;
using content::PageNavigator;
using content::WebContents;
namespace {
// Waits for a views::Widget dialog to show up.
class DialogWaiter : public aura::EnvObserver,
public views::WidgetObserver {
public:
DialogWaiter()
: dialog_created_(false),
dialog_(NULL) {
aura::Env::GetInstance()->AddObserver(this);
}
~DialogWaiter() override { aura::Env::GetInstance()->RemoveObserver(this); }
views::Widget* WaitForDialog() {
if (dialog_created_)
return dialog_;
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
return dialog_;
}
private:
// aura::EnvObserver:
void OnWindowInitialized(aura::Window* window) override {
if (dialog_)
return;
views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
if (!widget || !widget->IsDialogBox())
return;
dialog_ = widget;
dialog_->AddObserver(this);
}
// views::WidgetObserver:
void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override {
CHECK_EQ(dialog_, widget);
if (visible) {
dialog_created_ = true;
dialog_->RemoveObserver(this);
if (!quit_closure_.is_null())
quit_closure_.Run();
}
}
bool dialog_created_;
views::Widget* dialog_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(DialogWaiter);
};
// Waits for a dialog to terminate.
class DialogCloseWaiter : public views::WidgetObserver {
public:
explicit DialogCloseWaiter(views::Widget* dialog)
: dialog_closed_(false) {
dialog->AddObserver(this);
}
~DialogCloseWaiter() override {
// It is not necessary to remove |this| from the dialog's observer, since
// the dialog is destroyed before this waiter.
}
void WaitForDialogClose() {
if (dialog_closed_)
return;
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
}
private:
// views::WidgetObserver:
void OnWidgetDestroyed(views::Widget* widget) override {
dialog_closed_ = true;
if (!quit_closure_.is_null())
quit_closure_.Run();
}
bool dialog_closed_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(DialogCloseWaiter);
};
// Waits for a views::Widget to receive a Tab key.
class TabKeyWaiter : public ui::EventHandler {
public:
explicit TabKeyWaiter(views::Widget* widget)
: widget_(widget),
received_tab_(false) {
widget_->GetNativeView()->AddPreTargetHandler(this);
}
~TabKeyWaiter() override {
widget_->GetNativeView()->RemovePreTargetHandler(this);
}
void WaitForTab() {
if (received_tab_)
return;
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
}
private:
// ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* event) override {
if (event->type() == ui::ET_KEY_RELEASED &&
event->key_code() == ui::VKEY_TAB) {
received_tab_ = true;
if (!quit_closure_.is_null())
quit_closure_.Run();
}
}
views::Widget* widget_;
bool received_tab_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(TabKeyWaiter);
};
void MoveMouseAndPress(const gfx::Point& screen_pos,
ui_controls::MouseButton button,
int state,
const base::Closure& closure) {
ASSERT_TRUE(ui_controls::SendMouseMove(screen_pos.x(), screen_pos.y()));
ASSERT_TRUE(
ui_controls::SendMouseEventsNotifyWhenDone(button, state, closure));
}
// PageNavigator implementation that records the URL.
class TestingPageNavigator : public PageNavigator {
public:
TestingPageNavigator() {}
~TestingPageNavigator() override {}
WebContents* OpenURL(const OpenURLParams& params) override {
urls_.push_back(params.url);
return NULL;
}
const std::vector<GURL>& urls() const { return urls_; }
GURL last_url() const { return urls_.empty() ? GURL() : urls_.back(); }
private:
std::vector<GURL> urls_;
DISALLOW_COPY_AND_ASSIGN(TestingPageNavigator);
};
// TODO(erg): Fix bookmark DND tests on linux_aura. crbug.com/163931
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE(x) DISABLED_##x
#else
#define MAYBE(x) x
#endif
} // namespace
// Base class for event generating bookmark view tests. These test are intended
// to exercise View's menus, but that's easier done with BookmarkBarView rather
// than View's menu itself.
//
// SetUp creates a bookmark model with the following structure.
// All folders are in upper case, all URLs in lower case.
// F1
// f1a
// F11
// f11a
// f1b
// *
// a
// b
// c
// d
// F2
// e
// OTHER
// oa
// OF
// ofa
// ofb
// OF2
// of2a
// of2b
//
// * if CreateBigMenu returns return true, 100 menu items are created here with
// the names f1-f100.
//
// Subclasses should be sure and invoke super's implementation of SetUp and
// TearDown.
class BookmarkBarViewEventTestBase : public ViewEventTestBase {
public:
BookmarkBarViewEventTestBase()
: ViewEventTestBase(),
model_(NULL) {}
void SetUp() override {
content_client_.reset(new ChromeContentClient);
content::SetContentClient(content_client_.get());
browser_content_client_.reset(new ChromeContentBrowserClient());
content::SetBrowserClientForTesting(browser_content_client_.get());
views::MenuController::TurnOffMenuSelectionHoldForTest();
BookmarkBarView::DisableAnimationsForTesting(true);
SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient());
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
model_ = BookmarkModelFactory::GetForProfile(profile_.get());
bookmarks::test::WaitForBookmarkModelToLoad(model_);
profile_->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
Browser::CreateParams native_params(profile_.get());
browser_ = chrome::CreateBrowserWithTestWindowForParams(&native_params);
local_state_.reset(new ScopedTestingLocalState(
TestingBrowserProcess::GetGlobal()));
model_->ClearStore();
bb_view_.reset(new BookmarkBarView(browser_.get(), NULL));
bb_view_->set_owned_by_client();
bb_view_->SetPageNavigator(&navigator_);
AddTestData(CreateBigMenu());
// Create the Widget. Note the initial size is given by GetPreferredSize()
// during initialization. This occurs after the WidgetDelegate provides
// |bb_view_| as the contents view and adds it to the hierarchy.
ViewEventTestBase::SetUp();
// Verify the layout triggered by the initial size preserves the overflow
// state calculated in GetPreferredSize().
EXPECT_TRUE(GetBookmarkButton(5)->visible());
EXPECT_FALSE(GetBookmarkButton(6)->visible());
}
void TearDown() override {
// Destroy everything, then run the message loop to ensure we delete all
// Tasks and fully shut down.
browser_->tab_strip_model()->CloseAllTabs();
bb_view_.reset();
browser_.reset();
profile_.reset();
// Run the message loop to ensure we delete allTasks and fully shut down.
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
base::RunLoop run_loop;
loop->task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run();
ViewEventTestBase::TearDown();
BookmarkBarView::DisableAnimationsForTesting(false);
constrained_window::SetConstrainedWindowViewsClient(nullptr);
browser_content_client_.reset();
content_client_.reset();
content::SetContentClient(NULL);
}
protected:
views::View* CreateContentsView() override { return bb_view_.get(); }
gfx::Size GetPreferredSize() const override {
// Calculate the preferred size so that one button doesn't fit, which
// triggers the overflow button to appear. We have to do this incrementally
// as there isn't a good way to determine the point at which the overflow
// button is shown.
//
// This code looks a bit hacky, but it is written so that it shouldn't
// depend on any of the layout code in BookmarkBarView, or extra buttons
// added to the right of the bookmarks. Instead, brute force search for a
// size that triggers the overflow button.
gfx::Size size = bb_view_->GetPreferredSize();
size.set_width(1000);
do {
size.set_width(size.width() - 25);
bb_view_->SetBounds(0, 0, size.width(), size.height());
bb_view_->Layout();
} while (bb_view_->GetBookmarkButton(6)->visible());
return size;
}
views::LabelButton* GetBookmarkButton(int view_index) {
return bb_view_->GetBookmarkButton(view_index);
}
// See comment above class description for what this does.
virtual bool CreateBigMenu() { return false; }
BookmarkModel* model_;
scoped_ptr<BookmarkBarView> bb_view_;
TestingPageNavigator navigator_;
private:
void AddTestData(bool big_menu) {
const BookmarkNode* bb_node = model_->bookmark_bar_node();
std::string test_base = "file:///c:/tmp/";
const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1"));
model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a"));
const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11"));
model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a"));
model_->AddURL(f1, 2, ASCIIToUTF16("f1b"), GURL(test_base + "f1b"));
if (big_menu) {
for (int i = 1; i <= 100; ++i) {
model_->AddURL(f1, i + 1, ASCIIToUTF16("f") + base::IntToString16(i),
GURL(test_base + "f" + base::IntToString(i)));
}
}
model_->AddURL(bb_node, 1, ASCIIToUTF16("a"), GURL(test_base + "a"));
model_->AddURL(bb_node, 2, ASCIIToUTF16("b"), GURL(test_base + "b"));
model_->AddURL(bb_node, 3, ASCIIToUTF16("c"), GURL(test_base + "c"));
model_->AddURL(bb_node, 4, ASCIIToUTF16("d"), GURL(test_base + "d"));
model_->AddFolder(bb_node, 5, ASCIIToUTF16("F2"));
model_->AddURL(bb_node, 6, ASCIIToUTF16("d"), GURL(test_base + "d"));
model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("oa"),
GURL(test_base + "oa"));
const BookmarkNode* of = model_->AddFolder(model_->other_node(), 1,
ASCIIToUTF16("OF"));
model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa"));
model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb"));
const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2,
ASCIIToUTF16("OF2"));
model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a"));
model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b"));
}
scoped_ptr<ChromeContentClient> content_client_;
scoped_ptr<ChromeContentBrowserClient> browser_content_client_;
scoped_ptr<TestingProfile> profile_;
scoped_ptr<Browser> browser_;
scoped_ptr<ScopedTestingLocalState> local_state_;
};
// Clicks on first menu, makes sure button is depressed. Moves mouse to first
// child, clicks it and makes sure a navigation occurs.
class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest1::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Button should be depressed.
views::LabelButton* button = GetBookmarkButton(0);
ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED);
// Click on the 2nd menu item (A URL).
ASSERT_TRUE(menu->GetSubmenu());
views::MenuItemView* menu_to_select =
menu->GetSubmenu()->GetMenuItemAt(0);
ui_test_utils::MoveMouseToCenterAndPress(menu_to_select, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest1::Step3));
}
void Step3() {
// We should have navigated to URL f1a.
ASSERT_EQ(navigator_.last_url(),
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url());
// Make sure button is no longer pushed.
views::LabelButton* button = GetBookmarkButton(0);
ASSERT_TRUE(button->state() == views::CustomButton::STATE_NORMAL);
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing());
Done();
}
};
VIEW_TEST(BookmarkBarViewTest1, Basic)
// Brings up menu, clicks on empty space and make sure menu hides.
class BookmarkBarViewTest2 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest2::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL && menu->GetSubmenu()->IsShowing());
// Click on 0x0, which should trigger closing menu.
// NOTE: this code assume there is a left margin, which is currently
// true. If that changes, this code will need to find another empty space
// to press the mouse on.
gfx::Point mouse_loc;
views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
0, 0, CreateEventTask(this, &BookmarkBarViewTest2::Step3)));
}
void Step3() {
// As the click is on the desktop the hook never sees the up, so we only
// wait on the down. We still send the up though else the system thinks
// the mouse is still down.
ASSERT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest2::Step4)));
ASSERT_TRUE(
ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::UP));
}
void Step4() {
// The menu shouldn't be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing());
// Make sure button is no longer pushed.
views::LabelButton* button = GetBookmarkButton(0);
ASSERT_TRUE(button->state() == views::CustomButton::STATE_NORMAL);
Done();
}
};
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_HideOnDesktopClick DISABLED_HideOnDesktopClick
#else
#define MAYBE_HideOnDesktopClick HideOnDesktopClick
#endif
VIEW_TEST(BookmarkBarViewTest2, MAYBE_HideOnDesktopClick)
// Brings up menu. Moves over child to make sure submenu appears, moves over
// another child and make sure next menu appears.
class BookmarkBarViewTest3 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::MenuButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest3::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
// Click on second child, which has a submenu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest3::Step3));
}
void Step3() {
// Make sure sub menu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu->GetSubmenu() != NULL);
ASSERT_TRUE(child_menu->GetSubmenu()->IsShowing());
// Click on third child, which has a submenu too.
child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest3::Step4));
}
void Step4() {
// Make sure sub menu we first clicked isn't showing.
views::MenuItemView* menu = bb_view_->GetMenu();
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu->GetSubmenu() != NULL);
ASSERT_FALSE(child_menu->GetSubmenu()->IsShowing());
// And submenu we last clicked is showing.
child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL);
ASSERT_TRUE(child_menu->GetSubmenu()->IsShowing());
// Nothing should have been selected.
EXPECT_EQ(GURL(), navigator_.last_url());
// Hide menu.
menu->GetMenuController()->CancelAll();
Done();
}
};
VIEW_TEST(BookmarkBarViewTest3, Submenus)
// Observer that posts task upon the context menu creation.
// This is necessary for Linux as the context menu has to check
// the clipboard, which invokes the event loop.
class BookmarkContextMenuNotificationObserver
: public content::NotificationObserver {
public:
explicit BookmarkContextMenuNotificationObserver(const base::Closure& task)
: task_(task) {
registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN,
content::NotificationService::AllSources());
}
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override {
base::MessageLoop::current()->task_runner()->PostTask(FROM_HERE, task_);
}
// Sets the task that is posted when the context menu is shown.
void set_task(const base::Closure& task) { task_ = task; }
private:
content::NotificationRegistrar registrar_;
base::Closure task_;
DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver);
};
// Tests context menus by way of opening a context menu for a bookmark,
// then right clicking to get context menu and selecting the first menu item
// (open).
class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest4()
: observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest4::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Select the first menu item (open).
ui_test_utils::MoveMouseToCenterAndPress(
menu->GetSubmenu()->GetMenuItemAt(0),
ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest4::Step4));
}
void Step4() {
EXPECT_EQ(navigator_.last_url(), model_->other_node()->GetChild(0)->url());
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
VIEW_TEST(BookmarkBarViewTest4, ContextMenus)
// Tests drag and drop within the same menu.
class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
url_dragging_ =
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest5::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest5::Step3));
}
void Step3() {
views::MenuItemView* target_menu =
bb_view_->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
gfx::Point loc(1, target_menu->height() - 1);
views::View::ConvertPointToScreen(target_menu, &loc);
// Start a drag.
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(),
CreateEventTask(this, &BookmarkBarViewTest5::Step4)));
// See comment above this method as to why we do this.
ScheduleMouseMoveInBackground(loc.x(), loc.y());
}
void Step4() {
// Drop the item so that it's now the second item.
views::MenuItemView* target_menu =
bb_view_->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
gfx::Point loc(1, target_menu->height() - 2);
views::View::ConvertPointToScreen(target_menu, &loc);
ASSERT_TRUE(ui_controls::SendMouseMove(loc.x(), loc.y()));
ASSERT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest5::Step5)));
}
void Step5() {
GURL url = model_->bookmark_bar_node()->GetChild(0)->GetChild(1)->url();
EXPECT_EQ(url_dragging_, url);
Done();
}
GURL url_dragging_;
};
#if !defined(OS_WIN) // flaky http://crbug.com/400578
VIEW_TEST(BookmarkBarViewTest5, DND)
#endif
// Tests holding mouse down on overflow button, dragging such that menu pops up
// then selecting an item.
class BookmarkBarViewTest6 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Press the mouse button on the overflow button. Don't release it though.
views::LabelButton* button = bb_view_->overflow_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN, CreateEventTask(this, &BookmarkBarViewTest6::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Move mouse to center of menu and release mouse.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest6::Step3));
}
void Step3() {
ASSERT_EQ(navigator_.last_url(),
model_->bookmark_bar_node()->GetChild(6)->url());
Done();
}
GURL url_dragging_;
};
// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(BookmarkBarViewTest6, OpenMenuOnClickAndHold)
// Tests drag and drop to different menu.
class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
url_dragging_ =
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest7::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest7::Step3));
}
void Step3() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
#if defined(USE_AURA)
// TODO: fix this. Aura requires an additional mouse event to trigger drag
// and drop checking state.
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(),
base::Bind(&BookmarkBarViewTest7::Step3A, this)));
#else
// Start a drag.
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(), base::Bind(&BookmarkBarViewTest7::Step4, this)));
// See comment above this method as to why we do this.
ScheduleMouseMoveInBackground(loc.x(), loc.y());
#endif
}
void Step3A() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(), base::Bind(&BookmarkBarViewTest7::Step4, this)));
}
void Step4() {
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
views::MenuItemView* target_menu =
drop_menu->GetSubmenu()->GetMenuItemAt(0);
gfx::Point loc(1, 1);
views::View::ConvertPointToScreen(target_menu, &loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest7::Step5)));
}
void Step5() {
ASSERT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest7::Step6)));
}
void Step6() {
ASSERT_TRUE(model_->other_node()->GetChild(0)->url() == url_dragging_);
Done();
}
GURL url_dragging_;
};
#if !defined(OS_WIN)
// This test passes locally (on aero and non-aero) but fails on the trybots and
// buildbot.
// http://crbug.com/154081
VIEW_TEST(BookmarkBarViewTest7, MAYBE(DNDToDifferentMenu))
#endif
// Drags from one menu to next so that original menu closes, then back to
// original menu.
class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
url_dragging_ =
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest8::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest8::Step3));
}
void Step3() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
// Start a drag.
#if defined(USE_AURA)
// TODO: fix this. Aura requires an additional mouse event to trigger drag
// and drop checking state.
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(),
base::Bind(&BookmarkBarViewTest8::Step3A, this)));
#else
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(), base::Bind(&BookmarkBarViewTest8::Step4, this)));
// See comment above this method as to why we do this.
ScheduleMouseMoveInBackground(loc.x(), loc.y());
#endif
}
void Step3A() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(), base::Bind(&BookmarkBarViewTest8::Step4, this)));
}
void Step4() {
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
// Now drag back over first menu.
views::LabelButton* button = GetBookmarkButton(0);
gfx::Point loc(button->width() / 2, button->height() / 2);
views::View::ConvertPointToScreen(button, &loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(), base::Bind(&BookmarkBarViewTest8::Step5, this)));
}
void Step5() {
// Drop on folder F11.
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
views::MenuItemView* target_menu =
drop_menu->GetSubmenu()->GetMenuItemAt(1);
ui_test_utils::MoveMouseToCenterAndPress(
target_menu, ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest8::Step6));
}
void Step6() {
// Make sure drop was processed.
GURL final_url = model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->
GetChild(1)->url();
ASSERT_TRUE(final_url == url_dragging_);
Done();
}
GURL url_dragging_;
};
#if !defined(OS_WIN)
// This test passes locally (on aero and non-aero) but fails on the trybots and
// buildbot.
// http://crbug.com/154081
VIEW_TEST(BookmarkBarViewTest8, MAYBE(DNDBackToOriginatingMenu))
#endif
// Moves the mouse over the scroll button and makes sure we get scrolling.
class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase {
protected:
bool CreateBigMenu() override { return true; }
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest9::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
first_menu_ = menu->GetSubmenu()->GetMenuItemAt(0);
gfx::Point menu_loc;
views::View::ConvertPointToScreen(first_menu_, &menu_loc);
start_y_ = menu_loc.y();
// Move the mouse over the scroll button.
views::View* scroll_container = menu->GetSubmenu()->parent();
ASSERT_TRUE(scroll_container != NULL);
scroll_container = scroll_container->parent();
ASSERT_TRUE(scroll_container != NULL);
views::View* scroll_down_button = scroll_container->child_at(1);
ASSERT_TRUE(scroll_down_button);
gfx::Point loc(scroll_down_button->width() / 2,
scroll_down_button->height() / 2);
views::View::ConvertPointToScreen(scroll_down_button, &loc);
// On linux, the sending one location isn't enough.
ASSERT_TRUE(ui_controls::SendMouseMove(loc.x() - 1, loc.y() - 1));
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3)));
}
void Step3() {
base::MessageLoop::current()->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&BookmarkBarViewTest9::Step4, this),
base::TimeDelta::FromMilliseconds(200));
}
void Step4() {
gfx::Point menu_loc;
views::View::ConvertPointToScreen(first_menu_, &menu_loc);
ASSERT_NE(start_y_, menu_loc.y());
// Hide menu.
bb_view_->GetMenu()->GetMenuController()->CancelAll();
// On linux, Cancelling menu will call Quit on the message loop,
// which can interfere with Done. We need to run Done in the
// next execution loop.
base::MessageLoop::current()->task_runner()->PostTask(
FROM_HERE, base::Bind(&ViewEventTestBase::Done, this));
}
int start_y_;
views::MenuItemView* first_menu_;
};
// Fails on official cros bot. crbug.com/431427.
#if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)
#define MAYBE_ScrollButtonScrolls DISABLED_ScrollButtonScrolls
#else
#define MAYBE_ScrollButtonScrolls ScrollButtonScrolls
#endif
VIEW_TEST(BookmarkBarViewTest9, MAYBE_ScrollButtonScrolls)
// Tests up/down/left/enter key messages.
class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest10::Step2));
base::MessageLoop::current()->RunUntilIdle();
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Send a down event, which should select the first item.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_DOWN, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step3)));
}
void Step3() {
// Make sure menu is showing and item is selected.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
ASSERT_TRUE(menu->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
// Send a key down event, which should select the next item.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_DOWN, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step4)));
}
void Step4() {
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
ASSERT_FALSE(menu->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
ASSERT_TRUE(menu->GetSubmenu()->GetMenuItemAt(1)->IsSelected());
// Send a right arrow to force the menu to open.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_RIGHT, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step5)));
}
void Step5() {
// Make sure the submenu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(submenu->IsSelected());
ASSERT_TRUE(submenu->GetSubmenu());
ASSERT_TRUE(submenu->GetSubmenu()->IsShowing());
// Send a left arrow to close the submenu.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_LEFT, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step6)));
}
void Step6() {
// Make sure the submenu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(submenu->IsSelected());
ASSERT_TRUE(!submenu->GetSubmenu() || !submenu->GetSubmenu()->IsShowing());
// Send a down arrow to go down to f1b.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_DOWN, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step7)));
}
void Step7() {
// Make sure menu is showing and item is selected.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
ASSERT_TRUE(menu->GetSubmenu()->GetMenuItemAt(2)->IsSelected());
// Send a down arrow to wrap back to f1a.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_DOWN, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step8)));
}
void Step8() {
// Make sure menu is showing and item is selected.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
ASSERT_TRUE(menu->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
// Send enter, which should select the item.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_RETURN, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step9)));
}
void Step9() {
ASSERT_EQ(navigator_.last_url(),
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url());
Done();
}
};
#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_KeyEvents DISABLED_KeyEvents
#else
#define MAYBE_KeyEvents KeyEvents
#endif
VIEW_TEST(BookmarkBarViewTest10, MAYBE_KeyEvents)
// Make sure the menu closes with the following sequence: show menu, show
// context menu, close context menu (via escape), then click else where. This
// effectively verifies we maintain mouse capture after the context menu is
// hidden.
class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest11()
: observer_(CreateEventTask(this, &BookmarkBarViewTest11::Step3)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest11::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step3() {
// Send escape so that the context menu hides.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest11::Step4)));
}
void Step4() {
// Make sure the context menu is no longer showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(!menu || !menu->GetSubmenu() ||
!menu->GetSubmenu()->IsShowing());
// But the menu should be showing.
menu = bb_view_->GetMenu();
ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing());
// Now click on empty space.
gfx::Point mouse_loc;
views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc);
ASSERT_TRUE(ui_controls::SendMouseMove(mouse_loc.x(), mouse_loc.y()));
ASSERT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::UP | ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest11::Step5)));
}
void Step5() {
// Make sure the menu is not showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(!menu || !menu->GetSubmenu() ||
!menu->GetSubmenu()->IsShowing());
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_CloseMenuAfterClosingContextMenu \
DISABLED_CloseMenuAfterClosingContextMenu
#elif defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_CloseMenuAfterClosingContextMenu \
DISABLED_CloseMenuAfterClosingContextMenu
#else
#define MAYBE_CloseMenuAfterClosingContextMenu CloseMenuAfterClosingContextMenu
#endif
VIEW_TEST(BookmarkBarViewTest11, MAYBE_CloseMenuAfterClosingContextMenu)
// Tests showing a modal dialog from a context menu.
class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Open up the other folder.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest12::Step2));
chrome::num_bookmark_urls_before_prompting = 1;
}
~BookmarkBarViewTest12() override {
chrome::num_bookmark_urls_before_prompting = 15;
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
// Right click on the second child (a folder) to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest12::Step3));
}
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing());
// Select the first item in the context menu (open all).
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Click and wait until the dialog box appears.
scoped_ptr<DialogWaiter> dialog_waiter(new DialogWaiter());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
base::Bind(
&BookmarkBarViewTest12::Step4, this, base::Passed(&dialog_waiter)));
}
void Step4(scoped_ptr<DialogWaiter> waiter) {
views::Widget* dialog = waiter->WaitForDialog();
waiter.reset();
// Press tab to give focus to the cancel button. Wait until the widget
// receives the tab key.
TabKeyWaiter tab_waiter(dialog);
ASSERT_TRUE(ui_controls::SendKeyPress(
window_->GetNativeWindow(), ui::VKEY_TAB, false, false, false, false));
tab_waiter.WaitForTab();
// For some reason return isn't processed correctly unless we delay.
base::MessageLoop::current()->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&BookmarkBarViewTest12::Step5, this,
base::Unretained(dialog)),
base::TimeDelta::FromSeconds(1));
}
void Step5(views::Widget* dialog) {
DialogCloseWaiter waiter(dialog);
// And press enter so that the cancel button is selected.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_RETURN, false, false, false, false,
base::Closure()));
waiter.WaitForDialogClose();
Done();
}
};
// Times out on Win. http://crbug.com/499858
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_CloseWithModalDialog DISABLED_CloseWithModalDialog
#else
#define MAYBE_CloseWithModalDialog CloseWithModalDialog
#endif
VIEW_TEST(BookmarkBarViewTest12, MAYBE_CloseWithModalDialog)
// Tests clicking on the separator of a context menu (this is for coverage of
// bug 17862).
class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest13()
: observer_(CreateEventTask(this, &BookmarkBarViewTest13::Step3)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest13::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Find the first separator.
views::SubmenuView* submenu = menu->GetSubmenu();
views::View* separator_view = NULL;
for (int i = 0; i < submenu->child_count(); ++i) {
if (submenu->child_at(i)->id() != views::MenuItemView::kMenuItemViewID) {
separator_view = submenu->child_at(i);
break;
}
}
ASSERT_TRUE(separator_view);
// Click on the separator. Clicking on the separator shouldn't visually
// change anything.
ui_test_utils::MoveMouseToCenterAndPress(separator_view,
ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest13::Step4));
}
void Step4() {
// The context menu should still be showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Select the first context menu item.
ui_test_utils::MoveMouseToCenterAndPress(
menu->GetSubmenu()->GetMenuItemAt(0),
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest13::Step5));
}
void Step5() {
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator)
// Makes sure right clicking on a folder on the bookmark bar doesn't result in
// both a context menu and showing the menu.
class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest14()
: observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// right mouse button.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step2 will be invoked by BookmarkContextMenuNotificationObserver.
}
private:
void Step2() {
// Menu should NOT be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == NULL);
// Send escape so that the context menu hides.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest14::Step3)));
}
void Step3() {
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_ContextMenus2 DISABLED_ContextMenus2
#else
#define MAYBE_ContextMenus2 ContextMenus2
#endif
VIEW_TEST(BookmarkBarViewTest14, MAYBE_ContextMenus2)
// Makes sure deleting from the context menu keeps the bookmark menu showing.
class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest15()
: deleted_menu_id_(0),
observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3)) {
}
protected:
void DoTestOnMessageLoop() override {
// Show the other bookmarks.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest15::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
deleted_menu_id_ = child_menu->GetCommand();
// Right click on the second child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* delete_menu =
menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE);
ASSERT_TRUE(delete_menu);
// Click on the delete button.
ui_test_utils::MoveMouseToCenterAndPress(delete_menu,
ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest15::Step4));
}
void Step4() {
// The context menu should not be showing.
views::MenuItemView* context_menu = bb_view_->GetContextMenu();
ASSERT_TRUE(context_menu == NULL);
// But the menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// And the deleted_menu_id_ should have been removed.
ASSERT_TRUE(menu->GetMenuItemByID(deleted_menu_id_) == NULL);
bb_view_->GetMenu()->GetMenuController()->CancelAll();
Done();
}
int deleted_menu_id_;
BookmarkContextMenuNotificationObserver observer_;
};
VIEW_TEST(BookmarkBarViewTest15, MenuStaysVisibleAfterDelete)
// Tests that we don't crash or get stuck if the parent of a menu is closed.
class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest16::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Button should be depressed.
views::LabelButton* button = GetBookmarkButton(0);
ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED);
// Close the window.
window_->Close();
window_ = NULL;
base::MessageLoop::current()->task_runner()->PostTask(
FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest16::Done));
}
};
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_DeleteMenu DISABLED_DeleteMenu
#else
#define MAYBE_DeleteMenu DeleteMenu
#endif
VIEW_TEST(BookmarkBarViewTest16, MAYBE_DeleteMenu)
// Makes sure right clicking on an item while a context menu is already showing
// doesn't crash and works.
class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest17()
: observer_(CreateEventTask(this, &BookmarkBarViewTest17::Step3)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the other folder on the bookmark bar and press the
// left mouse button.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest17::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Right click on the second item to show its context menu.
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* context_menu = bb_view_->GetContextMenu();
ASSERT_TRUE(context_menu != NULL);
ASSERT_TRUE(context_menu->GetSubmenu());
ASSERT_TRUE(context_menu->GetSubmenu()->IsShowing());
// Right click on the first menu item to trigger its context menu.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
// The context menu and child_menu can be overlapped, calculate the
// non-intersected Rect of the child menu and click on its center to make
// sure the click is always on the child menu.
gfx::Rect context_rect = context_menu->GetSubmenu()->GetBoundsInScreen();
gfx::Rect child_menu_rect = child_menu->GetBoundsInScreen();
gfx::Rect clickable_rect =
gfx::SubtractRects(child_menu_rect, context_rect);
ASSERT_FALSE(clickable_rect.IsEmpty());
observer_.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4));
MoveMouseAndPress(clickable_rect.CenterPoint(), ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step4 will be invoked by BookmarkContextMenuNotificationObserver.
}
void Step4() {
// The context menu should still be showing.
views::MenuItemView* context_menu = bb_view_->GetContextMenu();
ASSERT_TRUE(context_menu != NULL);
// And the menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
bb_view_->GetMenu()->GetMenuController()->CancelAll();
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
#if defined(OS_WIN)
// Flaky on Win7. crbug/453796
#define MAYBE_ContextMenus3 DISABLED_ContextMenus3
#else
#define MAYBE_ContextMenus3 ContextMenus3
#endif
VIEW_TEST(BookmarkBarViewTest17, MAYBE_ContextMenus3)
// Verifies sibling menus works. Clicks on the 'other bookmarks' folder, then
// moves the mouse over the first item on the bookmark bar and makes sure the
// menu appears.
class BookmarkBarViewTest18 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the other folder on the bookmark bar and press the
// left mouse button.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest18::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// The button should be pressed.
EXPECT_EQ(views::Button::STATE_PRESSED,
bb_view_->other_bookmarks_button()->state());
// Move the mouse to the first folder on the bookmark bar.
views::LabelButton* button = GetBookmarkButton(0);
gfx::Point button_center(button->width() / 2, button->height() / 2);
views::View::ConvertPointToScreen(button, &button_center);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
button_center.x(), button_center.y(),
CreateEventTask(this, &BookmarkBarViewTest18::Step3)));
}
void Step3() {
// Make sure the menu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// The menu for the first folder should be in the pressed state (since the
// menu is showing for it)...
EXPECT_EQ(views::CustomButton::STATE_PRESSED,
GetBookmarkButton(0)->state());
// ... And the "other bookmarks" button should no longer be pressed.
EXPECT_EQ(views::Button::STATE_NORMAL,
bb_view_->other_bookmarks_button()->state());
menu->GetMenuController()->CancelAll();
Done();
}
};
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_BookmarkBarViewTest18_SiblingMenu \
DISABLED_BookmarkBarViewTest18_SiblingMenu
#else
#define MAYBE_BookmarkBarViewTest18_SiblingMenu \
BookmarkBarViewTest18_SiblingMenu
#endif
VIEW_TEST(BookmarkBarViewTest18, MAYBE_BookmarkBarViewTest18_SiblingMenu)
// Verifies mousing over an already open sibling menu doesn't prematurely cancel
// the menu.
class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the other folder on the bookmark bar and press the
// left mouse button.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest19::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Click on the first folder.
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest19::Step3));
}
void Step3() {
// Make sure the menu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Move the mouse back to the "Other Bookmarks" button.
views::LabelButton* button = bb_view_->other_bookmarks_button();
gfx::Point button_center(button->width() / 2, button->height() / 2);
views::View::ConvertPointToScreen(button, &button_center);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
button_center.x() + 1, button_center.y() + 1,
CreateEventTask(this, &BookmarkBarViewTest19::Step4)));
}
void Step4() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Click on the first folder.
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(1);
ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(
child_menu,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest19::Step5));
}
void Step5() {
// Make sure the menu is showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
menu->GetMenuController()->CancelAll();
Done();
}
};
VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu)
// Verify that when clicking a mouse button outside a context menu,
// the context menu is dismissed *and* the underlying view receives
// the the mouse event (due to event reposting).
class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest20() : test_view_(new TestViewForMenuExit) {}
protected:
void DoTestOnMessageLoop() override {
// Add |test_view_| next to |bb_view_|.
views::View* parent = bb_view_->parent();
views::View* container_view = new ContainerViewForMenuExit;
container_view->AddChildView(bb_view_.get());
container_view->AddChildView(test_view_);
parent->AddChildView(container_view);
parent->Layout();
ASSERT_EQ(test_view_->press_count(), 0);
// Move the mouse to the Test View and press the left mouse button.
ui_test_utils::MoveMouseToCenterAndPress(
test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step1));
}
private:
void Step1() {
ASSERT_EQ(test_view_->press_count(), 1);
ASSERT_TRUE(bb_view_->GetMenu() == NULL);
// Move the mouse to the first folder on the bookmark bar and press the
// left mouse button.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step2));
}
void Step2() {
ASSERT_EQ(test_view_->press_count(), 1);
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Move the mouse to the Test View and press the left mouse button.
// The context menu will consume the event and exit. Thereafter,
// the event is reposted and delivered to the Test View which
// increases its press-count.
ui_test_utils::MoveMouseToCenterAndPress(
test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step3));
}
void Step3() {
ASSERT_EQ(test_view_->press_count(), 2);
ASSERT_TRUE(bb_view_->GetMenu() == NULL);
Done();
}
class ContainerViewForMenuExit : public views::View {
public:
ContainerViewForMenuExit() {
}
void Layout() override {
DCHECK_EQ(2, child_count());
views::View* bb_view = child_at(0);
views::View* test_view = child_at(1);
const int width = bb_view->width();
const int height = bb_view->height();
bb_view->SetBounds(0,0, width - 22, height);
test_view->SetBounds(width - 20, 0, 20, height);
}
private:
DISALLOW_COPY_AND_ASSIGN(ContainerViewForMenuExit);
};
class TestViewForMenuExit : public views::View {
public:
TestViewForMenuExit() : press_count_(0) {
}
bool OnMousePressed(const ui::MouseEvent& event) override {
++press_count_;
return true;
}
int press_count() const { return press_count_; }
private:
int press_count_;
DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit);
};
TestViewForMenuExit* test_view_;
};
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(erg): linux_aura bringup: http://crbug.com/163931
#define MAYBE_ContextMenuExitTest DISABLED_ContextMenuExitTest
#else
#define MAYBE_ContextMenuExitTest ContextMenuExitTest
#endif
VIEW_TEST(BookmarkBarViewTest20, MAYBE_ContextMenuExitTest)
// Tests context menu by way of opening a context menu for a empty folder menu.
// The opened context menu should behave as it is from the folder button.
class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest21()
: observer_(CreateEventTask(this, &BookmarkBarViewTest21::Step3)) {
}
protected:
// Move the mouse to the empty folder on the bookmark bar and press the
// left mouse button.
void DoTestOnMessageLoop() override {
views::LabelButton* button = GetBookmarkButton(5);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest21::Step2));
}
private:
// Confirm that a menu for empty folder shows and right click the menu.
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
views::SubmenuView* submenu = menu->GetSubmenu();
ASSERT_TRUE(submenu->IsShowing());
ASSERT_EQ(1, submenu->child_count());
views::View* view = submenu->child_at(0);
ASSERT_TRUE(view != NULL);
EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id());
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
// Confirm that context menu shows and click REMOVE menu.
void Step3() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* delete_menu =
menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE);
ASSERT_TRUE(delete_menu);
// Click on the delete menu item.
ui_test_utils::MoveMouseToCenterAndPress(delete_menu,
ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest21::Step4));
}
// Confirm that the empty folder gets removed and menu doesn't show.
void Step4() {
views::LabelButton* button = GetBookmarkButton(5);
ASSERT_TRUE(button);
EXPECT_EQ(ASCIIToUTF16("d"), button->GetText());
EXPECT_TRUE(bb_view_->GetContextMenu() == NULL);
EXPECT_TRUE(bb_view_->GetMenu() == NULL);
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder)
// Test that closing the source browser window while dragging a bookmark does
// not cause a crash.
class BookmarkBarViewTest22 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest22::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::LEFT, ui_controls::DOWN,
CreateEventTask(this, &BookmarkBarViewTest22::Step3));
}
void Step3() {
views::MenuItemView* target_menu =
bb_view_->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
gfx::Point loc(1, target_menu->height() - 1);
views::View::ConvertPointToScreen(target_menu, &loc);
// Start a drag.
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(),
CreateEventTask(this, &BookmarkBarViewTest22::Step4)));
ScheduleMouseMoveInBackground(loc.x(), loc.y());
}
void Step4() {
window_->Close();
window_ = NULL;
#if defined(OS_CHROMEOS)
ASSERT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest22::Done)));
#else
// There are no widgets to send the mouse release to.
Done();
#endif
}
};
#if defined(OS_WIN)
// This test times out on Windows. TODO(pkotwicz): Find out why.
#define MAYBE_CloseSourceBrowserDuringDrag DISABLED_CloseSourceBrowserDuringDrag
#else
#define MAYBE_CloseSourceBrowserDuringDrag CloseSourceBrowserDuringDrag
#endif
VIEW_TEST(BookmarkBarViewTest22, MAYBE_CloseSourceBrowserDuringDrag)
// Tests opening a context menu for a bookmark node from the keyboard.
class BookmarkBarViewTest23 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest23()
: observer_(CreateEventTask(this, &BookmarkBarViewTest23::Step4)) {
}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest23::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Navigate down to highlight the first menu item.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
GetWidget()->GetNativeWindow(), ui::VKEY_DOWN, false, false, false,
false, // No modifer keys
CreateEventTask(this, &BookmarkBarViewTest23::Step3)));
}
void Step3() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Open the context menu via the keyboard.
ASSERT_TRUE(ui_controls::SendKeyPress(GetWidget()->GetNativeWindow(),
ui::VKEY_APPS, false, false, false,
false // No modifer keys
));
// The BookmarkContextMenuNotificationObserver triggers Step4.
}
void Step4() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Select the first menu item (open).
ui_test_utils::MoveMouseToCenterAndPress(
menu->GetSubmenu()->GetMenuItemAt(0),
ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest23::Step5));
}
void Step5() {
EXPECT_EQ(navigator_.last_url(), model_->other_node()->GetChild(0)->url());
Done();
}
BookmarkContextMenuNotificationObserver observer_;
};
#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_ContextMenusKeyboard DISABLED_ContextMenusKeyboard
#else
#define MAYBE_ContextMenusKeyboard ContextMenusKeyboard
#endif
VIEW_TEST(BookmarkBarViewTest23, MAYBE_ContextMenusKeyboard)
// Test that pressing escape on a menu opened via the keyboard dismisses the
// context menu but not the parent menu.
class BookmarkBarViewTest24 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest24()
: observer_(CreateEventTask(this, &BookmarkBarViewTest24::Step4)) {}
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = bb_view_->other_bookmarks_button();
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest24::Step2));
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Navigate down to highlight the first menu item.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
GetWidget()->GetNativeWindow(), ui::VKEY_DOWN, false, false, false,
false, // No modifer keys
CreateEventTask(this, &BookmarkBarViewTest24::Step3)));
}
void Step3() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Open the context menu via the keyboard.
ASSERT_TRUE(ui_controls::SendKeyPress(GetWidget()->GetNativeWindow(),
ui::VKEY_APPS, false, false, false,
false // No modifer keys
));
// The BookmarkContextMenuNotificationObserver triggers Step4.
}
void Step4() {
// Make sure the context menu is showing.
views::MenuItemView* menu = bb_view_->GetContextMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu());
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Send escape to close the context menu.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest24::Step5)));
}
void Step5() {
// The context menu should be closed but the parent menu should still be
// showing.
ASSERT_FALSE(bb_view_->GetContextMenu());
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Send escape to close the main menu.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest24::Done)));
}
BookmarkContextMenuNotificationObserver observer_;
};
#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_ContextMenusKeyboardEscape DISABLED_ContextMenusKeyboardEscape
#else
#define MAYBE_ContextMenusKeyboardEscape ContextMenusKeyboardEscape
#endif
VIEW_TEST(BookmarkBarViewTest24, MAYBE_ContextMenusKeyboardEscape)
#if defined(OS_WIN)
// Tests that pressing the key KEYCODE closes the menu.
template <ui::KeyboardCode KEYCODE>
class BookmarkBarViewTest25 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest25::Step2));
base::MessageLoop::current()->RunUntilIdle();
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != nullptr);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Send KEYCODE key event, which should close the menu.
ASSERT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
window_->GetNativeWindow(), KEYCODE, false, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest25::Step3)));
}
void Step3() {
// Make sure menu is not showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == nullptr);
Done();
}
};
// Tests that pressing F10 system key closes the menu.
using BookmarkBarViewTest25F10 = BookmarkBarViewTest25<ui::VKEY_F10>;
VIEW_TEST(BookmarkBarViewTest25F10, F10ClosesMenu);
// Tests that pressing Alt system key closes the menu.
using BookmarkBarViewTest25Alt = BookmarkBarViewTest25<ui::VKEY_MENU>;
VIEW_TEST(BookmarkBarViewTest25Alt, AltClosesMenu);
// Tests that WM_CANCELMODE closes the menu.
class BookmarkBarViewTest26 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
// Move the mouse to the first folder on the bookmark bar and press the
// mouse.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest26::Step2));
base::MessageLoop::current()->RunUntilIdle();
}
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != nullptr);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Send WM_CANCELMODE, which should close the menu. The message is sent
// synchronously, however, we post a task to make sure that the message is
// processed completely before finishing the test.
::SendMessage(
GetWidget()->GetNativeView()->GetHost()->GetAcceleratedWidget(),
WM_CANCELMODE, 0, 0);
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&BookmarkBarViewTest26::Step3, this));
}
void Step3() {
// Menu should not be showing anymore.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == nullptr);
Done();
}
};
VIEW_TEST(BookmarkBarViewTest26, CancelModeClosesMenu);
#endif
class BookmarkBarViewTest27 : public BookmarkBarViewEventTestBase {
protected:
void DoTestOnMessageLoop() override {
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::MIDDLE, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest27::Step2));
}
private:
void Step2() {
ASSERT_EQ(2u, navigator_.urls().size());
EXPECT_EQ(navigator_.urls()[0],
model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url());
EXPECT_EQ(navigator_.urls()[1],
model_->bookmark_bar_node()->GetChild(0)->GetChild(2)->url());
Done();
}
};
VIEW_TEST(BookmarkBarViewTest27, MiddleClickOnFolderOpensAllBookmarks);
|