Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover_unittest.cc

Issue 19616004: Add asserts to TestingProfile::CreateHistoryService to ensure files are deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix release unit tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 net::ServerBoundCertService* server_bound_cert_service_; 325 net::ServerBoundCertService* server_bound_cert_service_;
326 scoped_refptr<net::SSLConfigService> ssl_config_service_; 326 scoped_refptr<net::SSLConfigService> ssl_config_service_;
327 int ssl_config_changed_count_; 327 int ssl_config_changed_count_;
328 328
329 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); 329 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester);
330 }; 330 };
331 331
332 class RemoveHistoryTester { 332 class RemoveHistoryTester {
333 public: 333 public:
334 explicit RemoveHistoryTester(TestingProfile* profile) 334 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {}
335 : query_url_success_(false) { 335
336 profile->CreateHistoryService(true, false); 336 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
337 if (!profile->CreateHistoryService(true, false))
338 return false;
337 history_service_ = HistoryServiceFactory::GetForProfile( 339 history_service_ = HistoryServiceFactory::GetForProfile(
338 profile, Profile::EXPLICIT_ACCESS); 340 profile, Profile::EXPLICIT_ACCESS);
341 return true;
339 } 342 }
340 343
341 // Returns true, if the given URL exists in the history service. 344 // Returns true, if the given URL exists in the history service.
342 bool HistoryContainsURL(const GURL& url) { 345 bool HistoryContainsURL(const GURL& url) {
343 history_service_->QueryURL( 346 history_service_->QueryURL(
344 url, 347 url,
345 true, 348 true,
346 &consumer_, 349 &consumer_,
347 base::Bind(&RemoveHistoryTester::SaveResultAndQuit, 350 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
348 base::Unretained(this))); 351 base::Unretained(this)));
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 820
818 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 821 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
819 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 822 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
820 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); 823 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1));
821 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); 824 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2));
822 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 825 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
823 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOriginExt)); 826 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOriginExt));
824 } 827 }
825 828
826 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { 829 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
827 RemoveHistoryTester tester(GetProfile()); 830 RemoveHistoryTester tester;
831 ASSERT_TRUE(tester.Init(GetProfile()));
828 832
829 tester.AddHistory(kOrigin1, base::Time::Now()); 833 tester.AddHistory(kOrigin1, base::Time::Now());
830 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 834 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
831 835
832 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 836 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
833 BrowsingDataRemover::REMOVE_HISTORY, false); 837 BrowsingDataRemover::REMOVE_HISTORY, false);
834 838
835 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 839 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
836 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 840 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
837 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); 841 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
838 } 842 }
839 843
840 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { 844 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
841 RemoveHistoryTester tester(GetProfile()); 845 RemoveHistoryTester tester;
846 ASSERT_TRUE(tester.Init(GetProfile()));
842 847
843 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 848 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
844 849
845 tester.AddHistory(kOrigin1, base::Time::Now()); 850 tester.AddHistory(kOrigin1, base::Time::Now());
846 tester.AddHistory(kOrigin2, two_hours_ago); 851 tester.AddHistory(kOrigin2, two_hours_ago);
847 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 852 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
848 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 853 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
849 854
850 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 855 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
851 BrowsingDataRemover::REMOVE_HISTORY, false); 856 BrowsingDataRemover::REMOVE_HISTORY, false);
852 857
853 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 858 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
854 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 859 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
855 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); 860 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
856 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); 861 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
857 } 862 }
858 863
859 // This should crash (DCHECK) in Debug, but death tests don't work properly 864 // This should crash (DCHECK) in Debug, but death tests don't work properly
860 // here. 865 // here.
861 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 866 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
862 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) { 867 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
863 RemoveHistoryTester tester(GetProfile()); 868 RemoveHistoryTester tester;
869 ASSERT_TRUE(tester.Init(GetProfile()));
864 PrefService* prefs = GetProfile()->GetPrefs(); 870 PrefService* prefs = GetProfile()->GetPrefs();
865 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 871 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
866 872
867 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 873 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
868 874
869 tester.AddHistory(kOrigin1, base::Time::Now()); 875 tester.AddHistory(kOrigin1, base::Time::Now());
870 tester.AddHistory(kOrigin2, two_hours_ago); 876 tester.AddHistory(kOrigin2, two_hours_ago);
871 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 877 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
872 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 878 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
873 879
874 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 880 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
875 BrowsingDataRemover::REMOVE_HISTORY, false); 881 BrowsingDataRemover::REMOVE_HISTORY, false);
876 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 882 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
877 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 883 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
878 884
879 // Nothing should have been deleted. 885 // Nothing should have been deleted.
880 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); 886 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
881 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); 887 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
882 } 888 }
883 #endif 889 #endif
884 890
885 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) { 891 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
886 // Add some history. 892 // Add some history.
887 RemoveHistoryTester history_tester(GetProfile()); 893 RemoveHistoryTester history_tester;
894 ASSERT_TRUE(history_tester.Init(GetProfile()));
888 history_tester.AddHistory(kOrigin1, base::Time::Now()); 895 history_tester.AddHistory(kOrigin1, base::Time::Now());
889 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); 896 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
890 897
891 // Add some cookies. 898 // Add some cookies.
892 RemoveProfileCookieTester cookie_tester(GetProfile()); 899 RemoveProfileCookieTester cookie_tester(GetProfile());
893 cookie_tester.AddCookie(); 900 cookie_tester.AddCookie();
894 ASSERT_TRUE(cookie_tester.ContainsCookie()); 901 ASSERT_TRUE(cookie_tester.ContainsCookie());
895 902
896 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | 903 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
897 BrowsingDataRemover::REMOVE_COOKIES; 904 BrowsingDataRemover::REMOVE_COOKIES;
898 905
899 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 906 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
900 removal_mask, false); 907 removal_mask, false);
901 908
902 EXPECT_EQ(removal_mask, GetRemovalMask()); 909 EXPECT_EQ(removal_mask, GetRemovalMask());
903 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 910 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
904 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1)); 911 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
905 EXPECT_FALSE(cookie_tester.ContainsCookie()); 912 EXPECT_FALSE(cookie_tester.ContainsCookie());
906 } 913 }
907 914
908 // This should crash (DCHECK) in Debug, but death tests don't work properly 915 // This should crash (DCHECK) in Debug, but death tests don't work properly
909 // here. 916 // here.
910 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 917 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
911 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) { 918 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
912 PrefService* prefs = GetProfile()->GetPrefs(); 919 PrefService* prefs = GetProfile()->GetPrefs();
913 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 920 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
914 921
915 // Add some history. 922 // Add some history.
916 RemoveHistoryTester history_tester(GetProfile()); 923 RemoveHistoryTester history_tester;
924 ASSERT_TRUE(history_tester.Init(GetProfile()));
917 history_tester.AddHistory(kOrigin1, base::Time::Now()); 925 history_tester.AddHistory(kOrigin1, base::Time::Now());
918 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); 926 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
919 927
920 // Add some cookies. 928 // Add some cookies.
921 RemoveProfileCookieTester cookie_tester(GetProfile()); 929 RemoveProfileCookieTester cookie_tester(GetProfile());
922 cookie_tester.AddCookie(); 930 cookie_tester.AddCookie();
923 ASSERT_TRUE(cookie_tester.ContainsCookie()); 931 ASSERT_TRUE(cookie_tester.ContainsCookie());
924 932
925 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | 933 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
926 BrowsingDataRemover::REMOVE_COOKIES; 934 BrowsingDataRemover::REMOVE_COOKIES;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 kClientFile)); 1287 kClientFile));
1280 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginExt, kPersistent, 1288 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginExt, kPersistent,
1281 kClientFile)); 1289 kClientFile));
1282 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, 1290 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary,
1283 kClientFile)); 1291 kClientFile));
1284 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, 1292 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent,
1285 kClientFile)); 1293 kClientFile));
1286 } 1294 }
1287 1295
1288 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) { 1296 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1289 RemoveHistoryTester tester(GetProfile()); 1297 RemoveHistoryTester tester;
1298 ASSERT_TRUE(tester.Init(GetProfile()));
1290 1299
1291 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 1300 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1292 1301
1293 tester.AddHistory(kOrigin1, base::Time::Now()); 1302 tester.AddHistory(kOrigin1, base::Time::Now());
1294 tester.AddHistory(kOrigin2, two_hours_ago); 1303 tester.AddHistory(kOrigin2, two_hours_ago);
1295 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1304 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1296 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 1305 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1297 1306
1298 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, 1307 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1299 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); 1308 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1300 1309
1301 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1310 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1302 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1311 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1303 1312
1304 // Nothing should have been deleted. 1313 // Nothing should have been deleted.
1305 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1314 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1306 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2)); 1315 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1307 } 1316 }
1308 1317
1309 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) { 1318 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1310 RemoveHistoryTester tester(GetProfile()); 1319 RemoveHistoryTester tester;
1320 ASSERT_TRUE(tester.Init(GetProfile()));
1311 1321
1312 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 1322 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1313 1323
1314 tester.AddHistory(kOrigin1, base::Time::Now()); 1324 tester.AddHistory(kOrigin1, base::Time::Now());
1315 tester.AddHistory(kOrigin2, two_hours_ago); 1325 tester.AddHistory(kOrigin2, two_hours_ago);
1316 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1326 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1317 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 1327 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1318 1328
1319 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, 1329 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1320 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); 1330 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 BlockUntilBrowsingDataRemoved( 1383 BlockUntilBrowsingDataRemoved(
1374 BrowsingDataRemover::LAST_HOUR, 1384 BrowsingDataRemover::LAST_HOUR,
1375 BrowsingDataRemover::REMOVE_HISTORY, false); 1385 BrowsingDataRemover::REMOVE_HISTORY, false);
1376 1386
1377 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1387 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1378 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1388 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1379 EXPECT_TRUE(tester.HasOrigin(std::string())); 1389 EXPECT_TRUE(tester.HasOrigin(std::string()));
1380 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); 1390 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1381 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin)); 1391 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1382 } 1392 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model_unittest.cc ('k') | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698