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

Side by Side Diff: net/base/cert_database_nss_unittest.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <cert.h> 5 #include <cert.h>
6 #include <pk11pub.h> 6 #include <pk11pub.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/crypto/scoped_nss_types.h" 10 #include "base/crypto/scoped_nss_types.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 } // namespace 98 } // namespace
99 99
100 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is 100 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is
101 // fixed, switch back to using a separate userdb for each test. 101 // fixed, switch back to using a separate userdb for each test.
102 // (When doing so, remember to add some standalone tests of DeleteCert since it 102 // (When doing so, remember to add some standalone tests of DeleteCert since it
103 // won't be tested by TearDown anymore.) 103 // won't be tested by TearDown anymore.)
104 class CertDatabaseNSSTest : public testing::Test { 104 class CertDatabaseNSSTest : public testing::Test {
105 public: 105 public:
106 virtual void SetUp() { 106 virtual void SetUp() {
107 if (!temp_db_initialized_) { 107 ASSERT_TRUE(temp_db_dir_.CreateUniqueTempDir());
108 ScopedTempDir* temp_db_dir = Singleton< 108 ASSERT_TRUE(
109 ScopedTempDir, 109 base::OpenTestNSSDB(temp_db_dir_.path(), "CertDatabaseNSSTest db"));
110 DefaultSingletonTraits<ScopedTempDir>,
111 CertDatabaseNSSTest>::get();
112 ASSERT_TRUE(temp_db_dir->CreateUniqueTempDir());
113 ASSERT_TRUE(
114 base::OpenTestNSSDB(temp_db_dir->path(), "CertDatabaseNSSTest db"));
115 temp_db_initialized_ = true;
116 }
117 slot_.reset(base::GetDefaultNSSKeySlot()); 110 slot_.reset(base::GetDefaultNSSKeySlot());
118 111
119 // Test db should be empty at start of test. 112 // Test db should be empty at start of test.
120 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); 113 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size());
121 } 114 }
122 virtual void TearDown() { 115 virtual void TearDown() {
123 // Don't try to cleanup if the setup failed. 116 // Don't try to cleanup if the setup failed.
124 ASSERT_TRUE(temp_db_initialized_);
125 ASSERT_TRUE(slot_.get()); 117 ASSERT_TRUE(slot_.get());
126 118
127 EXPECT_TRUE(CleanupSlotContents(slot_.get())); 119 EXPECT_TRUE(CleanupSlotContents(slot_.get()));
128 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); 120 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size());
129 } 121 }
130 122
131 protected: 123 protected:
132 base::ScopedPK11Slot slot_; 124 base::ScopedPK11Slot slot_;
133 CertDatabase cert_db_; 125 CertDatabase cert_db_;
134 126
135 private: 127 private:
136 static bool temp_db_initialized_; 128 ScopedTempDir temp_db_dir_;
137 }; 129 };
138 130
139 // static
140 bool CertDatabaseNSSTest::temp_db_initialized_ = false;
141
142 TEST_F(CertDatabaseNSSTest, ListCerts) { 131 TEST_F(CertDatabaseNSSTest, ListCerts) {
143 // This test isn't terribly useful, though it will at least let valgrind test 132 // This test isn't terribly useful, though it will at least let valgrind test
144 // for leaks. 133 // for leaks.
145 CertificateList certs; 134 CertificateList certs;
146 cert_db_.ListCerts(&certs); 135 cert_db_.ListCerts(&certs);
147 // The test DB is empty, but let's assume there will always be something in 136 // The test DB is empty, but let's assume there will always be something in
148 // the other slots. 137 // the other slots.
149 EXPECT_LT(0U, certs.size()); 138 EXPECT_LT(0U, certs.size());
150 } 139 }
151 140
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 puny_cert.get(), CA_CERT, 482 puny_cert.get(), CA_CERT,
494 CertDatabase::TRUSTED_SSL | CertDatabase::TRUSTED_EMAIL)); 483 CertDatabase::TRUSTED_SSL | CertDatabase::TRUSTED_EMAIL));
495 484
496 verify_result.Reset(); 485 verify_result.Reset();
497 error = puny_cert->Verify("xn--wgv71a119e.com", flags, &verify_result); 486 error = puny_cert->Verify("xn--wgv71a119e.com", flags, &verify_result);
498 EXPECT_EQ(OK, error); 487 EXPECT_EQ(OK, error);
499 EXPECT_EQ(0, verify_result.cert_status); 488 EXPECT_EQ(0, verify_result.cert_status);
500 } 489 }
501 490
502 } // namespace net 491 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698