Chromium Code Reviews| Index: blimp/net/engine_authentication_handler_unittest.cc |
| diff --git a/blimp/net/engine_authentication_handler_unittest.cc b/blimp/net/engine_authentication_handler_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64af8b5a3efc5795c8594bf330d3c89dce9bd630 |
| --- /dev/null |
| +++ b/blimp/net/engine_authentication_handler_unittest.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stddef.h> |
| +#include <string> |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "blimp/common/create_blimp_message.h" |
| +#include "blimp/common/proto/blimp_message.pb.h" |
| +#include "blimp/net/blimp_connection.h" |
| +#include "blimp/net/blimp_transport.h" |
| +#include "blimp/net/common.h" |
| +#include "blimp/net/connection_error_observer.h" |
| +#include "blimp/net/engine_authentication_handler.h" |
| +#include "blimp/net/test_common.h" |
| +#include "net/base/completion_callback.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/base/test_completion_callback.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using testing::_; |
| +using testing::Eq; |
| +using testing::SaveArg; |
| + |
| +namespace blimp { |
| + |
| +class EngineAuthenticationHandlerTest : public testing::Test { |
| + public: |
| + EngineAuthenticationHandlerTest() |
| + : auth_handler_(new EngineAuthenticationHandler(&connection_handler_)), |
| + connection_(new testing::StrictMock<MockBlimpConnection>()) {} |
| + |
| + ~EngineAuthenticationHandlerTest() override {} |
| + |
| + protected: |
| + void ExpectOnConnection() { |
| + EXPECT_CALL(*connection_, SetConnectionErrorObserver(_)) |
| + .Times(2) |
| + .WillRepeatedly(SaveArg<0>(&error_observer_)); |
| + EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_)) |
| + .Times(2) |
| + .WillRepeatedly(SaveArg<0>(&incoming_message_processor_)); |
| + } |
| + |
| + base::MessageLoop message_loop_; |
| + testing::StrictMock<MockConnectionHandler> connection_handler_; |
| + scoped_ptr<EngineAuthenticationHandler> auth_handler_; |
| + scoped_ptr<testing::StrictMock<MockBlimpConnection>> connection_; |
| + ConnectionErrorObserver* error_observer_ = nullptr; |
| + BlimpMessageProcessor* incoming_message_processor_ = nullptr; |
| +}; |
| + |
| +TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) { |
| + ExpectOnConnection(); |
| + EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get()))); |
| + auth_handler_->HandleConnection(std::move(connection_)); |
| + EXPECT_NE(nullptr, error_observer_); |
| + EXPECT_NE(nullptr, incoming_message_processor_); |
| + |
| + StartConnectionMessage* start_connection; |
| + scoped_ptr<BlimpMessage> blimp_message = |
| + CreateBlimpMessage(&start_connection); |
| + start_connection->set_client_token(""); |
| + start_connection->set_protocol_version(0); |
| + net::TestCompletionCallback process_message_cb; |
| + incoming_message_processor_->ProcessMessage(std::move(blimp_message), |
| + process_message_cb.callback()); |
| + EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); |
| + EXPECT_EQ(nullptr, error_observer_); |
| + EXPECT_EQ(nullptr, incoming_message_processor_); |
| +} |
| + |
| +TEST_F(EngineAuthenticationHandlerTest, AuthenticationFails) { |
|
Wez
2015/12/08 00:31:41
Add tests that simulate a timeout, and that simula
haibinlu
2015/12/08 01:54:50
Done.
|
| + ExpectOnConnection(); |
| + auth_handler_->HandleConnection(std::move(connection_)); |
| + |
| + InputMessage* input_message; |
| + scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&input_message); |
| + net::TestCompletionCallback process_message_cb; |
| + incoming_message_processor_->ProcessMessage(std::move(blimp_message), |
| + process_message_cb.callback()); |
| + EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); |
| + EXPECT_EQ(nullptr, error_observer_); |
| + EXPECT_EQ(nullptr, incoming_message_processor_); |
| +} |
| + |
| +} // namespace blimp |