OLD | NEW |
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 326 |
327 net::ServerBoundCertService* server_bound_cert_service_; | 327 net::ServerBoundCertService* server_bound_cert_service_; |
328 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 328 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
329 int ssl_config_changed_count_; | 329 int ssl_config_changed_count_; |
330 | 330 |
331 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); | 331 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); |
332 }; | 332 }; |
333 | 333 |
334 class RemoveHistoryTester { | 334 class RemoveHistoryTester { |
335 public: | 335 public: |
336 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} | 336 explicit RemoveHistoryTester(TestingProfile* profile) |
337 | 337 : query_url_success_(false) { |
338 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { | 338 profile->CreateHistoryService(true, false); |
339 if (!profile->CreateHistoryService(true, false)) | |
340 return false; | |
341 history_service_ = HistoryServiceFactory::GetForProfile( | 339 history_service_ = HistoryServiceFactory::GetForProfile( |
342 profile, Profile::EXPLICIT_ACCESS); | 340 profile, Profile::EXPLICIT_ACCESS); |
343 return true; | |
344 } | 341 } |
345 | 342 |
346 // Returns true, if the given URL exists in the history service. | 343 // Returns true, if the given URL exists in the history service. |
347 bool HistoryContainsURL(const GURL& url) { | 344 bool HistoryContainsURL(const GURL& url) { |
348 history_service_->QueryURL( | 345 history_service_->QueryURL( |
349 url, | 346 url, |
350 true, | 347 true, |
351 &consumer_, | 348 &consumer_, |
352 base::Bind(&RemoveHistoryTester::SaveResultAndQuit, | 349 base::Bind(&RemoveHistoryTester::SaveResultAndQuit, |
353 base::Unretained(this))); | 350 base::Unretained(this))); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 819 |
823 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); | 820 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); |
824 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 821 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
825 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 822 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
826 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 823 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
827 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 824 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
828 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOriginExt)); | 825 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOriginExt)); |
829 } | 826 } |
830 | 827 |
831 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { | 828 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
832 RemoveHistoryTester tester; | 829 RemoveHistoryTester tester(GetProfile()); |
833 ASSERT_TRUE(tester.Init(GetProfile())); | |
834 | 830 |
835 tester.AddHistory(kOrigin1, base::Time::Now()); | 831 tester.AddHistory(kOrigin1, base::Time::Now()); |
836 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 832 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
837 | 833 |
838 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 834 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
839 BrowsingDataRemover::REMOVE_HISTORY, false); | 835 BrowsingDataRemover::REMOVE_HISTORY, false); |
840 | 836 |
841 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 837 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
842 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 838 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
843 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); | 839 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); |
844 } | 840 } |
845 | 841 |
846 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { | 842 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { |
847 RemoveHistoryTester tester; | 843 RemoveHistoryTester tester(GetProfile()); |
848 ASSERT_TRUE(tester.Init(GetProfile())); | |
849 | 844 |
850 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | 845 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
851 | 846 |
852 tester.AddHistory(kOrigin1, base::Time::Now()); | 847 tester.AddHistory(kOrigin1, base::Time::Now()); |
853 tester.AddHistory(kOrigin2, two_hours_ago); | 848 tester.AddHistory(kOrigin2, two_hours_ago); |
854 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 849 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
855 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); | 850 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
856 | 851 |
857 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 852 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
858 BrowsingDataRemover::REMOVE_HISTORY, false); | 853 BrowsingDataRemover::REMOVE_HISTORY, false); |
(...skipping 25 matching lines...) Expand all Loading... |
884 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 879 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
885 | 880 |
886 // Nothing should have been deleted. | 881 // Nothing should have been deleted. |
887 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 882 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
888 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); | 883 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
889 } | 884 } |
890 #endif | 885 #endif |
891 | 886 |
892 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) { | 887 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) { |
893 // Add some history. | 888 // Add some history. |
894 RemoveHistoryTester history_tester; | 889 RemoveHistoryTester history_tester(GetProfile()); |
895 ASSERT_TRUE(history_tester.Init(GetProfile())); | |
896 history_tester.AddHistory(kOrigin1, base::Time::Now()); | 890 history_tester.AddHistory(kOrigin1, base::Time::Now()); |
897 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); | 891 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); |
898 | 892 |
899 // Add some cookies. | 893 // Add some cookies. |
900 RemoveProfileCookieTester cookie_tester(GetProfile()); | 894 RemoveProfileCookieTester cookie_tester(GetProfile()); |
901 cookie_tester.AddCookie(); | 895 cookie_tester.AddCookie(); |
902 ASSERT_TRUE(cookie_tester.ContainsCookie()); | 896 ASSERT_TRUE(cookie_tester.ContainsCookie()); |
903 | 897 |
904 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | | 898 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | |
905 BrowsingDataRemover::REMOVE_COOKIES; | 899 BrowsingDataRemover::REMOVE_COOKIES; |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 kClientFile)); | 1281 kClientFile)); |
1288 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginExt, kPersistent, | 1282 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginExt, kPersistent, |
1289 kClientFile)); | 1283 kClientFile)); |
1290 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, | 1284 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, |
1291 kClientFile)); | 1285 kClientFile)); |
1292 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, | 1286 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, |
1293 kClientFile)); | 1287 kClientFile)); |
1294 } | 1288 } |
1295 | 1289 |
1296 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) { | 1290 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) { |
1297 RemoveHistoryTester tester; | 1291 RemoveHistoryTester tester(GetProfile()); |
1298 ASSERT_TRUE(tester.Init(GetProfile())); | |
1299 | 1292 |
1300 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | 1293 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
1301 | 1294 |
1302 tester.AddHistory(kOrigin1, base::Time::Now()); | 1295 tester.AddHistory(kOrigin1, base::Time::Now()); |
1303 tester.AddHistory(kOrigin2, two_hours_ago); | 1296 tester.AddHistory(kOrigin2, two_hours_ago); |
1304 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 1297 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
1305 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); | 1298 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
1306 | 1299 |
1307 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 1300 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
1308 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); | 1301 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); |
1309 | 1302 |
1310 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 1303 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
1311 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 1304 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
1312 | 1305 |
1313 // Nothing should have been deleted. | 1306 // Nothing should have been deleted. |
1314 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 1307 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
1315 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2)); | 1308 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2)); |
1316 } | 1309 } |
1317 | 1310 |
1318 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) { | 1311 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) { |
1319 RemoveHistoryTester tester; | 1312 RemoveHistoryTester tester(GetProfile()); |
1320 ASSERT_TRUE(tester.Init(GetProfile())); | |
1321 | 1313 |
1322 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | 1314 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
1323 | 1315 |
1324 tester.AddHistory(kOrigin1, base::Time::Now()); | 1316 tester.AddHistory(kOrigin1, base::Time::Now()); |
1325 tester.AddHistory(kOrigin2, two_hours_ago); | 1317 tester.AddHistory(kOrigin2, two_hours_ago); |
1326 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 1318 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
1327 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); | 1319 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
1328 | 1320 |
1329 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, | 1321 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, |
1330 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); | 1322 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 BlockUntilBrowsingDataRemoved( | 1375 BlockUntilBrowsingDataRemoved( |
1384 BrowsingDataRemover::LAST_HOUR, | 1376 BrowsingDataRemover::LAST_HOUR, |
1385 BrowsingDataRemover::REMOVE_HISTORY, false); | 1377 BrowsingDataRemover::REMOVE_HISTORY, false); |
1386 | 1378 |
1387 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 1379 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
1388 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 1380 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
1389 EXPECT_TRUE(tester.HasOrigin(std::string())); | 1381 EXPECT_TRUE(tester.HasOrigin(std::string())); |
1390 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); | 1382 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); |
1391 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin)); | 1383 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin)); |
1392 } | 1384 } |
OLD | NEW |