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

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

Issue 9617039: Change Origin bound certs -> Domain bound certs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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_remover.h" 5 #include "chrome/browser/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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 browser_process_->SetSafeBrowsingService(NULL); 189 browser_process_->SetSafeBrowsingService(NULL);
190 } 190 }
191 191
192 private: 192 private:
193 TestingBrowserProcess* browser_process_; 193 TestingBrowserProcess* browser_process_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); 195 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
196 }; 196 };
197 #endif 197 #endif
198 198
199 class RemoveOriginBoundCertTester : public BrowsingDataRemoverTester { 199 class RemoveServerBoundCertTester : public BrowsingDataRemoverTester {
200 public: 200 public:
201 explicit RemoveOriginBoundCertTester(TestingProfile* profile) { 201 explicit RemoveServerBoundCertTester(TestingProfile* profile) {
202 profile->CreateRequestContext(); 202 profile->CreateRequestContext();
203 ob_cert_service_ = profile->GetRequestContext()->GetURLRequestContext()-> 203 server_bound_cert_service_ = profile->GetRequestContext()->
204 origin_bound_cert_service(); 204 GetURLRequestContext()->server_bound_cert_service();
205 } 205 }
206 206
207 int OriginBoundCertCount() { 207 int ServerBoundCertCount() {
208 return ob_cert_service_->cert_count(); 208 return server_bound_cert_service_->cert_count();
209 } 209 }
210 210
211 // Add an origin bound cert for |origin| with specific creation and expiry 211 // Add a server bound cert for |server| with specific creation and expiry
212 // times. The cert and key data will be filled with dummy values. 212 // times. The cert and key data will be filled with dummy values.
213 void AddOriginBoundCertWithTimes(const std::string& origin, 213 void AddServerBoundCertWithTimes(const std::string& server_identifier,
214 base::Time creation_time, 214 base::Time creation_time,
215 base::Time expiration_time) { 215 base::Time expiration_time) {
216 GetCertStore()->SetOriginBoundCert(origin, net::CLIENT_CERT_RSA_SIGN, 216 GetCertStore()->SetServerBoundCert(server_identifier,
217 creation_time, expiration_time, 217 net::CLIENT_CERT_RSA_SIGN, creation_time,
218 "a", "b"); 218 expiration_time, "a", "b");
219 } 219 }
220 220
221 // Add an origin bound cert for |origin|, with the current time as the 221 // Add a server bound cert for |server|, with the current time as the
222 // creation time. The cert and key data will be filled with dummy values. 222 // creation time. The cert and key data will be filled with dummy values.
223 void AddOriginBoundCert(const std::string& origin) { 223 void AddServerBoundCert(const std::string& server_identifier) {
224 base::Time now = base::Time::Now(); 224 base::Time now = base::Time::Now();
225 AddOriginBoundCertWithTimes(origin, 225 AddServerBoundCertWithTimes(server_identifier,
226 now, 226 now,
227 now + base::TimeDelta::FromDays(1)); 227 now + base::TimeDelta::FromDays(1));
228 } 228 }
229 229
230 net::OriginBoundCertStore* GetCertStore() { 230 net::ServerBoundCertStore* GetCertStore() {
231 return ob_cert_service_->GetCertStore(); 231 return server_bound_cert_service_->GetCertStore();
232 } 232 }
233 233
234 private: 234 private:
235 net::OriginBoundCertService* ob_cert_service_; 235 net::ServerBoundCertService* server_bound_cert_service_;
236 236
237 net::SSLClientCertType type_; 237 net::SSLClientCertType type_;
238 std::string key_; 238 std::string key_;
239 std::string cert_; 239 std::string cert_;
240 240
241 DISALLOW_COPY_AND_ASSIGN(RemoveOriginBoundCertTester); 241 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester);
242 }; 242 };
243 243
244 class RemoveHistoryTester : public BrowsingDataRemoverTester { 244 class RemoveHistoryTester : public BrowsingDataRemoverTester {
245 public: 245 public:
246 explicit RemoveHistoryTester(TestingProfile* profile) 246 explicit RemoveHistoryTester(TestingProfile* profile)
247 : query_url_success_(false) { 247 : query_url_success_(false) {
248 profile->CreateHistoryService(true, false); 248 profile->CreateHistoryService(true, false);
249 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 249 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
250 } 250 }
251 251
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 504 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
505 BrowsingDataRemover::REMOVE_COOKIES, tester.get()); 505 BrowsingDataRemover::REMOVE_COOKIES, tester.get());
506 506
507 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 507 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
508 // Removing with time period other than EVERYTHING should not clear safe 508 // Removing with time period other than EVERYTHING should not clear safe
509 // browsing cookies. 509 // browsing cookies.
510 EXPECT_TRUE(tester->ContainsCookie()); 510 EXPECT_TRUE(tester->ContainsCookie());
511 } 511 }
512 #endif 512 #endif
513 513
514 TEST_F(BrowsingDataRemoverTest, RemoveOriginBoundCertForever) { 514 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) {
515 scoped_ptr<RemoveOriginBoundCertTester> tester( 515 scoped_ptr<RemoveServerBoundCertTester> tester(
516 new RemoveOriginBoundCertTester(GetProfile())); 516 new RemoveServerBoundCertTester(GetProfile()));
517 517
518 tester->AddOriginBoundCert(kTestkOrigin1); 518 tester->AddServerBoundCert(kTestkOrigin1);
519 EXPECT_EQ(1, tester->OriginBoundCertCount()); 519 EXPECT_EQ(1, tester->ServerBoundCertCount());
520 520
521 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 521 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
522 BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, tester.get()); 522 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get());
523 523
524 EXPECT_EQ(BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, GetRemovalMask()); 524 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
525 EXPECT_EQ(0, tester->OriginBoundCertCount()); 525 EXPECT_EQ(0, tester->ServerBoundCertCount());
526 } 526 }
527 527
528 TEST_F(BrowsingDataRemoverTest, RemoveOriginBoundCertLastHour) { 528 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) {
529 scoped_ptr<RemoveOriginBoundCertTester> tester( 529 scoped_ptr<RemoveServerBoundCertTester> tester(
530 new RemoveOriginBoundCertTester(GetProfile())); 530 new RemoveServerBoundCertTester(GetProfile()));
531 531
532 base::Time now = base::Time::Now(); 532 base::Time now = base::Time::Now();
533 tester->AddOriginBoundCert(kTestkOrigin1); 533 tester->AddServerBoundCert(kTestkOrigin1);
534 tester->AddOriginBoundCertWithTimes(kTestkOrigin2, 534 tester->AddServerBoundCertWithTimes(kTestkOrigin2,
535 now - base::TimeDelta::FromHours(2), 535 now - base::TimeDelta::FromHours(2),
536 now); 536 now);
537 EXPECT_EQ(2, tester->OriginBoundCertCount()); 537 EXPECT_EQ(2, tester->ServerBoundCertCount());
538 538
539 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 539 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
540 BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, tester.get()); 540 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get());
541 541
542 EXPECT_EQ(BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, GetRemovalMask()); 542 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
543 EXPECT_EQ(1, tester->OriginBoundCertCount()); 543 EXPECT_EQ(1, tester->ServerBoundCertCount());
544 std::vector<net::OriginBoundCertStore::OriginBoundCert> certs; 544 std::vector<net::ServerBoundCertStore::ServerBoundCert> certs;
545 tester->GetCertStore()->GetAllOriginBoundCerts(&certs); 545 tester->GetCertStore()->GetAllServerBoundCerts(&certs);
546 EXPECT_EQ(kTestkOrigin2, certs[0].origin()); 546 EXPECT_EQ(kTestkOrigin2, certs[0].server_identifier());
547 } 547 }
548 548
549 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { 549 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
550 scoped_ptr<RemoveHistoryTester> tester( 550 scoped_ptr<RemoveHistoryTester> tester(
551 new RemoveHistoryTester(GetProfile())); 551 new RemoveHistoryTester(GetProfile()));
552 552
553 tester->AddHistory(kOrigin1, base::Time::Now()); 553 tester->AddHistory(kOrigin1, base::Time::Now());
554 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); 554 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
555 555
556 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 556 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); 880 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
881 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); 881 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
882 882
883 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, 883 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
884 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); 884 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get());
885 885
886 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 886 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
887 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); 887 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1));
888 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); 888 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
889 } 889 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | chrome/browser/extensions/api/browsing_data/browsing_data_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698