| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "components/domain_reliability/service.h" | 49 #include "components/domain_reliability/service.h" |
| 50 #include "content/public/browser/cookie_store_factory.h" | 50 #include "content/public/browser/cookie_store_factory.h" |
| 51 #include "content/public/browser/dom_storage_context.h" | 51 #include "content/public/browser/dom_storage_context.h" |
| 52 #include "content/public/browser/local_storage_usage_info.h" | 52 #include "content/public/browser/local_storage_usage_info.h" |
| 53 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
| 54 #include "content/public/browser/storage_partition.h" | 54 #include "content/public/browser/storage_partition.h" |
| 55 #include "content/public/test/test_browser_thread.h" | 55 #include "content/public/test/test_browser_thread.h" |
| 56 #include "content/public/test/test_browser_thread_bundle.h" | 56 #include "content/public/test/test_browser_thread_bundle.h" |
| 57 #include "content/public/test/test_utils.h" | 57 #include "content/public/test/test_utils.h" |
| 58 #include "net/cookies/cookie_store.h" | 58 #include "net/cookies/cookie_store.h" |
| 59 #include "net/ssl/server_bound_cert_service.h" | 59 #include "net/ssl/channel_id_service.h" |
| 60 #include "net/ssl/server_bound_cert_store.h" | 60 #include "net/ssl/channel_id_store.h" |
| 61 #include "net/ssl/ssl_client_cert_type.h" | 61 #include "net/ssl/ssl_client_cert_type.h" |
| 62 #include "net/url_request/url_request_context.h" | 62 #include "net/url_request/url_request_context.h" |
| 63 #include "net/url_request/url_request_context_getter.h" | 63 #include "net/url_request/url_request_context_getter.h" |
| 64 #include "testing/gmock/include/gmock/gmock.h" | 64 #include "testing/gmock/include/gmock/gmock.h" |
| 65 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
| 66 | 66 |
| 67 using content::BrowserThread; | 67 using content::BrowserThread; |
| 68 using content::StoragePartition; | 68 using content::StoragePartition; |
| 69 using domain_reliability::CLEAR_BEACONS; | 69 using domain_reliability::CLEAR_BEACONS; |
| 70 using domain_reliability::CLEAR_CONTEXTS; | 70 using domain_reliability::CLEAR_CONTEXTS; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 browser_process_->SetSafeBrowsingService(NULL); | 291 browser_process_->SetSafeBrowsingService(NULL); |
| 292 } | 292 } |
| 293 | 293 |
| 294 private: | 294 private: |
| 295 TestingBrowserProcess* browser_process_; | 295 TestingBrowserProcess* browser_process_; |
| 296 | 296 |
| 297 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); | 297 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); |
| 298 }; | 298 }; |
| 299 #endif | 299 #endif |
| 300 | 300 |
| 301 class RemoveServerBoundCertTester : public net::SSLConfigService::Observer { | 301 class RemoveChannelIDTester : public net::SSLConfigService::Observer { |
| 302 public: | 302 public: |
| 303 explicit RemoveServerBoundCertTester(TestingProfile* profile) | 303 explicit RemoveChannelIDTester(TestingProfile* profile) |
| 304 : ssl_config_changed_count_(0) { | 304 : ssl_config_changed_count_(0) { |
| 305 server_bound_cert_service_ = profile->GetRequestContext()-> | 305 channel_id_service_ = profile->GetRequestContext()-> |
| 306 GetURLRequestContext()->server_bound_cert_service(); | 306 GetURLRequestContext()->channel_id_service(); |
| 307 ssl_config_service_ = profile->GetSSLConfigService(); | 307 ssl_config_service_ = profile->GetSSLConfigService(); |
| 308 ssl_config_service_->AddObserver(this); | 308 ssl_config_service_->AddObserver(this); |
| 309 } | 309 } |
| 310 | 310 |
| 311 virtual ~RemoveServerBoundCertTester() { | 311 virtual ~RemoveChannelIDTester() { |
| 312 ssl_config_service_->RemoveObserver(this); | 312 ssl_config_service_->RemoveObserver(this); |
| 313 } | 313 } |
| 314 | 314 |
| 315 int ServerBoundCertCount() { | 315 int ChannelIDCount() { |
| 316 return server_bound_cert_service_->cert_count(); | 316 return channel_id_service_->cert_count(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Add a server bound cert for |server| with specific creation and expiry | 319 // Add a server bound cert for |server| with specific creation and expiry |
| 320 // times. The cert and key data will be filled with dummy values. | 320 // times. The cert and key data will be filled with dummy values. |
| 321 void AddServerBoundCertWithTimes(const std::string& server_identifier, | 321 void AddChannelIDWithTimes(const std::string& server_identifier, |
| 322 base::Time creation_time, | 322 base::Time creation_time, |
| 323 base::Time expiration_time) { | 323 base::Time expiration_time) { |
| 324 GetCertStore()->SetServerBoundCert(server_identifier, | 324 GetChannelIDStore()->SetChannelID(server_identifier, |
| 325 creation_time, | 325 creation_time, |
| 326 expiration_time, | 326 expiration_time, |
| 327 "a", | 327 "a", |
| 328 "b"); | 328 "b"); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Add a server bound cert for |server|, with the current time as the | 331 // Add a server bound cert for |server|, with the current time as the |
| 332 // creation time. The cert and key data will be filled with dummy values. | 332 // creation time. The cert and key data will be filled with dummy values. |
| 333 void AddServerBoundCert(const std::string& server_identifier) { | 333 void AddChannelID(const std::string& server_identifier) { |
| 334 base::Time now = base::Time::Now(); | 334 base::Time now = base::Time::Now(); |
| 335 AddServerBoundCertWithTimes(server_identifier, | 335 AddChannelIDWithTimes(server_identifier, |
| 336 now, | 336 now, |
| 337 now + base::TimeDelta::FromDays(1)); | 337 now + base::TimeDelta::FromDays(1)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void GetCertList(net::ServerBoundCertStore::ServerBoundCertList* certs) { | 340 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { |
| 341 GetCertStore()->GetAllServerBoundCerts( | 341 GetChannelIDStore()->GetAllChannelIDs( |
| 342 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback, certs)); | 342 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback, |
| 343 channel_ids)); |
| 343 } | 344 } |
| 344 | 345 |
| 345 net::ServerBoundCertStore* GetCertStore() { | 346 net::ChannelIDStore* GetChannelIDStore() { |
| 346 return server_bound_cert_service_->GetCertStore(); | 347 return channel_id_service_->GetChannelIDStore(); |
| 347 } | 348 } |
| 348 | 349 |
| 349 int ssl_config_changed_count() const { | 350 int ssl_config_changed_count() const { |
| 350 return ssl_config_changed_count_; | 351 return ssl_config_changed_count_; |
| 351 } | 352 } |
| 352 | 353 |
| 353 // net::SSLConfigService::Observer implementation: | 354 // net::SSLConfigService::Observer implementation: |
| 354 virtual void OnSSLConfigChanged() OVERRIDE { | 355 virtual void OnSSLConfigChanged() OVERRIDE { |
| 355 ssl_config_changed_count_++; | 356 ssl_config_changed_count_++; |
| 356 } | 357 } |
| 357 | 358 |
| 358 private: | 359 private: |
| 359 static void GetAllCertsCallback( | 360 static void GetAllChannelIDsCallback( |
| 360 net::ServerBoundCertStore::ServerBoundCertList* dest, | 361 net::ChannelIDStore::ChannelIDList* dest, |
| 361 const net::ServerBoundCertStore::ServerBoundCertList& result) { | 362 const net::ChannelIDStore::ChannelIDList& result) { |
| 362 *dest = result; | 363 *dest = result; |
| 363 } | 364 } |
| 364 | 365 |
| 365 net::ServerBoundCertService* server_bound_cert_service_; | 366 net::ChannelIDService* channel_id_service_; |
| 366 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 367 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
| 367 int ssl_config_changed_count_; | 368 int ssl_config_changed_count_; |
| 368 | 369 |
| 369 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); | 370 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); |
| 370 }; | 371 }; |
| 371 | 372 |
| 372 class RemoveHistoryTester { | 373 class RemoveHistoryTester { |
| 373 public: | 374 public: |
| 374 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} | 375 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} |
| 375 | 376 |
| 376 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { | 377 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { |
| 377 if (!profile->CreateHistoryService(true, false)) | 378 if (!profile->CreateHistoryService(true, false)) |
| 378 return false; | 379 return false; |
| 379 history_service_ = HistoryServiceFactory::GetForProfile( | 380 history_service_ = HistoryServiceFactory::GetForProfile( |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 BrowsingDataRemover::REMOVE_COOKIES, false); | 879 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 879 | 880 |
| 880 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | 881 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 881 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 882 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 882 // Removing with time period other than EVERYTHING should not clear safe | 883 // Removing with time period other than EVERYTHING should not clear safe |
| 883 // browsing cookies. | 884 // browsing cookies. |
| 884 EXPECT_TRUE(tester.ContainsCookie()); | 885 EXPECT_TRUE(tester.ContainsCookie()); |
| 885 } | 886 } |
| 886 #endif | 887 #endif |
| 887 | 888 |
| 888 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) { | 889 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) { |
| 889 RemoveServerBoundCertTester tester(GetProfile()); | 890 RemoveChannelIDTester tester(GetProfile()); |
| 890 | 891 |
| 891 tester.AddServerBoundCert(kTestOrigin1); | 892 tester.AddChannelID(kTestOrigin1); |
| 892 EXPECT_EQ(0, tester.ssl_config_changed_count()); | 893 EXPECT_EQ(0, tester.ssl_config_changed_count()); |
| 893 EXPECT_EQ(1, tester.ServerBoundCertCount()); | 894 EXPECT_EQ(1, tester.ChannelIDCount()); |
| 894 | 895 |
| 895 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 896 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 896 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); | 897 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); |
| 897 | 898 |
| 898 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); | 899 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); |
| 899 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 900 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 900 EXPECT_EQ(1, tester.ssl_config_changed_count()); | 901 EXPECT_EQ(1, tester.ssl_config_changed_count()); |
| 901 EXPECT_EQ(0, tester.ServerBoundCertCount()); | 902 EXPECT_EQ(0, tester.ChannelIDCount()); |
| 902 } | 903 } |
| 903 | 904 |
| 904 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) { | 905 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) { |
| 905 RemoveServerBoundCertTester tester(GetProfile()); | 906 RemoveChannelIDTester tester(GetProfile()); |
| 906 | 907 |
| 907 base::Time now = base::Time::Now(); | 908 base::Time now = base::Time::Now(); |
| 908 tester.AddServerBoundCert(kTestOrigin1); | 909 tester.AddChannelID(kTestOrigin1); |
| 909 tester.AddServerBoundCertWithTimes(kTestOrigin2, | 910 tester.AddChannelIDWithTimes(kTestOrigin2, |
| 910 now - base::TimeDelta::FromHours(2), | 911 now - base::TimeDelta::FromHours(2), |
| 911 now); | 912 now); |
| 912 EXPECT_EQ(0, tester.ssl_config_changed_count()); | 913 EXPECT_EQ(0, tester.ssl_config_changed_count()); |
| 913 EXPECT_EQ(2, tester.ServerBoundCertCount()); | 914 EXPECT_EQ(2, tester.ChannelIDCount()); |
| 914 | 915 |
| 915 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 916 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 916 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); | 917 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); |
| 917 | 918 |
| 918 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); | 919 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); |
| 919 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 920 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 920 EXPECT_EQ(1, tester.ssl_config_changed_count()); | 921 EXPECT_EQ(1, tester.ssl_config_changed_count()); |
| 921 ASSERT_EQ(1, tester.ServerBoundCertCount()); | 922 ASSERT_EQ(1, tester.ChannelIDCount()); |
| 922 net::ServerBoundCertStore::ServerBoundCertList certs; | 923 net::ChannelIDStore::ChannelIDList channel_ids; |
| 923 tester.GetCertList(&certs); | 924 tester.GetChannelIDList(&channel_ids); |
| 924 ASSERT_EQ(1U, certs.size()); | 925 ASSERT_EQ(1U, channel_ids.size()); |
| 925 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier()); | 926 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier()); |
| 926 } | 927 } |
| 927 | 928 |
| 928 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { | 929 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { |
| 929 // Protect kOrigin1. | 930 // Protect kOrigin1. |
| 930 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = | 931 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
| 931 new MockExtensionSpecialStoragePolicy; | 932 new MockExtensionSpecialStoragePolicy; |
| 932 mock_policy->AddProtected(kOrigin1.GetOrigin()); | 933 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 933 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); | 934 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); |
| 934 | 935 |
| 935 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 936 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 EXPECT_EQ(1u, tester.clear_count()); | 1781 EXPECT_EQ(1u, tester.clear_count()); |
| 1781 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 1782 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 1782 } | 1783 } |
| 1783 | 1784 |
| 1784 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { | 1785 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { |
| 1785 BlockUntilBrowsingDataRemoved( | 1786 BlockUntilBrowsingDataRemoved( |
| 1786 BrowsingDataRemover::EVERYTHING, | 1787 BrowsingDataRemover::EVERYTHING, |
| 1787 BrowsingDataRemover::REMOVE_HISTORY | | 1788 BrowsingDataRemover::REMOVE_HISTORY | |
| 1788 BrowsingDataRemover::REMOVE_COOKIES, false); | 1789 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 1789 } | 1790 } |
| OLD | NEW |