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 GetCertStore()->SetChannelID(server_identifier, |
325 creation_time, | 325 creation_time, |
326 expiration_time, | 326 expiration_time, |
327 "a", | 327 "a", |
328 "b"); | 328 "b"); |
wtc
2014/07/01 19:50:48
Fix the indentation of this entire method.
Ryan Hamilton
2014/07/21 19:12:04
Done.
| |
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 GetCertList(net::ChannelIDStore::ChannelIDList* certs) { |
wtc
2014/07/01 19:50:48
GetCertList => GetChannelIDList
certs => channel_
Ryan Hamilton
2014/07/21 19:12:04
Done.
| |
341 GetCertStore()->GetAllServerBoundCerts( | 341 GetCertStore()->GetAllChannelIDs( |
342 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback, certs)); | 342 base::Bind(&RemoveChannelIDTester::GetAllCertsCallback, certs)); |
343 } | 343 } |
344 | 344 |
345 net::ServerBoundCertStore* GetCertStore() { | 345 net::ChannelIDStore* GetCertStore() { |
wtc
2014/07/01 19:50:48
GetCertStore => GetChannelIDStore
Ryan Hamilton
2014/07/21 19:12:04
Done.
| |
346 return server_bound_cert_service_->GetCertStore(); | 346 return channel_id_service_->GetCertStore(); |
347 } | 347 } |
348 | 348 |
349 int ssl_config_changed_count() const { | 349 int ssl_config_changed_count() const { |
350 return ssl_config_changed_count_; | 350 return ssl_config_changed_count_; |
351 } | 351 } |
352 | 352 |
353 // net::SSLConfigService::Observer implementation: | 353 // net::SSLConfigService::Observer implementation: |
354 virtual void OnSSLConfigChanged() OVERRIDE { | 354 virtual void OnSSLConfigChanged() OVERRIDE { |
355 ssl_config_changed_count_++; | 355 ssl_config_changed_count_++; |
356 } | 356 } |
357 | 357 |
358 private: | 358 private: |
359 static void GetAllCertsCallback( | 359 static void GetAllCertsCallback( |
wtc
2014/07/01 19:50:48
GetAllCertsCallback => GetAllChannelIDsCallback
Ryan Hamilton
2014/07/21 19:12:04
Done.
| |
360 net::ServerBoundCertStore::ServerBoundCertList* dest, | 360 net::ChannelIDStore::ChannelIDList* dest, |
361 const net::ServerBoundCertStore::ServerBoundCertList& result) { | 361 const net::ChannelIDStore::ChannelIDList& result) { |
362 *dest = result; | 362 *dest = result; |
363 } | 363 } |
364 | 364 |
365 net::ServerBoundCertService* server_bound_cert_service_; | 365 net::ChannelIDService* channel_id_service_; |
366 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 366 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
367 int ssl_config_changed_count_; | 367 int ssl_config_changed_count_; |
368 | 368 |
369 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); | 369 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); |
370 }; | 370 }; |
371 | 371 |
372 class RemoveHistoryTester { | 372 class RemoveHistoryTester { |
373 public: | 373 public: |
374 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} | 374 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} |
375 | 375 |
376 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { | 376 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { |
377 if (!profile->CreateHistoryService(true, false)) | 377 if (!profile->CreateHistoryService(true, false)) |
378 return false; | 378 return false; |
379 history_service_ = HistoryServiceFactory::GetForProfile( | 379 history_service_ = HistoryServiceFactory::GetForProfile( |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 BrowsingDataRemover::REMOVE_COOKIES, false); | 878 BrowsingDataRemover::REMOVE_COOKIES, false); |
879 | 879 |
880 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | 880 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
881 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 881 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
882 // Removing with time period other than EVERYTHING should not clear safe | 882 // Removing with time period other than EVERYTHING should not clear safe |
883 // browsing cookies. | 883 // browsing cookies. |
884 EXPECT_TRUE(tester.ContainsCookie()); | 884 EXPECT_TRUE(tester.ContainsCookie()); |
885 } | 885 } |
886 #endif | 886 #endif |
887 | 887 |
888 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) { | 888 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) { |
889 RemoveServerBoundCertTester tester(GetProfile()); | 889 RemoveChannelIDTester tester(GetProfile()); |
890 | 890 |
891 tester.AddServerBoundCert(kTestOrigin1); | 891 tester.AddChannelID(kTestOrigin1); |
892 EXPECT_EQ(0, tester.ssl_config_changed_count()); | 892 EXPECT_EQ(0, tester.ssl_config_changed_count()); |
893 EXPECT_EQ(1, tester.ServerBoundCertCount()); | 893 EXPECT_EQ(1, tester.ChannelIDCount()); |
894 | 894 |
895 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 895 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
896 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); | 896 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); |
897 | 897 |
898 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); | 898 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); |
899 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 899 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
900 EXPECT_EQ(1, tester.ssl_config_changed_count()); | 900 EXPECT_EQ(1, tester.ssl_config_changed_count()); |
901 EXPECT_EQ(0, tester.ServerBoundCertCount()); | 901 EXPECT_EQ(0, tester.ChannelIDCount()); |
902 } | 902 } |
903 | 903 |
904 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) { | 904 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) { |
905 RemoveServerBoundCertTester tester(GetProfile()); | 905 RemoveChannelIDTester tester(GetProfile()); |
906 | 906 |
907 base::Time now = base::Time::Now(); | 907 base::Time now = base::Time::Now(); |
908 tester.AddServerBoundCert(kTestOrigin1); | 908 tester.AddChannelID(kTestOrigin1); |
909 tester.AddServerBoundCertWithTimes(kTestOrigin2, | 909 tester.AddChannelIDWithTimes(kTestOrigin2, |
910 now - base::TimeDelta::FromHours(2), | 910 now - base::TimeDelta::FromHours(2), |
911 now); | 911 now); |
912 EXPECT_EQ(0, tester.ssl_config_changed_count()); | 912 EXPECT_EQ(0, tester.ssl_config_changed_count()); |
913 EXPECT_EQ(2, tester.ServerBoundCertCount()); | 913 EXPECT_EQ(2, tester.ChannelIDCount()); |
914 | 914 |
915 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 915 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
916 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); | 916 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); |
917 | 917 |
918 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); | 918 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); |
919 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 919 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
920 EXPECT_EQ(1, tester.ssl_config_changed_count()); | 920 EXPECT_EQ(1, tester.ssl_config_changed_count()); |
921 ASSERT_EQ(1, tester.ServerBoundCertCount()); | 921 ASSERT_EQ(1, tester.ChannelIDCount()); |
922 net::ServerBoundCertStore::ServerBoundCertList certs; | 922 net::ChannelIDStore::ChannelIDList certs; |
923 tester.GetCertList(&certs); | 923 tester.GetCertList(&certs); |
924 ASSERT_EQ(1U, certs.size()); | 924 ASSERT_EQ(1U, certs.size()); |
925 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier()); | 925 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier()); |
926 } | 926 } |
927 | 927 |
928 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { | 928 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { |
929 // Protect kOrigin1. | 929 // Protect kOrigin1. |
930 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = | 930 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
931 new MockExtensionSpecialStoragePolicy; | 931 new MockExtensionSpecialStoragePolicy; |
932 mock_policy->AddProtected(kOrigin1.GetOrigin()); | 932 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 EXPECT_EQ(1u, tester.clear_count()); | 1780 EXPECT_EQ(1u, tester.clear_count()); |
1781 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 1781 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
1782 } | 1782 } |
1783 | 1783 |
1784 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { | 1784 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { |
1785 BlockUntilBrowsingDataRemoved( | 1785 BlockUntilBrowsingDataRemoved( |
1786 BrowsingDataRemover::EVERYTHING, | 1786 BrowsingDataRemover::EVERYTHING, |
1787 BrowsingDataRemover::REMOVE_HISTORY | | 1787 BrowsingDataRemover::REMOVE_HISTORY | |
1788 BrowsingDataRemover::REMOVE_COOKIES, false); | 1788 BrowsingDataRemover::REMOVE_COOKIES, false); |
1789 } | 1789 } |
OLD | NEW |