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

Unified Diff: chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc

Issue 11742037: Make ServerBoundCertStore interface async, move SQLiteServerBoundCertStore load onto DB thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
diff --git a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc b/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
index 6c62fe7695c98f17c190aaea9128f96a20012252..f2eef51151f99c654fc457c82d97e873407ffd15 100644
--- a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
+++ b/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
@@ -8,6 +8,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/message_loop.h"
+#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/test/thread_test_helper.h"
#include "chrome/browser/net/clear_on_exit_policy.h"
@@ -24,8 +25,25 @@ using content::BrowserThread;
class SQLiteServerBoundCertStoreTest : public testing::Test {
public:
- SQLiteServerBoundCertStoreTest()
- : db_thread_(BrowserThread::DB) {
+ SQLiteServerBoundCertStoreTest() : db_thread_(BrowserThread::DB) {}
+
+ void Load(
+ ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>* certs) {
+ base::RunLoop run_loop;
+ store_->Load(base::Bind(&SQLiteServerBoundCertStoreTest::OnLoaded,
+ base::Unretained(this),
+ &run_loop));
+ run_loop.Run();
+ certs->swap(certs_);
+ certs_.clear();
+ }
+
+ void OnLoaded(
+ base::RunLoop* run_loop,
+ scoped_ptr<ScopedVector<
+ net::DefaultServerBoundCertStore::ServerBoundCert> > certs) {
+ certs_.swap(*certs);
+ run_loop->Quit();
}
protected:
@@ -66,7 +84,7 @@ class SQLiteServerBoundCertStoreTest : public testing::Test {
store_ = new SQLiteServerBoundCertStore(
temp_dir_.path().Append(chrome::kOBCertFilename), NULL);
ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(0u, certs.size());
// Make sure the store gets written at least once.
store_->AddServerBoundCert(
@@ -78,9 +96,11 @@ class SQLiteServerBoundCertStoreTest : public testing::Test {
"a", "b"));
}
+ MessageLoopForIO message_loop_;
content::TestBrowserThread db_thread_;
base::ScopedTempDir temp_dir_;
scoped_refptr<SQLiteServerBoundCertStore> store_;
+ ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs_;
};
// Test if data is stored as expected in the SQLite database.
@@ -107,7 +127,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
temp_dir_.path().Append(chrome::kOBCertFilename), NULL);
// Reload and test for persistence
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(2U, certs.size());
net::DefaultServerBoundCertStore::ServerBoundCert* ec_cert;
net::DefaultServerBoundCertStore::ServerBoundCert* rsa_cert;
@@ -142,7 +162,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
temp_dir_.path().Append(chrome::kOBCertFilename), NULL);
// Reload and check if the cert has been removed.
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(0U, certs.size());
}
@@ -193,7 +213,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) {
store_ = new SQLiteServerBoundCertStore(v1_db_path, NULL);
// Load the database and ensure the certs can be read and are marked as RSA.
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(2U, certs.size());
ASSERT_STREQ("google.com", certs[0]->server_identifier().c_str());
@@ -281,7 +301,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) {
store_ = new SQLiteServerBoundCertStore(v2_db_path, NULL);
// Load the database and ensure the certs can be read and are marked as RSA.
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(2U, certs.size());
ASSERT_STREQ("google.com", certs[0]->server_identifier().c_str());
@@ -371,7 +391,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) {
store_ = new SQLiteServerBoundCertStore(v3_db_path, NULL);
// Load the database and ensure the certs can be read and are marked as RSA.
- ASSERT_TRUE(store_->Load(&certs.get()));
+ Load(&certs);
ASSERT_EQ(2U, certs.size());
ASSERT_STREQ("google.com", certs[0]->server_identifier().c_str());

Powered by Google App Engine
This is Rietveld 408576698