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