| 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..361307be04b080fe7018b1f204a0ef7132720991 100644
|
| --- a/net/base/keygen_handler_unittest.cc
|
| +++ b/net/base/keygen_handler_unittest.cc
|
| @@ -8,17 +8,21 @@
|
|
|
| #include "base/base64.h"
|
| #include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/threading/worker_pool.h"
|
| #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_util.h"
|
| +#include "crypto/nss_util_internal.h"
|
| #endif
|
|
|
| namespace net {
|
| @@ -30,8 +34,16 @@ class KeygenHandlerTest : public ::testing::Test {
|
| KeygenHandlerTest() {}
|
| virtual ~KeygenHandlerTest() {}
|
|
|
| - private:
|
| -#if defined(OS_CHROMEOS) && defined(USE_NSS)
|
| + protected:
|
| + void SetUpKeyHandler(KeygenHandler* handler) {
|
| +#if defined(USE_NSS)
|
| + crypto::ScopedPK11Slot slot(crypto::GetPersistentNSSKeySlot());
|
| + handler->set_key_slot(
|
| + crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot.get())));
|
| +#endif
|
| + }
|
| +
|
| +#if defined(USE_NSS)
|
| crypto::ScopedTestNSSDB test_nss_db_;
|
| #endif
|
| };
|
| @@ -74,6 +86,7 @@ void AssertValidSignedPublicKeyAndChallenge(const std::string& result,
|
|
|
| TEST_F(KeygenHandlerTest, SmokeTest) {
|
| KeygenHandler handler(768, "some challenge", GURL("http://www.example.com"));
|
| + SetUpKeyHandler(&handler);
|
| handler.set_stores_key(false); // Don't leave the key-pair behind
|
| std::string result = handler.GenKeyAndSignChallenge();
|
| VLOG(1) << "KeygenHandler produced: " << result;
|
| @@ -81,14 +94,13 @@ TEST_F(KeygenHandlerTest, SmokeTest) {
|
| }
|
|
|
| void ConcurrencyTestCallback(base::WaitableEvent* event,
|
| - const std::string& challenge,
|
| + 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.
|
| @@ -106,15 +118,19 @@ void ConcurrencyTestCallback(base::WaitableEvent* event,
|
| // test tries to catch concurrency problems in the keygen implementation.
|
| TEST_F(KeygenHandlerTest, ConcurrencyTest) {
|
| const int NUM_HANDLERS = 5;
|
| - base::WaitableEvent* events[NUM_HANDLERS] = { NULL };
|
| + base::WaitableEvent* events[NUM_HANDLERS] = {NULL};
|
| std::string results[NUM_HANDLERS];
|
| for (int i = 0; i < NUM_HANDLERS; i++) {
|
| + scoped_ptr<KeygenHandler> handler(new KeygenHandler(
|
| + 768, "some challenge", GURL("http://www.example.com")));
|
| + SetUpKeyHandler(handler.get());
|
| 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,
|
| + events[i],
|
| + base::Passed(&handler),
|
| + &results[i]),
|
| + true);
|
| }
|
|
|
| for (int i = 0; i < NUM_HANDLERS; i++) {
|
|
|