Index: net/base/keygen_handler_unittest.cc |
diff --git a/net/base/keygen_handler_unittest.cc b/net/base/keygen_handler_unittest.cc |
index a868b2925c8745ee9362f8cf1a6dee84df208028..2cb64743c8b4a7b5f74ce4e5b39e959c4c21ea7c 100644 |
--- a/net/base/keygen_handler_unittest.cc |
+++ b/net/base/keygen_handler_unittest.cc |
@@ -14,24 +14,59 @@ |
#include "base/threading/thread_restrictions.h" |
#include "base/synchronization/waitable_event.h" |
#include "build/build_config.h" |
-#include "crypto/nss_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#if defined(USE_NSS) |
#include <private/pprthred.h> // PR_DetachThread |
+#include "crypto/nss_crypto_module_delegate.h" |
+#include "crypto/nss_util.h" |
+#include "crypto/nss_util_internal.h" |
#endif |
namespace net { |
namespace { |
+#if defined(USE_NSS) |
+class StubCryptoModuleDelegate : public crypto::NSSCryptoModuleDelegate { |
+ public: |
+ explicit StubCryptoModuleDelegate(crypto::ScopedPK11Slot slot) |
+ : slot_(slot.Pass()) {} |
+ |
+ virtual std::string RequestPassword(const std::string& slot_name, |
+ bool retry, |
+ bool* cancelled) OVERRIDE{ |
+ return std::string(); |
+ } |
+ |
+ virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE { |
+ return crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot_.get())); |
+ } |
+ |
+ private: |
+ crypto::ScopedPK11Slot slot_; |
+}; |
+#endif |
+ |
class KeygenHandlerTest : public ::testing::Test { |
public: |
KeygenHandlerTest() {} |
virtual ~KeygenHandlerTest() {} |
+ scoped_ptr<KeygenHandler> CreateKeygenHandler() { |
+ scoped_ptr<KeygenHandler> handler(new KeygenHandler( |
+ 768, "some challenge", GURL("http://www.example.com"))); |
+#if defined(USE_NSS) |
+ handler->set_crypto_module_delegate( |
+ scoped_ptr<crypto::NSSCryptoModuleDelegate>( |
+ new StubCryptoModuleDelegate( |
+ crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot())))); |
+#endif |
+ return handler.Pass(); |
+ } |
+ |
private: |
-#if defined(OS_CHROMEOS) && defined(USE_NSS) |
+#if defined(USE_NSS) |
crypto::ScopedTestNSSDB test_nss_db_; |
#endif |
}; |
@@ -73,22 +108,22 @@ void AssertValidSignedPublicKeyAndChallenge(const std::string& result, |
} |
TEST_F(KeygenHandlerTest, SmokeTest) { |
- KeygenHandler handler(768, "some challenge", GURL("http://www.example.com")); |
- handler.set_stores_key(false); // Don't leave the key-pair behind |
- std::string result = handler.GenKeyAndSignChallenge(); |
+ scoped_ptr<KeygenHandler> handler(CreateKeygenHandler()); |
+ handler->set_stores_key(false); // Don't leave the key-pair behind |
+ std::string result = handler->GenKeyAndSignChallenge(); |
VLOG(1) << "KeygenHandler produced: " << result; |
AssertValidSignedPublicKeyAndChallenge(result, "some challenge"); |
} |
-void ConcurrencyTestCallback(base::WaitableEvent* event, |
- const std::string& challenge, |
+void ConcurrencyTestCallback(const std::string& challenge, |
+ base::WaitableEvent* event, |
+ scoped_ptr<KeygenHandler> handler, |
std::string* result) { |
// We allow Singleton use on the worker thread here since we use a |
// WaitableEvent to synchronize, so it's safe. |
base::ThreadRestrictions::ScopedAllowSingleton scoped_allow_singleton; |
- KeygenHandler handler(768, challenge, GURL("http://www.example.com")); |
- handler.set_stores_key(false); // Don't leave the key-pair behind. |
- *result = handler.GenKeyAndSignChallenge(); |
+ handler->set_stores_key(false); // Don't leave the key-pair behind. |
+ *result = handler->GenKeyAndSignChallenge(); |
event->Signal(); |
#if defined(USE_NSS) |
// Detach the thread from NSPR. |
@@ -109,12 +144,15 @@ TEST_F(KeygenHandlerTest, ConcurrencyTest) { |
base::WaitableEvent* events[NUM_HANDLERS] = { NULL }; |
std::string results[NUM_HANDLERS]; |
for (int i = 0; i < NUM_HANDLERS; i++) { |
+ scoped_ptr<KeygenHandler> handler(CreateKeygenHandler()); |
events[i] = new base::WaitableEvent(false, false); |
- base::WorkerPool::PostTask( |
- FROM_HERE, |
- base::Bind(ConcurrencyTestCallback, events[i], "some challenge", |
- &results[i]), |
- true); |
+ base::WorkerPool::PostTask(FROM_HERE, |
+ base::Bind(ConcurrencyTestCallback, |
+ "some challenge", |
+ events[i], |
+ base::Passed(&handler), |
+ &results[i]), |
+ true); |
} |
for (int i = 0; i < NUM_HANDLERS; i++) { |