diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 02:17:05 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 02:17:05 +0000 |
commit | 88e241257ce551af29d26c087d5093e48eac294d (patch) | |
tree | d62788b452b85d4e56c8bdfdaf3d214e3b9a0cb4 /remoting/protocol/authenticator_test_base.cc | |
parent | e057e5a18da8c79c8ed3b202fc83c6a43968f38d (diff) | |
download | chromium_src-88e241257ce551af29d26c087d5093e48eac294d.zip chromium_src-88e241257ce551af29d26c087d5093e48eac294d.tar.gz chromium_src-88e241257ce551af29d26c087d5093e48eac294d.tar.bz2 |
Move the core state machine of SSLClientSocketNSS into a thread-safe Core
NSS SSL functions may block on the underlying PKCS#11 modules or on
user input. On ChromeOS, which has a hardware TPM, calls may take upwards
of several seconds, preventing any IPC due to the I/O thread being
blocked.
To avoid blocking the I/O thread on ChromeOS, move the core SSL
implementation to a dedicated worker thread, so that only SSL sockets
are blocked.
BUG=122355
TEST=existing net_unittests + see bug.
Review URL: https://chromiumcodereview.appspot.com/10454066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140697 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/authenticator_test_base.cc')
-rw-r--r-- | remoting/protocol/authenticator_test_base.cc | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/remoting/protocol/authenticator_test_base.cc b/remoting/protocol/authenticator_test_base.cc index edff6d3..5ffe559 100644 --- a/remoting/protocol/authenticator_test_base.cc +++ b/remoting/protocol/authenticator_test_base.cc @@ -7,6 +7,8 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" +#include "base/test/test_timeouts.h" +#include "base/timer.h" #include "crypto/rsa_private_key.h" #include "net/base/cert_test_util.h" #include "remoting/protocol/authenticator.h" @@ -21,16 +23,25 @@ using testing::SaveArg; namespace remoting { namespace protocol { -AuthenticatorTestBase::MockChannelDoneCallback::MockChannelDoneCallback() { -} -AuthenticatorTestBase::MockChannelDoneCallback::~MockChannelDoneCallback() { -} +namespace { -AuthenticatorTestBase::AuthenticatorTestBase() { -} -AuthenticatorTestBase::~AuthenticatorTestBase() { +ACTION_P(QuitThreadOnCounter, counter) { + --(*counter); + EXPECT_GE(*counter, 0); + if (*counter == 0) + MessageLoop::current()->Quit(); } +} // namespace + +AuthenticatorTestBase::MockChannelDoneCallback::MockChannelDoneCallback() {} + +AuthenticatorTestBase::MockChannelDoneCallback::~MockChannelDoneCallback() {} + +AuthenticatorTestBase::AuthenticatorTestBase() {} + +AuthenticatorTestBase::~AuthenticatorTestBase() {} + void AuthenticatorTestBase::SetUp() { FilePath certs_dir(net::GetTestCertsDirectory()); @@ -99,22 +110,40 @@ void AuthenticatorTestBase::RunChannelAuth(bool expected_fail) { net::StreamSocket* client_socket = NULL; net::StreamSocket* host_socket = NULL; + // Expect two callbacks to be called - the client callback and the host + // callback. + int callback_counter = 2; + EXPECT_CALL(client_callback_, OnDone(net::OK, _)) - .WillOnce(SaveArg<1>(&client_socket)); + .WillOnce(DoAll(SaveArg<1>(&client_socket), + QuitThreadOnCounter(&callback_counter))); if (expected_fail) { - EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL)); + EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL)) + .WillOnce(QuitThreadOnCounter(&callback_counter)); } else { EXPECT_CALL(host_callback_, OnDone(net::OK, _)) - .WillOnce(SaveArg<1>(&host_socket)); + .WillOnce(DoAll(SaveArg<1>(&host_socket), + QuitThreadOnCounter(&callback_counter))); } - message_loop_.RunAllPending(); + // Ensure that .Run() does not run unbounded if the callbacks are never + // called. + base::Timer shutdown_timer(false, false); + shutdown_timer.Start(FROM_HERE, TestTimeouts::action_timeout(), + MessageLoop::QuitClosure()); + message_loop_.Run(); + shutdown_timer.Stop(); testing::Mock::VerifyAndClearExpectations(&client_callback_); testing::Mock::VerifyAndClearExpectations(&host_callback_); client_socket_.reset(client_socket); host_socket_.reset(host_socket); + + if (!expected_fail) { + ASSERT_TRUE(client_socket_.get() != NULL); + ASSERT_TRUE(host_socket_.get() != NULL); + } } void AuthenticatorTestBase::OnHostConnected( |