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

Side by Side Diff: chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « chrome/browser/net/sqlite_server_bound_cert_store.cc ('k') | chrome/browser/page_info_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 base::Time::FromInternalValue(4), 92 base::Time::FromInternalValue(4),
93 "c", "d")); 93 "c", "d"));
94 94
95 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 95 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
96 // Replace the store effectively destroying the current one and forcing it 96 // Replace the store effectively destroying the current one and forcing it
97 // to write its data to disk. Then we can see if after loading it again it 97 // to write its data to disk. Then we can see if after loading it again it
98 // is still there. 98 // is still there.
99 store_ = NULL; 99 store_ = NULL;
100 scoped_refptr<base::ThreadTestHelper> helper( 100 scoped_refptr<base::ThreadTestHelper> helper(
101 new base::ThreadTestHelper( 101 new base::ThreadTestHelper(
102 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 102 BrowserThread::GetMessageLoopProxyForThread(
103 BrowserThread::DB).get()));
103 // Make sure we wait until the destructor has run. 104 // Make sure we wait until the destructor has run.
104 ASSERT_TRUE(helper->Run()); 105 ASSERT_TRUE(helper->Run());
105 store_ = new SQLiteServerBoundCertStore( 106 store_ = new SQLiteServerBoundCertStore(
106 temp_dir_.path().Append(chrome::kOBCertFilename), NULL); 107 temp_dir_.path().Append(chrome::kOBCertFilename), NULL);
107 108
108 // Reload and test for persistence 109 // Reload and test for persistence
109 ASSERT_TRUE(store_->Load(&certs.get())); 110 ASSERT_TRUE(store_->Load(&certs.get()));
110 ASSERT_EQ(2U, certs.size()); 111 ASSERT_EQ(2U, certs.size());
111 net::DefaultServerBoundCertStore::ServerBoundCert* ec_cert; 112 net::DefaultServerBoundCertStore::ServerBoundCert* ec_cert;
112 net::DefaultServerBoundCertStore::ServerBoundCert* rsa_cert; 113 net::DefaultServerBoundCertStore::ServerBoundCert* rsa_cert;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[1]->type()); 207 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[1]->type());
207 // Undecodable cert, expiration time will be uninitialized. 208 // Undecodable cert, expiration time will be uninitialized.
208 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); 209 ASSERT_EQ(base::Time(), certs[1]->expiration_time());
209 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); 210 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str());
210 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); 211 ASSERT_STREQ("\xbb", certs[1]->cert().c_str());
211 212
212 store_ = NULL; 213 store_ = NULL;
213 // Make sure we wait until the destructor has run. 214 // Make sure we wait until the destructor has run.
214 scoped_refptr<base::ThreadTestHelper> helper( 215 scoped_refptr<base::ThreadTestHelper> helper(
215 new base::ThreadTestHelper( 216 new base::ThreadTestHelper(
216 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 217 BrowserThread::GetMessageLoopProxyForThread(
218 BrowserThread::DB).get()));
217 ASSERT_TRUE(helper->Run()); 219 ASSERT_TRUE(helper->Run());
218 220
219 // Verify the database version is updated. 221 // Verify the database version is updated.
220 { 222 {
221 sql::Connection db; 223 sql::Connection db;
222 ASSERT_TRUE(db.Open(v1_db_path)); 224 ASSERT_TRUE(db.Open(v1_db_path));
223 sql::Statement smt(db.GetUniqueStatement( 225 sql::Statement smt(db.GetUniqueStatement(
224 "SELECT value FROM meta WHERE key = \"version\"")); 226 "SELECT value FROM meta WHERE key = \"version\""));
225 ASSERT_TRUE(smt.Step()); 227 ASSERT_TRUE(smt.Step());
226 EXPECT_EQ(4, smt.ColumnInt(0)); 228 EXPECT_EQ(4, smt.ColumnInt(0));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type()); 296 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type());
295 // Undecodable cert, expiration time will be uninitialized. 297 // Undecodable cert, expiration time will be uninitialized.
296 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); 298 ASSERT_EQ(base::Time(), certs[1]->expiration_time());
297 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); 299 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str());
298 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); 300 ASSERT_STREQ("\xbb", certs[1]->cert().c_str());
299 301
300 store_ = NULL; 302 store_ = NULL;
301 // Make sure we wait until the destructor has run. 303 // Make sure we wait until the destructor has run.
302 scoped_refptr<base::ThreadTestHelper> helper( 304 scoped_refptr<base::ThreadTestHelper> helper(
303 new base::ThreadTestHelper( 305 new base::ThreadTestHelper(
304 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 306 BrowserThread::GetMessageLoopProxyForThread(
307 BrowserThread::DB).get()));
305 ASSERT_TRUE(helper->Run()); 308 ASSERT_TRUE(helper->Run());
306 309
307 // Verify the database version is updated. 310 // Verify the database version is updated.
308 { 311 {
309 sql::Connection db; 312 sql::Connection db;
310 ASSERT_TRUE(db.Open(v2_db_path)); 313 ASSERT_TRUE(db.Open(v2_db_path));
311 sql::Statement smt(db.GetUniqueStatement( 314 sql::Statement smt(db.GetUniqueStatement(
312 "SELECT value FROM meta WHERE key = \"version\"")); 315 "SELECT value FROM meta WHERE key = \"version\""));
313 ASSERT_TRUE(smt.Step()); 316 ASSERT_TRUE(smt.Step());
314 EXPECT_EQ(4, smt.ColumnInt(0)); 317 EXPECT_EQ(4, smt.ColumnInt(0));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ASSERT_EQ(2000, certs[1]->expiration_time().ToInternalValue()); 389 ASSERT_EQ(2000, certs[1]->expiration_time().ToInternalValue());
387 // Undecodable cert, creation time will be uninitialized. 390 // Undecodable cert, creation time will be uninitialized.
388 ASSERT_EQ(base::Time(), certs[1]->creation_time()); 391 ASSERT_EQ(base::Time(), certs[1]->creation_time());
389 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); 392 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str());
390 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); 393 ASSERT_STREQ("\xbb", certs[1]->cert().c_str());
391 394
392 store_ = NULL; 395 store_ = NULL;
393 // Make sure we wait until the destructor has run. 396 // Make sure we wait until the destructor has run.
394 scoped_refptr<base::ThreadTestHelper> helper( 397 scoped_refptr<base::ThreadTestHelper> helper(
395 new base::ThreadTestHelper( 398 new base::ThreadTestHelper(
396 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 399 BrowserThread::GetMessageLoopProxyForThread(
400 BrowserThread::DB).get()));
397 ASSERT_TRUE(helper->Run()); 401 ASSERT_TRUE(helper->Run());
398 402
399 // Verify the database version is updated. 403 // Verify the database version is updated.
400 { 404 {
401 sql::Connection db; 405 sql::Connection db;
402 ASSERT_TRUE(db.Open(v3_db_path)); 406 ASSERT_TRUE(db.Open(v3_db_path));
403 sql::Statement smt(db.GetUniqueStatement( 407 sql::Statement smt(db.GetUniqueStatement(
404 "SELECT value FROM meta WHERE key = \"version\"")); 408 "SELECT value FROM meta WHERE key = \"version\""));
405 ASSERT_TRUE(smt.Step()); 409 ASSERT_TRUE(smt.Step());
406 EXPECT_EQ(4, smt.ColumnInt(0)); 410 EXPECT_EQ(4, smt.ColumnInt(0));
(...skipping 23 matching lines...) Expand all
430 base::Time(), 434 base::Time(),
431 base::Time(), 435 base::Time(),
432 private_key, 436 private_key,
433 cert)); 437 cert));
434 } 438 }
435 439
436 // Call Flush() and wait until the DB thread is idle. 440 // Call Flush() and wait until the DB thread is idle.
437 store_->Flush(base::Closure()); 441 store_->Flush(base::Closure());
438 scoped_refptr<base::ThreadTestHelper> helper( 442 scoped_refptr<base::ThreadTestHelper> helper(
439 new base::ThreadTestHelper( 443 new base::ThreadTestHelper(
440 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 444 BrowserThread::GetMessageLoopProxyForThread(
445 BrowserThread::DB).get()));
441 ASSERT_TRUE(helper->Run()); 446 ASSERT_TRUE(helper->Run());
442 447
443 // We forced a write, so now the file will be bigger. 448 // We forced a write, so now the file will be bigger.
444 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); 449 ASSERT_TRUE(file_util::GetFileInfo(path, &info));
445 ASSERT_GT(info.size, base_size); 450 ASSERT_GT(info.size, base_size);
446 } 451 }
447 452
448 // Counts the number of times Callback() has been run. 453 // Counts the number of times Callback() has been run.
449 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { 454 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> {
450 public: 455 public:
(...skipping 18 matching lines...) Expand all
469 TEST_F(SQLiteServerBoundCertStoreTest, TestFlushCompletionCallback) { 474 TEST_F(SQLiteServerBoundCertStoreTest, TestFlushCompletionCallback) {
470 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); 475 scoped_refptr<CallbackCounter> counter(new CallbackCounter());
471 476
472 // Callback shouldn't be invoked until we call Flush(). 477 // Callback shouldn't be invoked until we call Flush().
473 ASSERT_EQ(0, counter->callback_count()); 478 ASSERT_EQ(0, counter->callback_count());
474 479
475 store_->Flush(base::Bind(&CallbackCounter::Callback, counter.get())); 480 store_->Flush(base::Bind(&CallbackCounter::Callback, counter.get()));
476 481
477 scoped_refptr<base::ThreadTestHelper> helper( 482 scoped_refptr<base::ThreadTestHelper> helper(
478 new base::ThreadTestHelper( 483 new base::ThreadTestHelper(
479 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 484 BrowserThread::GetMessageLoopProxyForThread(
485 BrowserThread::DB).get()));
480 ASSERT_TRUE(helper->Run()); 486 ASSERT_TRUE(helper->Run());
481 487
482 ASSERT_EQ(1, counter->callback_count()); 488 ASSERT_EQ(1, counter->callback_count());
483 } 489 }
OLDNEW
« no previous file with comments | « chrome/browser/net/sqlite_server_bound_cert_store.cc ('k') | chrome/browser/page_info_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698