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

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

Issue 356713005: Rename ServerBoundCert => ChannelID to reflect the current name (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix cookies_list.js Created 6 years, 4 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 | Annotate | Revision Log
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 BrowsingDataRemover::REMOVE_COOKIES, false); 880 BrowsingDataRemover::REMOVE_COOKIES, false);
880 881
881 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 882 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
882 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 883 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
883 // Removing with time period other than EVERYTHING should not clear safe 884 // Removing with time period other than EVERYTHING should not clear safe
884 // browsing cookies. 885 // browsing cookies.
885 EXPECT_TRUE(tester.ContainsCookie()); 886 EXPECT_TRUE(tester.ContainsCookie());
886 } 887 }
887 #endif 888 #endif
888 889
889 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) { 890 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
890 RemoveServerBoundCertTester tester(GetProfile()); 891 RemoveChannelIDTester tester(GetProfile());
891 892
892 tester.AddServerBoundCert(kTestOrigin1); 893 tester.AddChannelID(kTestOrigin1);
893 EXPECT_EQ(0, tester.ssl_config_changed_count()); 894 EXPECT_EQ(0, tester.ssl_config_changed_count());
894 EXPECT_EQ(1, tester.ServerBoundCertCount()); 895 EXPECT_EQ(1, tester.ChannelIDCount());
895 896
896 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 897 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
897 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); 898 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
898 899
899 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); 900 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
900 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 901 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
901 EXPECT_EQ(1, tester.ssl_config_changed_count()); 902 EXPECT_EQ(1, tester.ssl_config_changed_count());
902 EXPECT_EQ(0, tester.ServerBoundCertCount()); 903 EXPECT_EQ(0, tester.ChannelIDCount());
903 } 904 }
904 905
905 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) { 906 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
906 RemoveServerBoundCertTester tester(GetProfile()); 907 RemoveChannelIDTester tester(GetProfile());
907 908
908 base::Time now = base::Time::Now(); 909 base::Time now = base::Time::Now();
909 tester.AddServerBoundCert(kTestOrigin1); 910 tester.AddChannelID(kTestOrigin1);
910 tester.AddServerBoundCertWithTimes(kTestOrigin2, 911 tester.AddChannelIDWithTimes(kTestOrigin2,
911 now - base::TimeDelta::FromHours(2), 912 now - base::TimeDelta::FromHours(2),
912 now); 913 now);
913 EXPECT_EQ(0, tester.ssl_config_changed_count()); 914 EXPECT_EQ(0, tester.ssl_config_changed_count());
914 EXPECT_EQ(2, tester.ServerBoundCertCount()); 915 EXPECT_EQ(2, tester.ChannelIDCount());
915 916
916 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 917 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
917 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); 918 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
918 919
919 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); 920 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
920 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 921 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
921 EXPECT_EQ(1, tester.ssl_config_changed_count()); 922 EXPECT_EQ(1, tester.ssl_config_changed_count());
922 ASSERT_EQ(1, tester.ServerBoundCertCount()); 923 ASSERT_EQ(1, tester.ChannelIDCount());
923 net::ServerBoundCertStore::ServerBoundCertList certs; 924 net::ChannelIDStore::ChannelIDList channel_ids;
924 tester.GetCertList(&certs); 925 tester.GetChannelIDList(&channel_ids);
925 ASSERT_EQ(1U, certs.size()); 926 ASSERT_EQ(1U, channel_ids.size());
926 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier()); 927 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
927 } 928 }
928 929
929 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { 930 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
930 // Protect kOrigin1. 931 // Protect kOrigin1.
931 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 932 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
932 new MockExtensionSpecialStoragePolicy; 933 new MockExtensionSpecialStoragePolicy;
933 mock_policy->AddProtected(kOrigin1.GetOrigin()); 934 mock_policy->AddProtected(kOrigin1.GetOrigin());
934 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 935 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
935 936
936 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 937 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 EXPECT_EQ(1u, tester.clear_count()); 1750 EXPECT_EQ(1u, tester.clear_count());
1750 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); 1751 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1751 } 1752 }
1752 1753
1753 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { 1754 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) {
1754 BlockUntilBrowsingDataRemoved( 1755 BlockUntilBrowsingDataRemoved(
1755 BrowsingDataRemover::EVERYTHING, 1756 BrowsingDataRemover::EVERYTHING,
1756 BrowsingDataRemover::REMOVE_HISTORY | 1757 BrowsingDataRemover::REMOVE_HISTORY |
1757 BrowsingDataRemover::REMOVE_COOKIES, false); 1758 BrowsingDataRemover::REMOVE_COOKIES, false);
1758 } 1759 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698