summaryrefslogtreecommitdiffstats
path: root/crypto/scoped_test_system_nss_key_slot.cc
diff options
context:
space:
mode:
authorpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-28 09:56:51 +0000
committerpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-28 09:56:51 +0000
commit190933f29103844bbc40a88bca8b14e49bf7e008 (patch)
tree8a14ff4d9011f73175a12f851d5fb039c45bd41c /crypto/scoped_test_system_nss_key_slot.cc
parenta017c66088a4671cf0ea59be150c73d3679f31d4 (diff)
downloadchromium_src-190933f29103844bbc40a88bca8b14e49bf7e008.zip
chromium_src-190933f29103844bbc40a88bca8b14e49bf7e008.tar.gz
chromium_src-190933f29103844bbc40a88bca8b14e49bf7e008.tar.bz2
Extract ScopedTestNSSDB from nss_util.
Before ScopedTestNSSDB affected several slot getters from nss_util.h . This change reduces ScopedTestNSSDB to solely setup a temporary test DB and not influencing the global state in nss_util anymore. As a replacement for some of its old behavior, a new ScopedTestSystemNSSKeySlot is added, which allows to override the slot returned by GetSystemNSSKeySlot(). With this change it's now possible to write tests that need both a user and system NSS DB by using ScopedTestSystemNSSKeySlot. As a side-effect, GetPersistentNSSKeySlot() is now compiled on !OS_CHROMEOS only. BUG=210525 (For include changes:) R=rsleevi@chromium.org TBR=nkostylev@chromium.org, stevenjb@chromium.org Review URL: https://codereview.chromium.org/401623006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/scoped_test_system_nss_key_slot.cc')
-rw-r--r--crypto/scoped_test_system_nss_key_slot.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/crypto/scoped_test_system_nss_key_slot.cc b/crypto/scoped_test_system_nss_key_slot.cc
new file mode 100644
index 0000000..ee5e1df
--- /dev/null
+++ b/crypto/scoped_test_system_nss_key_slot.cc
@@ -0,0 +1,28 @@
+// Copyright 2014 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.
+
+#include "crypto/scoped_test_system_nss_key_slot.h"
+
+#include "crypto/nss_util_internal.h"
+#include "crypto/scoped_test_nss_db.h"
+
+namespace crypto {
+
+ScopedTestSystemNSSKeySlot::ScopedTestSystemNSSKeySlot()
+ : test_db_(new ScopedTestNSSDB) {
+ if (!test_db_->is_open())
+ return;
+ SetSystemKeySlotForTesting(
+ ScopedPK11Slot(PK11_ReferenceSlot(test_db_->slot())));
+}
+
+ScopedTestSystemNSSKeySlot::~ScopedTestSystemNSSKeySlot() {
+ SetSystemKeySlotForTesting(ScopedPK11Slot());
+}
+
+bool ScopedTestSystemNSSKeySlot::ConstructedSuccessfully() const {
+ return test_db_->is_open();
+}
+
+} // namespace crypto