summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/cros/onc_network_parser_unittest.cc17
-rw-r--r--crypto/nss_util.cc23
-rw-r--r--crypto/nss_util.h13
-rw-r--r--net/base/cert_database_nss_unittest.cc21
4 files changed, 31 insertions, 43 deletions
diff --git a/chrome/browser/chromeos/cros/onc_network_parser_unittest.cc b/chrome/browser/chromeos/cros/onc_network_parser_unittest.cc
index bc77fd3..2c637f1 100644
--- a/chrome/browser/chromeos/cros/onc_network_parser_unittest.cc
+++ b/chrome/browser/chromeos/cros/onc_network_parser_unittest.cc
@@ -12,7 +12,6 @@
#include "base/json/json_value_serializer.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
-#include "base/scoped_temp_dir.h"
#include "base/threading/thread_restrictions.h"
#include "base/stringprintf.h"
#include "base/values.h"
@@ -56,18 +55,15 @@ net::CertType GetCertType(const net::X509Certificate* cert) {
class OncNetworkParserTest : public testing::Test {
public:
static void SetUpTestCase() {
- ASSERT_TRUE(temp_db_dir_.Get().CreateUniqueTempDir());
// Ideally, we'd open a test DB for each test case, and close it
// again, removing the temp dir, but unfortunately, there's a
// bug in NSS that prevents this from working, so we just open
// it once, and empty it for each test case. Here's the bug:
// https://bugzilla.mozilla.org/show_bug.cgi?id=588269
- ASSERT_TRUE(
- crypto::OpenTestNSSDB(temp_db_dir_.Get().path(), g_token_name));
- }
-
- static void TearDownTestCase() {
- ASSERT_TRUE(temp_db_dir_.Get().Delete());
+ ASSERT_TRUE(crypto::OpenTestNSSDB());
+ // There is no matching TearDownTestCase call to close the test NSS DB
+ // because that would leave NSS in a potentially broken state for further
+ // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269
}
virtual void SetUp() {
@@ -141,7 +137,6 @@ class OncNetworkParserTest : public testing::Test {
return ok;
}
- static base::LazyInstance<ScopedTempDir> temp_db_dir_;
ScopedStubCrosEnabler stub_cros_enabler_;
};
@@ -207,10 +202,6 @@ void OncNetworkParserTest::TestProxySettings(const std::string test_blob,
net_config));
}
-// static
-base::LazyInstance<ScopedTempDir> OncNetworkParserTest::temp_db_dir_ =
- LAZY_INSTANCE_INITIALIZER;
-
TEST_F(OncNetworkParserTest, TestCreateNetworkWifi) {
std::string test_blob;
GetTestData("network-wifi.onc", &test_blob);
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index c60b7ea..4a48db1 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -30,6 +30,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/native_library.h"
+#include "base/scoped_temp_dir.h"
#include "base/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
@@ -220,6 +221,11 @@ class NSPRInitSingleton {
base::LazyInstance<NSPRInitSingleton>::Leaky
g_nspr_singleton = LAZY_INSTANCE_INITIALIZER;
+// This is a LazyInstance so that it will be deleted automatically when the
+// unittest exits. NSSInitSingleton is a LeakySingleton, so it would not be
+// deleted if it were a regular member.
+base::LazyInstance<ScopedTempDir> g_test_nss_db_dir = LAZY_INSTANCE_INITIALIZER;
+
class NSSInitSingleton {
public:
#if defined(OS_CHROMEOS)
@@ -343,8 +349,12 @@ class NSSInitSingleton {
#endif // defined(OS_CHROMEOS)
- bool OpenTestNSSDB(const FilePath& path, const char* description) {
- test_slot_ = OpenUserDB(path, description);
+ bool OpenTestNSSDB() {
+ if (test_slot_)
+ return true;
+ if (!g_test_nss_db_dir.Get().CreateUniqueTempDir())
+ return false;
+ test_slot_ = OpenUserDB(g_test_nss_db_dir.Get().path(), "Test DB");
return !!test_slot_;
}
@@ -355,6 +365,7 @@ class NSSInitSingleton {
PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
PK11_FreeSlot(test_slot_);
test_slot_ = NULL;
+ ignore_result(g_test_nss_db_dir.Get().Delete());
}
}
@@ -698,12 +709,8 @@ bool CheckNSSVersion(const char* version) {
}
#if defined(USE_NSS)
-bool OpenTestNSSDB(const FilePath& path, const char* description) {
- return g_nss_singleton.Get().OpenTestNSSDB(path, description);
-}
-
-void CloseTestNSSDB() {
- g_nss_singleton.Get().CloseTestNSSDB();
+bool OpenTestNSSDB() {
+ return g_nss_singleton.Get().OpenTestNSSDB();
}
base::Lock* GetNSSWriteLock() {
diff --git a/crypto/nss_util.h b/crypto/nss_util.h
index 746691d..9cfdf0b 100644
--- a/crypto/nss_util.h
+++ b/crypto/nss_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -154,11 +154,12 @@ CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime);
CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time);
#if defined(USE_NSS)
-// Exposed for unittests only. |path| should be an existing directory under
-// which the DB files will be placed. |description| is a user-visible name for
-// the DB, as a utf8 string, which will be truncated at 32 bytes.
-CRYPTO_EXPORT bool OpenTestNSSDB(const FilePath& path, const char* description);
-CRYPTO_EXPORT void CloseTestNSSDB();
+// Exposed for unittests only.
+// TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is
+// fixed, switch back to using a separate userdb for each test. (Maybe refactor
+// to provide a ScopedTestNSSDB instead of open/close methods.)
+CRYPTO_EXPORT bool OpenTestNSSDB();
+// NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB.
// NSS has a bug which can cause a deadlock or stall in some cases when writing
// to the certDB and keyDB. It also has a bug which causes concurrent key pair
diff --git a/net/base/cert_database_nss_unittest.cc b/net/base/cert_database_nss_unittest.cc
index d5a4092..4d94946 100644
--- a/net/base/cert_database_nss_unittest.cc
+++ b/net/base/cert_database_nss_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,6 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
-#include "base/scoped_temp_dir.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -39,14 +38,10 @@ namespace net {
class CertDatabaseNSSTest : public testing::Test {
public:
static void SetUpTestCase() {
- ASSERT_TRUE(temp_db_dir_.Get().CreateUniqueTempDir());
- ASSERT_TRUE(
- crypto::OpenTestNSSDB(temp_db_dir_.Get().path(),
- "CertDatabaseNSSTest db"));
- }
-
- static void TearDownTestCase() {
- ASSERT_TRUE(temp_db_dir_.Get().Delete());
+ ASSERT_TRUE(crypto::OpenTestNSSDB());
+ // There is no matching TearDownTestCase call to close the test NSS DB
+ // because that would leave NSS in a potentially broken state for further
+ // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269
}
virtual void SetUp() {
@@ -129,14 +124,8 @@ class CertDatabaseNSSTest : public testing::Test {
}
return ok;
}
-
- static base::LazyInstance<ScopedTempDir> temp_db_dir_;
};
-// static
-base::LazyInstance<ScopedTempDir> CertDatabaseNSSTest::temp_db_dir_ =
- LAZY_INSTANCE_INITIALIZER;
-
TEST_F(CertDatabaseNSSTest, ListCerts) {
// This test isn't terribly useful, though it will at least let valgrind test
// for leaks.