| Index: remoting/host/gnubby_auth_handler_posix_unittest.cc
|
| diff --git a/remoting/host/gnubby_auth_handler_posix_unittest.cc b/remoting/host/gnubby_auth_handler_posix_unittest.cc
|
| index c3a8c9ff5d29deb5eb2f7705a1812456e2ee4939..2f8c2f38533b390e1baf62a9b19419a22bf603d1 100644
|
| --- a/remoting/host/gnubby_auth_handler_posix_unittest.cc
|
| +++ b/remoting/host/gnubby_auth_handler_posix_unittest.cc
|
| @@ -2,9 +2,12 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/message_loop/message_loop.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "base/timer/mock_timer.h"
|
| #include "net/socket/stream_listen_socket.h"
|
| #include "remoting/host/gnubby_auth_handler_posix.h"
|
| +#include "remoting/host/gnubby_socket.h"
|
| #include "remoting/protocol/protocol_mock_objects.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -66,6 +69,8 @@ class GnubbyAuthHandlerPosixTest : public testing::Test {
|
| // Mock client stub.
|
| MockClientStub client_stub_;
|
|
|
| + base::MessageLoop message_loop_;
|
| +
|
| private:
|
| void OnConnect(int result);
|
| };
|
| @@ -78,12 +83,12 @@ void GnubbyAuthHandlerPosixTest::SetUp() {
|
|
|
| MATCHER_P2(EqualsDataMessage, id, data, "") {
|
| std::string connection_id = base::StringPrintf("\"connectionId\":%d", id);
|
| - std::string json_message = base::StringPrintf("\"jsonMessage\":\"%s\"", data);
|
| + std::string data_message = base::StringPrintf("\"base64Data\":\"%s\"", data);
|
|
|
| return (arg.type() == "gnubby-auth" &&
|
| arg.data().find("\"type\":\"data\"") != std::string::npos &&
|
| arg.data().find(connection_id) != std::string::npos &&
|
| - arg.data().find(json_message) != std::string::npos);
|
| + arg.data().find(data_message) != std::string::npos);
|
| }
|
|
|
| TEST_F(GnubbyAuthHandlerPosixTest, HostDataMessageDelivered) {
|
| @@ -109,7 +114,8 @@ TEST_F(GnubbyAuthHandlerPosixTest, DidRead) {
|
| net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
|
|
|
| delegate_->DidAccept(NULL, make_scoped_ptr(socket));
|
| - delegate_->DidRead(socket, reinterpret_cast<const char*>(request_data),
|
| + delegate_->DidRead(socket,
|
| + reinterpret_cast<const char*>(request_data),
|
| sizeof(request_data));
|
| }
|
|
|
| @@ -120,9 +126,38 @@ TEST_F(GnubbyAuthHandlerPosixTest, DidReadByteByByte) {
|
|
|
| delegate_->DidAccept(NULL, make_scoped_ptr(socket));
|
| for (unsigned int i = 0; i < sizeof(request_data); ++i) {
|
| - delegate_->DidRead(socket,
|
| - reinterpret_cast<const char *>(request_data + i), 1);
|
| + delegate_->DidRead(
|
| + socket, reinterpret_cast<const char*>(request_data + i), 1);
|
| }
|
| }
|
|
|
| +TEST_F(GnubbyAuthHandlerPosixTest, DidReadTimeout) {
|
| + net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
|
| +
|
| + delegate_->DidAccept(NULL, make_scoped_ptr(socket));
|
| + ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
|
| +
|
| + base::MockTimer* mock_timer = new base::MockTimer(false, false);
|
| + auth_handler_posix_->GetGnubbySocketForTesting(socket)
|
| + ->SetTimerForTesting(mock_timer);
|
| + delegate_->DidRead(socket, reinterpret_cast<const char*>(request_data), 1);
|
| + mock_timer->Fire();
|
| +
|
| + ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
|
| +}
|
| +
|
| +TEST_F(GnubbyAuthHandlerPosixTest, ClientErrorMessageDelivered) {
|
| + net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
|
| +
|
| + delegate_->DidAccept(NULL, make_scoped_ptr(socket));
|
| +
|
| + std::string error_json = base::StringPrintf(
|
| + "{\"type\":\"error\",\"connectionId\":%d}",
|
| + auth_handler_posix_->GetConnectionIdForTesting(socket));
|
| +
|
| + ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
|
| + auth_handler_->DeliverClientMessage(error_json);
|
| + ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
|
| +}
|
| +
|
| } // namespace remoting
|
|
|