summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
Diffstat (limited to 'remoting')
-rw-r--r--remoting/protocol/authenticator_test_base.cc51
-rw-r--r--remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc44
-rw-r--r--remoting/protocol/v2_authenticator_unittest.cc3
3 files changed, 72 insertions, 26 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(
diff --git a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
index 49e4c1e..5ad8b4f 100644
--- a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
+++ b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
@@ -8,6 +8,8 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
+#include "base/test/test_timeouts.h"
+#include "base/timer.h"
#include "base/path_service.h"
#include "crypto/rsa_private_key.h"
#include "net/base/cert_test_util.h"
@@ -35,14 +37,19 @@ class MockChannelDoneCallback {
MOCK_METHOD2(OnDone, void(net::Error error, net::StreamSocket* socket));
};
+ACTION_P(QuitThreadOnCounter, counter) {
+ --(*counter);
+ EXPECT_GE(*counter, 0);
+ if (*counter == 0)
+ MessageLoop::current()->Quit();
+}
+
} // namespace
class SslHmacChannelAuthenticatorTest : public testing::Test {
public:
- SslHmacChannelAuthenticatorTest() {
- }
- virtual ~SslHmacChannelAuthenticatorTest() {
- }
+ SslHmacChannelAuthenticatorTest() {}
+ virtual ~SslHmacChannelAuthenticatorTest() {}
protected:
virtual void SetUp() OVERRIDE {
@@ -77,15 +84,28 @@ class SslHmacChannelAuthenticatorTest : public testing::Test {
base::Bind(&SslHmacChannelAuthenticatorTest::OnHostConnected,
base::Unretained(this)));
+ // Expect two callbacks to be called - the client callback and the host
+ // callback.
+ int callback_counter = 2;
+
if (expected_fail) {
- EXPECT_CALL(client_callback_, OnDone(net::ERR_FAILED, NULL));
- EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL));
+ EXPECT_CALL(client_callback_, OnDone(net::ERR_FAILED, NULL))
+ .WillOnce(QuitThreadOnCounter(&callback_counter));
+ EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL))
+ .WillOnce(QuitThreadOnCounter(&callback_counter));
} else {
- EXPECT_CALL(client_callback_, OnDone(net::OK, NotNull()));
- EXPECT_CALL(host_callback_, OnDone(net::OK, NotNull()));
+ EXPECT_CALL(client_callback_, OnDone(net::OK, NotNull()))
+ .WillOnce(QuitThreadOnCounter(&callback_counter));
+ EXPECT_CALL(host_callback_, OnDone(net::OK, NotNull()))
+ .WillOnce(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();
}
void OnHostConnected(net::Error error,
@@ -125,8 +145,8 @@ TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) {
RunChannelAuth(false);
- EXPECT_TRUE(client_socket_.get() != NULL);
- EXPECT_TRUE(host_socket_.get() != NULL);
+ ASSERT_TRUE(client_socket_.get() != NULL);
+ ASSERT_TRUE(host_socket_.get() != NULL);
StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
100, 2);
@@ -145,7 +165,7 @@ TEST_F(SslHmacChannelAuthenticatorTest, InvalidChannelSecret) {
RunChannelAuth(true);
- EXPECT_TRUE(host_socket_.get() == NULL);
+ ASSERT_TRUE(host_socket_.get() == NULL);
}
} // namespace protocol
diff --git a/remoting/protocol/v2_authenticator_unittest.cc b/remoting/protocol/v2_authenticator_unittest.cc
index 0d634e4..dc95318 100644
--- a/remoting/protocol/v2_authenticator_unittest.cc
+++ b/remoting/protocol/v2_authenticator_unittest.cc
@@ -61,9 +61,6 @@ TEST_F(V2AuthenticatorTest, SuccessfulAuth) {
host_auth_ = host_->CreateChannelAuthenticator();
RunChannelAuth(false);
- EXPECT_TRUE(client_socket_.get() != NULL);
- EXPECT_TRUE(host_socket_.get() != NULL);
-
StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
kMessageSize, kMessages);