Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: blimp/net/engine_authentication_handler_unittest.cc

Issue 1492643003: [Blimp Net] Add EngineAuthHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses comments and adds unit tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6 #include <string>
7
8 #include "base/message_loop/message_loop.h"
9 #include "blimp/common/create_blimp_message.h"
10 #include "blimp/common/proto/blimp_message.pb.h"
11 #include "blimp/net/blimp_connection.h"
12 #include "blimp/net/blimp_transport.h"
13 #include "blimp/net/common.h"
14 #include "blimp/net/connection_error_observer.h"
15 #include "blimp/net/engine_authentication_handler.h"
16 #include "blimp/net/test_common.h"
17 #include "net/base/completion_callback.h"
18 #include "net/base/net_errors.h"
19 #include "net/base/test_completion_callback.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 using testing::_;
24 using testing::Eq;
25 using testing::SaveArg;
26
27 namespace blimp {
28
29 class EngineAuthenticationHandlerTest : public testing::Test {
30 public:
31 EngineAuthenticationHandlerTest()
32 : auth_handler_(new EngineAuthenticationHandler(&connection_handler_)),
33 connection_(new testing::StrictMock<MockBlimpConnection>()) {}
34
35 ~EngineAuthenticationHandlerTest() override {}
36
37 protected:
38 void ExpectOnConnection() {
39 EXPECT_CALL(*connection_, SetConnectionErrorObserver(_))
40 .Times(2)
41 .WillRepeatedly(SaveArg<0>(&error_observer_));
42 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_))
43 .Times(2)
44 .WillRepeatedly(SaveArg<0>(&incoming_message_processor_));
45 }
46
47 base::MessageLoop message_loop_;
48 testing::StrictMock<MockConnectionHandler> connection_handler_;
49 scoped_ptr<EngineAuthenticationHandler> auth_handler_;
50 scoped_ptr<testing::StrictMock<MockBlimpConnection>> connection_;
51 ConnectionErrorObserver* error_observer_ = nullptr;
52 BlimpMessageProcessor* incoming_message_processor_ = nullptr;
53 };
54
55 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) {
56 ExpectOnConnection();
57 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get())));
58 auth_handler_->HandleConnection(std::move(connection_));
59 EXPECT_NE(nullptr, error_observer_);
60 EXPECT_NE(nullptr, incoming_message_processor_);
61
62 StartConnectionMessage* start_connection;
63 scoped_ptr<BlimpMessage> blimp_message =
64 CreateBlimpMessage(&start_connection);
65 start_connection->set_client_token("");
66 start_connection->set_protocol_version(0);
67 net::TestCompletionCallback process_message_cb;
68 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
69 process_message_cb.callback());
70 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
71 EXPECT_EQ(nullptr, error_observer_);
72 EXPECT_EQ(nullptr, incoming_message_processor_);
73 }
74
75 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.
76 ExpectOnConnection();
77 auth_handler_->HandleConnection(std::move(connection_));
78
79 InputMessage* input_message;
80 scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&input_message);
81 net::TestCompletionCallback process_message_cb;
82 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
83 process_message_cb.callback());
84 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
85 EXPECT_EQ(nullptr, error_observer_);
86 EXPECT_EQ(nullptr, incoming_message_processor_);
87 }
88
89 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698