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
|
// 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 "chrome/browser/browsing_data/browsing_data_remover.h"
#include <set>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/guid.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/domain_reliability/clear_mode.h"
#include "components/domain_reliability/monitor.h"
#include "components/domain_reliability/service.h"
#include "components/favicon/core/favicon_service.h"
#include "components/history/core/browser/history_service.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/dom_storage_context.h"
#include "content/public/browser/local_storage_usage_info.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "net/cookies/cookie_store.h"
#include "net/ssl/channel_id_service.h"
#include "net/ssl/channel_id_store.h"
#include "net/ssl/ssl_client_cert_type.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/favicon_size.h"
#include "url/origin.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/mock_cryptohome_client.h"
#endif
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
#endif
class MockExtensionSpecialStoragePolicy;
using content::BrowserThread;
using content::StoragePartition;
using domain_reliability::CLEAR_BEACONS;
using domain_reliability::CLEAR_CONTEXTS;
using domain_reliability::DomainReliabilityClearMode;
using domain_reliability::DomainReliabilityMonitor;
using domain_reliability::DomainReliabilityService;
using domain_reliability::DomainReliabilityServiceFactory;
using testing::_;
using testing::ByRef;
using testing::Invoke;
using testing::Matcher;
using testing::MakeMatcher;
using testing::MatcherInterface;
using testing::MatchResultListener;
using testing::Return;
using testing::WithArgs;
namespace {
const char kTestOrigin1[] = "http://host1:1/";
const char kTestOrigin2[] = "http://host2:1/";
const char kTestOrigin3[] = "http://host3:1/";
const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
// For Autofill.
const char kChromeOrigin[] = "Chrome settings";
const char kWebOrigin[] = "https://www.example.com/";
const GURL kOrigin1(kTestOrigin1);
const GURL kOrigin2(kTestOrigin2);
const GURL kOrigin3(kTestOrigin3);
const GURL kOriginExt(kTestOriginExt);
const GURL kOriginDevTools(kTestOriginDevTools);
const base::FilePath::CharType kDomStorageOrigin1[] =
FILE_PATH_LITERAL("http_host1_1.localstorage");
const base::FilePath::CharType kDomStorageOrigin2[] =
FILE_PATH_LITERAL("http_host2_1.localstorage");
const base::FilePath::CharType kDomStorageOrigin3[] =
FILE_PATH_LITERAL("http_host3_1.localstorage");
const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
"chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
#if defined(OS_CHROMEOS)
void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
}
#endif
struct StoragePartitionRemovalData {
uint32 remove_mask = 0;
uint32 quota_storage_remove_mask = 0;
GURL remove_origin;
base::Time remove_begin;
base::Time remove_end;
StoragePartition::OriginMatcherFunction origin_matcher;
StoragePartitionRemovalData() {}
};
class TestStoragePartition : public StoragePartition {
public:
TestStoragePartition() {}
~TestStoragePartition() override {}
// content::StoragePartition implementation.
base::FilePath GetPath() override { return base::FilePath(); }
net::URLRequestContextGetter* GetURLRequestContext() override {
return nullptr;
}
net::URLRequestContextGetter* GetMediaURLRequestContext() override {
return nullptr;
}
storage::QuotaManager* GetQuotaManager() override { return nullptr; }
content::AppCacheService* GetAppCacheService() override { return nullptr; }
storage::FileSystemContext* GetFileSystemContext() override {
return nullptr;
}
storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; }
content::DOMStorageContext* GetDOMStorageContext() override {
return nullptr;
}
content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; }
content::ServiceWorkerContext* GetServiceWorkerContext() override {
return nullptr;
}
content::CacheStorageContext* GetCacheStorageContext() override {
return nullptr;
}
content::GeofencingManager* GetGeofencingManager() override {
return nullptr;
}
content::NavigatorConnectContext* GetNavigatorConnectContext() override {
return nullptr;
}
content::PlatformNotificationContext* GetPlatformNotificationContext()
override {
return nullptr;
}
content::BackgroundSyncContext* GetBackgroundSyncContext() override {
return nullptr;
}
content::HostZoomMap* GetHostZoomMap() override { return nullptr; }
content::HostZoomLevelContext* GetHostZoomLevelContext() override {
return nullptr;
}
content::ZoomLevelDelegate* GetZoomLevelDelegate() override {
return nullptr;
}
void ClearDataForOrigin(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const GURL& storage_origin,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) override {
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&TestStoragePartition::AsyncRunCallback,
base::Unretained(this),
callback));
}
void ClearData(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const GURL& storage_origin,
const OriginMatcherFunction& origin_matcher,
const base::Time begin,
const base::Time end,
const base::Closure& callback) override {
// Store stuff to verify parameters' correctness later.
storage_partition_removal_data_.remove_mask = remove_mask;
storage_partition_removal_data_.quota_storage_remove_mask =
quota_storage_remove_mask;
storage_partition_removal_data_.remove_origin = storage_origin;
storage_partition_removal_data_.remove_begin = begin;
storage_partition_removal_data_.remove_end = end;
storage_partition_removal_data_.origin_matcher = origin_matcher;
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&TestStoragePartition::AsyncRunCallback,
base::Unretained(this), callback));
}
void Flush() override {}
StoragePartitionRemovalData GetStoragePartitionRemovalData() {
return storage_partition_removal_data_;
}
private:
void AsyncRunCallback(const base::Closure& callback) {
callback.Run();
}
StoragePartitionRemovalData storage_partition_removal_data_;
DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
};
// Custom matcher to verify is-same-origin relationship to given reference
// origin.
// (We cannot use equality-based matching because operator== is not defined for
// Origin, and we in fact want to rely on IsSameOrigin for matching purposes.)
class SameOriginMatcher : public MatcherInterface<const url::Origin&> {
public:
explicit SameOriginMatcher(const url::Origin& reference)
: reference_(reference) {}
virtual bool MatchAndExplain(const url::Origin& origin,
MatchResultListener* listener) const {
return reference_.IsSameOriginWith(origin);
}
virtual void DescribeTo(::std::ostream* os) const {
*os << "is same origin with " << reference_;
}
virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "is not same origin with " << reference_;
}
private:
const url::Origin& reference_;
};
inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) {
return MakeMatcher(new SameOriginMatcher(reference));
}
} // namespace
// Testers -------------------------------------------------------------------
class RemoveCookieTester {
public:
RemoveCookieTester() {}
// Returns true, if the given cookie exists in the cookie store.
bool ContainsCookie() {
scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
quit_closure_ = message_loop_runner->QuitClosure();
get_cookie_success_ = false;
cookie_store_->GetCookiesWithOptionsAsync(
kOrigin1, net::CookieOptions(),
base::Bind(&RemoveCookieTester::GetCookieCallback,
base::Unretained(this)));
message_loop_runner->Run();
return get_cookie_success_;
}
void AddCookie() {
scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
quit_closure_ = message_loop_runner->QuitClosure();
cookie_store_->SetCookieWithOptionsAsync(
kOrigin1, "A=1", net::CookieOptions(),
base::Bind(&RemoveCookieTester::SetCookieCallback,
base::Unretained(this)));
message_loop_runner->Run();
}
protected:
void SetMonster(net::CookieStore* monster) {
cookie_store_ = monster;
}
private:
void GetCookieCallback(const std::string& cookies) {
if (cookies == "A=1") {
get_cookie_success_ = true;
} else {
EXPECT_EQ("", cookies);
get_cookie_success_ = false;
}
quit_closure_.Run();
}
void SetCookieCallback(bool result) {
ASSERT_TRUE(result);
quit_closure_.Run();
}
bool get_cookie_success_ = false;
base::Closure quit_closure_;
net::CookieStore* cookie_store_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
};
#if defined(SAFE_BROWSING_SERVICE)
class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
public:
RemoveSafeBrowsingCookieTester()
: browser_process_(TestingBrowserProcess::GetGlobal()) {
scoped_refptr<SafeBrowsingService> sb_service =
SafeBrowsingService::CreateSafeBrowsingService();
browser_process_->SetSafeBrowsingService(sb_service.get());
sb_service->Initialize();
base::MessageLoop::current()->RunUntilIdle();
// Create a cookiemonster that does not have persistant storage, and replace
// the SafeBrowsingService created one with it.
net::CookieStore* monster =
content::CreateCookieStore(content::CookieStoreConfig());
sb_service->url_request_context()->GetURLRequestContext()->
set_cookie_store(monster);
SetMonster(monster);
}
virtual ~RemoveSafeBrowsingCookieTester() {
browser_process_->safe_browsing_service()->ShutDown();
base::MessageLoop::current()->RunUntilIdle();
browser_process_->SetSafeBrowsingService(nullptr);
}
private:
TestingBrowserProcess* browser_process_;
DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
};
#endif
class RemoveChannelIDTester : public net::SSLConfigService::Observer {
public:
explicit RemoveChannelIDTester(TestingProfile* profile) {
channel_id_service_ = profile->GetRequestContext()->
GetURLRequestContext()->channel_id_service();
ssl_config_service_ = profile->GetSSLConfigService();
ssl_config_service_->AddObserver(this);
}
~RemoveChannelIDTester() override {
ssl_config_service_->RemoveObserver(this);
}
int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
// Add a server bound cert for |server| with specific creation and expiry
// times. The cert and key data will be filled with dummy values.
void AddChannelIDWithTimes(const std::string& server_identifier,
base::Time creation_time) {
GetChannelIDStore()->SetChannelID(
make_scoped_ptr(new net::ChannelIDStore::ChannelID(
server_identifier, creation_time,
make_scoped_ptr(crypto::ECPrivateKey::Create()))));
}
// Add a server bound cert for |server|, with the current time as the
// creation time. The cert and key data will be filled with dummy values.
void AddChannelID(const std::string& server_identifier) {
base::Time now = base::Time::Now();
AddChannelIDWithTimes(server_identifier, now);
}
void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
GetChannelIDStore()->GetAllChannelIDs(
base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback,
channel_ids));
}
net::ChannelIDStore* GetChannelIDStore() {
return channel_id_service_->GetChannelIDStore();
}
int ssl_config_changed_count() const {
return ssl_config_changed_count_;
}
// net::SSLConfigService::Observer implementation:
void OnSSLConfigChanged() override { ssl_config_changed_count_++; }
private:
static void GetAllChannelIDsCallback(
net::ChannelIDStore::ChannelIDList* dest,
const net::ChannelIDStore::ChannelIDList& result) {
*dest = result;
}
net::ChannelIDService* channel_id_service_;
scoped_refptr<net::SSLConfigService> ssl_config_service_;
int ssl_config_changed_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
};
class RemoveHistoryTester {
public:
RemoveHistoryTester() {}
bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
if (!profile->CreateHistoryService(true, false))
return false;
history_service_ = HistoryServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
return true;
}
// Returns true, if the given URL exists in the history service.
bool HistoryContainsURL(const GURL& url) {
scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
quit_closure_ = message_loop_runner->QuitClosure();
history_service_->QueryURL(
url,
true,
base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
base::Unretained(this)),
&tracker_);
message_loop_runner->Run();
return query_url_success_;
}
void AddHistory(const GURL& url, base::Time time) {
history_service_->AddPage(url, time, nullptr, 0, GURL(),
history::RedirectList(), ui::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, false);
}
private:
// Callback for HistoryService::QueryURL.
void SaveResultAndQuit(bool success,
const history::URLRow&,
const history::VisitVector&) {
query_url_success_ = success;
quit_closure_.Run();
}
// For History requests.
base::CancelableTaskTracker tracker_;
bool query_url_success_ = false;
base::Closure quit_closure_;
// TestingProfile owns the history service; we shouldn't delete it.
history::HistoryService* history_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
};
class RemoveFaviconTester {
public:
RemoveFaviconTester() {}
bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
// Create the history service if it has not been created yet.
history_service_ = HistoryServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
if (!history_service_) {
if (!profile->CreateHistoryService(true, false))
return false;
history_service_ = HistoryServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
}
profile->CreateFaviconService();
favicon_service_ = FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
return true;
}
// Returns true if there is a favicon stored for |page_url| in the favicon
// database.
bool HasFaviconForPageURL(const GURL& page_url) {
RequestFaviconSyncForPageURL(page_url);
return got_favicon_;
}
// Returns true if:
// - There is a favicon stored for |page_url| in the favicon database.
// - The stored favicon is expired.
bool HasExpiredFaviconForPageURL(const GURL& page_url) {
RequestFaviconSyncForPageURL(page_url);
return got_expired_favicon_;
}
// Adds a visit to history and stores an arbitrary favicon bitmap for
// |page_url|.
void VisitAndAddFavicon(const GURL& page_url) {
history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(),
history::RedirectList(), ui::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, false);
SkBitmap bitmap;
bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize);
bitmap.eraseColor(SK_ColorBLUE);
favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON,
gfx::Image::CreateFrom1xBitmap(bitmap));
}
private:
// Synchronously requests the favicon for |page_url| from the favicon
// database.
void RequestFaviconSyncForPageURL(const GURL& page_url) {
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
favicon_service_->GetRawFaviconForPageURL(
page_url,
favicon_base::FAVICON,
gfx::kFaviconSize,
base::Bind(&RemoveFaviconTester::SaveResultAndQuit,
base::Unretained(this)),
&tracker_);
run_loop.Run();
}
// Callback for HistoryService::QueryURL.
void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) {
got_favicon_ = result.is_valid();
got_expired_favicon_ = result.is_valid() && result.expired;
quit_closure_.Run();
}
// For favicon requests.
base::CancelableTaskTracker tracker_;
bool got_favicon_ = false;
bool got_expired_favicon_ = false;
base::Closure quit_closure_;
// Owned by TestingProfile.
history::HistoryService* history_service_ = nullptr;
favicon::FaviconService* favicon_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
};
class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
public:
explicit RemoveAutofillTester(TestingProfile* profile)
: personal_data_manager_(
autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
autofill::test::DisableSystemServices(profile->GetPrefs());
personal_data_manager_->AddObserver(this);
}
~RemoveAutofillTester() override {
personal_data_manager_->RemoveObserver(this);
}
// Returns true if there are autofill profiles.
bool HasProfile() {
return !personal_data_manager_->GetProfiles().empty() &&
!personal_data_manager_->GetCreditCards().empty();
}
bool HasOrigin(const std::string& origin) {
const std::vector<autofill::AutofillProfile*>& profiles =
personal_data_manager_->GetProfiles();
for (const autofill::AutofillProfile* profile : profiles) {
if (profile->origin() == origin)
return true;
}
const std::vector<autofill::CreditCard*>& credit_cards =
personal_data_manager_->GetCreditCards();
for (const autofill::CreditCard* credit_card : credit_cards) {
if (credit_card->origin() == origin)
return true;
}
return false;
}
// Add two profiles and two credit cards to the database. In each pair, one
// entry has a web origin and the other has a Chrome origin.
void AddProfilesAndCards() {
std::vector<autofill::AutofillProfile> profiles;
autofill::AutofillProfile profile;
profile.set_guid(base::GenerateGUID());
profile.set_origin(kWebOrigin);
profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
profile.SetRawInfo(autofill::EMAIL_ADDRESS,
base::ASCIIToUTF16("sue@example.com"));
profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
profiles.push_back(profile);
profile.set_guid(base::GenerateGUID());
profile.set_origin(kChromeOrigin);
profiles.push_back(profile);
personal_data_manager_->SetProfiles(&profiles);
base::MessageLoop::current()->Run();
std::vector<autofill::CreditCard> cards;
autofill::CreditCard card;
card.set_guid(base::GenerateGUID());
card.set_origin(kWebOrigin);
card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
base::ASCIIToUTF16("1234-5678-9012-3456"));
cards.push_back(card);
card.set_guid(base::GenerateGUID());
card.set_origin(kChromeOrigin);
cards.push_back(card);
personal_data_manager_->SetCreditCards(&cards);
base::MessageLoop::current()->Run();
}
private:
void OnPersonalDataChanged() override {
base::MessageLoop::current()->QuitWhenIdle();
}
autofill::PersonalDataManager* personal_data_manager_;
DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
};
class RemoveLocalStorageTester {
public:
explicit RemoveLocalStorageTester(TestingProfile* profile)
: profile_(profile) {
dom_storage_context_ =
content::BrowserContext::GetDefaultStoragePartition(profile)->
GetDOMStorageContext();
}
// Returns true, if the given origin URL exists.
bool DOMStorageExistsForOrigin(const GURL& origin) {
scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
quit_closure_ = message_loop_runner->QuitClosure();
GetLocalStorageUsage();
message_loop_runner->Run();
for (size_t i = 0; i < infos_.size(); ++i) {
if (origin == infos_[i].origin)
return true;
}
return false;
}
void AddDOMStorageTestData() {
// Note: This test depends on details of how the dom_storage library
// stores data in the host file system.
base::FilePath storage_path =
profile_->GetPath().AppendASCII("Local Storage");
base::CreateDirectory(storage_path);
// Write some files.
base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0);
base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0);
base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0);
base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0);
// Tweak their dates.
base::Time now = base::Time::Now();
base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
base::TouchFile(storage_path.Append(kDomStorageOrigin2),
one_day_ago, one_day_ago);
base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
base::TouchFile(storage_path.Append(kDomStorageOrigin3),
sixty_days_ago, sixty_days_ago);
base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
}
private:
void GetLocalStorageUsage() {
dom_storage_context_->GetLocalStorageUsage(
base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
base::Unretained(this)));
}
void OnGotLocalStorageUsage(
const std::vector<content::LocalStorageUsageInfo>& infos) {
infos_ = infos;
quit_closure_.Run();
}
// We don't own these pointers.
TestingProfile* profile_;
content::DOMStorageContext* dom_storage_context_ = nullptr;
std::vector<content::LocalStorageUsageInfo> infos_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
};
class MockDomainReliabilityService : public DomainReliabilityService {
public:
MockDomainReliabilityService() {}
~MockDomainReliabilityService() override {}
scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
override {
NOTREACHED();
return scoped_ptr<DomainReliabilityMonitor>();
}
void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
const base::Closure& callback) override {
clear_count_++;
last_clear_mode_ = clear_mode;
callback.Run();
}
void GetWebUIData(const base::Callback<void(scoped_ptr<base::Value>)>&
callback) const override {
NOTREACHED();
}
int clear_count() const { return clear_count_; }
DomainReliabilityClearMode last_clear_mode() const {
return last_clear_mode_;
}
private:
unsigned clear_count_ = 0;
DomainReliabilityClearMode last_clear_mode_;
};
struct TestingDomainReliabilityServiceFactoryUserData
: public base::SupportsUserData::Data {
TestingDomainReliabilityServiceFactoryUserData(
content::BrowserContext* context,
MockDomainReliabilityService* service)
: context(context),
service(service),
attached(false) {}
~TestingDomainReliabilityServiceFactoryUserData() override {}
content::BrowserContext* const context;
MockDomainReliabilityService* const service;
bool attached;
static const void* kKey;
};
// static
const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
&TestingDomainReliabilityServiceFactoryUserData::kKey;
scoped_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction(
content::BrowserContext* context) {
const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
TestingDomainReliabilityServiceFactoryUserData* data =
static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
context->GetUserData(kKey));
EXPECT_TRUE(data);
EXPECT_EQ(data->context, context);
EXPECT_FALSE(data->attached);
data->attached = true;
return make_scoped_ptr(data->service);
}
class ClearDomainReliabilityTester {
public:
explicit ClearDomainReliabilityTester(TestingProfile* profile) :
profile_(profile),
mock_service_(new MockDomainReliabilityService()) {
AttachService();
}
unsigned clear_count() const { return mock_service_->clear_count(); }
DomainReliabilityClearMode last_clear_mode() const {
return mock_service_->last_clear_mode();
}
private:
void AttachService() {
const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
// Attach kludgey UserData struct to profile.
TestingDomainReliabilityServiceFactoryUserData* data =
new TestingDomainReliabilityServiceFactoryUserData(profile_,
mock_service_);
EXPECT_FALSE(profile_->GetUserData(kKey));
profile_->SetUserData(kKey, data);
// Set and use factory that will attach service stuffed in kludgey struct.
DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile_,
&TestingDomainReliabilityServiceFactoryFunction);
// Verify and detach kludgey struct.
EXPECT_EQ(data, profile_->GetUserData(kKey));
EXPECT_TRUE(data->attached);
profile_->RemoveUserData(kKey);
}
TestingProfile* profile_;
MockDomainReliabilityService* mock_service_;
};
class RemoveDownloadsTester {
public:
explicit RemoveDownloadsTester(TestingProfile* testing_profile)
: download_manager_(new content::MockDownloadManager()),
chrome_download_manager_delegate_(testing_profile) {
content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
download_manager_);
EXPECT_EQ(download_manager_,
content::BrowserContext::GetDownloadManager(testing_profile));
EXPECT_CALL(*download_manager_, GetDelegate())
.WillOnce(Return(&chrome_download_manager_delegate_));
EXPECT_CALL(*download_manager_, Shutdown());
}
~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
content::MockDownloadManager* download_manager() { return download_manager_; }
private:
content::MockDownloadManager* download_manager_;
ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
};
// Test Class ----------------------------------------------------------------
class BrowsingDataRemoverTest : public testing::Test {
public:
BrowsingDataRemoverTest()
: profile_(new TestingProfile()),
clear_domain_reliability_tester_(GetProfile()) {
callback_subscription_ =
BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails,
base::Unretained(this)));
}
~BrowsingDataRemoverTest() override {}
void TearDown() override {
#if defined(ENABLE_EXTENSIONS)
mock_policy_ = nullptr;
#endif
// TestingProfile contains a DOMStorageContext. BrowserContext's destructor
// posts a message to the WEBKIT thread to delete some of its member
// variables. We need to ensure that the profile is destroyed, and that
// the message loop is cleared out, before destroying the threads and loop.
// Otherwise we leak memory.
profile_.reset();
base::MessageLoop::current()->RunUntilIdle();
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
}
void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
int remove_mask,
bool include_protected_origins) {
BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
profile_.get(), period);
TestStoragePartition storage_partition;
remover->OverrideStoragePartitionForTesting(&storage_partition);
called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
// BrowsingDataRemover deletes itself when it completes.
int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
if (include_protected_origins)
origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
BrowsingDataRemoverCompletionObserver completion_observer(remover);
remover->Remove(remove_mask, origin_type_mask);
completion_observer.BlockUntilCompletion();
// Save so we can verify later.
storage_partition_removal_data_ =
storage_partition.GetStoragePartitionRemovalData();
}
void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
int remove_mask,
const GURL& remove_origin) {
BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
profile_.get(), period);
TestStoragePartition storage_partition;
remover->OverrideStoragePartitionForTesting(&storage_partition);
called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
// BrowsingDataRemover deletes itself when it completes.
BrowsingDataRemoverCompletionObserver completion_observer(remover);
remover->RemoveImpl(remove_mask, remove_origin,
BrowsingDataHelper::UNPROTECTED_WEB);
completion_observer.BlockUntilCompletion();
// Save so we can verify later.
storage_partition_removal_data_ =
storage_partition.GetStoragePartitionRemovalData();
}
TestingProfile* GetProfile() {
return profile_.get();
}
base::Time GetBeginTime() {
return called_with_details_->removal_begin;
}
int GetRemovalMask() {
return called_with_details_->removal_mask;
}
int GetOriginTypeMask() {
return called_with_details_->origin_type_mask;
}
StoragePartitionRemovalData GetStoragePartitionRemovalData() {
return storage_partition_removal_data_;
}
// Callback for browsing data removal events.
void NotifyWithDetails(
const BrowsingDataRemover::NotificationDetails& details) {
// We're not taking ownership of the details object, but storing a copy of
// it locally.
called_with_details_.reset(
new BrowsingDataRemover::NotificationDetails(details));
callback_subscription_.reset();
}
MockExtensionSpecialStoragePolicy* CreateMockPolicy() {
#if defined(ENABLE_EXTENSIONS)
mock_policy_ = new MockExtensionSpecialStoragePolicy;
return mock_policy_.get();
#else
NOTREACHED();
return nullptr;
#endif
}
storage::SpecialStoragePolicy* mock_policy() {
#if defined(ENABLE_EXTENSIONS)
return mock_policy_.get();
#else
return nullptr;
#endif
}
// If |kOrigin1| is protected when extensions are enabled, the expected
// result for tests where the OriginMatcherFunction result is variable.
bool ShouldRemoveForProtectedOriginOne() const {
#if defined(ENABLE_EXTENSIONS)
return false;
#else
return true;
#endif
}
const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
return clear_domain_reliability_tester_;
}
protected:
scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
private:
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
StoragePartitionRemovalData storage_partition_removal_data_;
#if defined(ENABLE_EXTENSIONS)
scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
#endif
BrowsingDataRemover::CallbackSubscription callback_subscription_;
// Needed to mock out DomainReliabilityService, even for unrelated tests.
ClearDomainReliabilityTester clear_domain_reliability_tester_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
};
// Tests ---------------------------------------------------------------------
TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify that storage partition was instructed to remove the cookies.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_COOKIES);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
}
TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_COOKIES,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify that storage partition was instructed to remove the cookies.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_COOKIES);
// Removing with time period other than EVERYTHING should not clear
// persistent storage data.
EXPECT_EQ(removal_data.quota_storage_remove_mask,
~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
}
#if defined(SAFE_BROWSING_SERVICE)
TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
RemoveSafeBrowsingCookieTester tester;
tester.AddCookie();
ASSERT_TRUE(tester.ContainsCookie());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_FALSE(tester.ContainsCookie());
}
TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
RemoveSafeBrowsingCookieTester tester;
tester.AddCookie();
ASSERT_TRUE(tester.ContainsCookie());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_COOKIES, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Removing with time period other than EVERYTHING should not clear safe
// browsing cookies.
EXPECT_TRUE(tester.ContainsCookie());
}
#endif
TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
RemoveChannelIDTester tester(GetProfile());
tester.AddChannelID(kTestOrigin1);
EXPECT_EQ(0, tester.ssl_config_changed_count());
EXPECT_EQ(1, tester.ChannelIDCount());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_EQ(1, tester.ssl_config_changed_count());
EXPECT_EQ(0, tester.ChannelIDCount());
}
TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
RemoveChannelIDTester tester(GetProfile());
base::Time now = base::Time::Now();
tester.AddChannelID(kTestOrigin1);
tester.AddChannelIDWithTimes(kTestOrigin2,
now - base::TimeDelta::FromHours(2));
EXPECT_EQ(0, tester.ssl_config_changed_count());
EXPECT_EQ(2, tester.ChannelIDCount());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_EQ(1, tester.ssl_config_changed_count());
ASSERT_EQ(1, tester.ChannelIDCount());
net::ChannelIDStore::ChannelIDList channel_ids;
tester.GetChannelIDList(&channel_ids);
ASSERT_EQ(1U, channel_ids.size());
EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
}
TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
#if defined(ENABLE_EXTENSIONS)
MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
// Protect kOrigin1.
policy->AddProtected(kOrigin1.GetOrigin());
#endif
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify that storage partition was instructed to remove the data correctly.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
// Check origin matcher.
EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
#if defined(ENABLE_EXTENSIONS)
// Protect kOrigin1.
MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
policy->AddProtected(kOrigin1.GetOrigin());
#endif
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
true);
EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
BrowsingDataHelper::PROTECTED_WEB, GetOriginTypeMask());
// Verify that storage partition was instructed to remove the data correctly.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
// Check origin matcher all http origin will match since we specified
// both protected and unprotected.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
#if defined(ENABLE_EXTENSIONS)
CreateMockPolicy();
#endif
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify that storage partition was instructed to remove the data correctly.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
// Persistent storage won't be deleted.
EXPECT_EQ(removal_data.quota_storage_remove_mask,
~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
// Check origin matcher.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
tester.AddHistory(kOrigin1, base::Time::Now());
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
}
TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
tester.AddHistory(kOrigin1, base::Time::Now());
tester.AddHistory(kOrigin2, two_hours_ago);
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
}
// This should crash (DCHECK) in Debug, but death tests don't work properly
// here.
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
PrefService* prefs = GetProfile()->GetPrefs();
prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
tester.AddHistory(kOrigin1, base::Time::Now());
tester.AddHistory(kOrigin2, two_hours_ago);
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Nothing should have been deleted.
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
}
#endif
TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
// Add some history.
RemoveHistoryTester history_tester;
ASSERT_TRUE(history_tester.Init(GetProfile()));
history_tester.AddHistory(kOrigin1, base::Time::Now());
ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_COOKIES;
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
removal_mask, false);
EXPECT_EQ(removal_mask, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
// The cookie would be deleted throught the StorageParition, check if the
// partition was requested to remove cookie.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_COOKIES);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
}
// This should crash (DCHECK) in Debug, but death tests don't work properly
// here.
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
PrefService* prefs = GetProfile()->GetPrefs();
prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
// Add some history.
RemoveHistoryTester history_tester;
ASSERT_TRUE(history_tester.Init(GetProfile()));
history_tester.AddHistory(kOrigin1, base::Time::Now());
ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_COOKIES;
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
removal_mask, false);
EXPECT_EQ(removal_mask, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// 1/2. History should remain.
EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
// 2/2. The cookie(s) would be deleted throught the StorageParition, check if
// the partition was requested to remove cookie.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_COOKIES);
// Persistent storage won't be deleted, since EVERYTHING was not specified.
EXPECT_EQ(removal_data.quota_storage_remove_mask,
~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
}
#endif
// Test that clearing history deletes favicons not associated with bookmarks.
TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
GURL page_url("http://a");
RemoveFaviconTester favicon_tester;
ASSERT_TRUE(favicon_tester.Init(GetProfile()));
favicon_tester.VisitAndAddFavicon(page_url);
ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url));
}
// Test that a bookmark's favicon is expired and not deleted when clearing
// history. Expiring the favicon causes the bookmark's favicon to be updated
// when the user next visits the bookmarked page. Expiring the bookmark's
// favicon is useful when the bookmark's favicon becomes incorrect (See
// crbug.com/474421 for a sample bug which causes this).
TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
GURL bookmarked_page("http://a");
TestingProfile* profile = GetProfile();
profile->CreateBookmarkModel(true);
bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForProfile(profile);
bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
base::ASCIIToUTF16("a"), bookmarked_page);
RemoveFaviconTester favicon_tester;
ASSERT_TRUE(favicon_tester.Init(GetProfile()));
favicon_tester.VisitAndAddFavicon(bookmarked_page);
ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
#if defined(ENABLE_EXTENSIONS)
CreateMockPolicy();
#endif
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check that all related origin data would be removed, that is, origin
// matcher would match these origin.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
#if defined(ENABLE_EXTENSIONS)
CreateMockPolicy();
#endif
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check that all related origin data would be removed, that is, origin
// matcher would match these origin.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
#if defined(ENABLE_EXTENSIONS)
CreateMockPolicy();
#endif
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check that all related origin data would be removed, that is, origin
// matcher would match these origin.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
// Remove Origin 1.
BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
kOrigin1);
EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_EQ(removal_data.remove_origin, kOrigin1);
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
// Persistent data would be left out since we are not removing from
// beginning of time.
uint32 expected_quota_mask =
~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check removal begin time.
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::LAST_WEEK,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
// Persistent data would be left out since we are not removing from
// beginning of time.
uint32 expected_quota_mask =
~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check removal begin time.
EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
#if defined(ENABLE_EXTENSIONS)
MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
// Protect kOrigin1.
policy->AddProtected(kOrigin1.GetOrigin());
#endif
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_WEBSQL |
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_INDEXEDDB,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check OriginMatcherFunction.
EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
#if defined(ENABLE_EXTENSIONS)
MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
// Protect kOrigin1.
policy->AddProtected(kOrigin1.GetOrigin());
#endif
// Try to remove kOrigin1. Expect failure.
BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
kOrigin1);
EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_EQ(removal_data.remove_origin, kOrigin1);
// Check OriginMatcherFunction.
EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
#if defined(ENABLE_EXTENSIONS)
MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
// Protect kOrigin1.
policy->AddProtected(kOrigin1.GetOrigin());
#endif
// Try to remove kOrigin1. Expect success.
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
true);
EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check OriginMatcherFunction, |kOrigin1| would match mask since we
// would have 'protected' specified in origin_type_mask.
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
#if defined(ENABLE_EXTENSIONS)
CreateMockPolicy();
#endif
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
BrowsingDataRemover::REMOVE_CACHE_STORAGE |
BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
BrowsingDataRemover::REMOVE_INDEXEDDB |
BrowsingDataRemover::REMOVE_WEBSQL,
GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Verify storage partition related stuffs.
StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
EXPECT_EQ(removal_data.remove_mask,
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_WEBSQL |
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
EXPECT_EQ(removal_data.quota_storage_remove_mask,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
EXPECT_TRUE(removal_data.remove_origin.is_empty());
// Check that extension and devtools data wouldn't be removed, that is,
// origin matcher would not match these origin.
EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
}
TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
tester.AddHistory(kOrigin1, base::Time::Now());
tester.AddHistory(kOrigin2, two_hours_ago);
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
// Nothing should have been deleted.
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
}
TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
tester.AddHistory(kOrigin1, base::Time::Now());
tester.AddHistory(kOrigin2, two_hours_ago);
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
}
// Verify that clearing autofill form data works.
TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
ASSERT_FALSE(tester.HasProfile());
tester.AddProfilesAndCards();
ASSERT_TRUE(tester.HasProfile());
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_FORM_DATA, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
ASSERT_FALSE(tester.HasProfile());
}
TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
ASSERT_FALSE(tester.HasProfile());
tester.AddProfilesAndCards();
ASSERT_TRUE(tester.HasProfile());
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_FORM_DATA, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
ASSERT_FALSE(tester.HasProfile());
}
// Verify that clearing autofill form data works.
TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
tester.AddProfilesAndCards();
EXPECT_FALSE(tester.HasOrigin(std::string()));
EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
EXPECT_TRUE(tester.HasOrigin(std::string()));
EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
}
TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
// The |completion_inhibitor| on the stack should prevent removal sessions
// from completing until after ContinueToCompletion() is called.
BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
// BrowsingDataRemover deletes itself when it completes.
BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
GetProfile(), BrowsingDataRemover::EVERYTHING);
remover->Remove(BrowsingDataRemover::REMOVE_HISTORY,
BrowsingDataHelper::UNPROTECTED_WEB);
// Process messages until the inhibitor is notified, and then some, to make
// sure we do not complete asynchronously before ContinueToCompletion() is
// called.
completion_inhibitor.BlockUntilNearCompletion();
base::RunLoop().RunUntilIdle();
// Verify that the completion notification has not yet been broadcasted.
EXPECT_EQ(-1, GetRemovalMask());
EXPECT_EQ(-1, GetOriginTypeMask());
// Now run the removal process until completion, and verify that observers are
// now notified, and the notifications is sent out.
BrowsingDataRemoverCompletionObserver completion_observer(remover);
completion_inhibitor.ContinueToCompletion();
completion_observer.BlockUntilCompletion();
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
}
TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
PrefService* prefs = GetProfile()->GetPrefs();
prefs->SetString(omnibox::kZeroSuggestCachedResults,
"[\"\", [\"foo\", \"bar\"]]");
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES,
false);
// Expect the prefs to be cleared when cookies are removed.
EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty());
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
}
#if defined(OS_CHROMEOS)
TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
chromeos::ScopedTestCrosSettings test_cros_settings;
chromeos::MockUserManager* mock_user_manager =
new testing::NiceMock<chromeos::MockUserManager>();
mock_user_manager->SetActiveUser("test@example.com");
chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
chromeos::DBusThreadManager::GetSetterForTesting();
chromeos::MockCryptohomeClient* cryptohome_client =
new chromeos::MockCryptohomeClient;
dbus_setter->SetCryptohomeClient(
scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
// Expect exactly one call. No calls means no attempt to delete keys and more
// than one call means a significant performance problem.
EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
.WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
chromeos::DBusThreadManager::Shutdown();
}
#endif
TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
EXPECT_EQ(0u, tester.clear_count());
}
TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, false);
EXPECT_EQ(1u, tester.clear_count());
EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
}
TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES, false);
EXPECT_EQ(1u, tester.clear_count());
EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
}
TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_COOKIES, false);
EXPECT_EQ(1u, tester.clear_count());
EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
}
TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES, true);
EXPECT_EQ(1u, tester.clear_count());
EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
}
// TODO(ttuttle): This isn't actually testing the no-monitor case, since
// BrowsingDataRemoverTest now creates one unconditionally, since it's needed
// for some unrelated test cases. This should be fixed so it tests the no-
// monitor case again.
TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
BlockUntilBrowsingDataRemoved(
BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_COOKIES, false);
}
TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) {
RemoveDownloadsTester tester(GetProfile());
const url::Origin expectedOrigin(kOrigin1);
EXPECT_CALL(*tester.download_manager(),
RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _));
BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1);
}
|