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

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 wez's comments 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/memory/ref_counted.h"
9 #include "base/test/test_mock_time_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "blimp/common/create_blimp_message.h"
12 #include "blimp/common/proto/blimp_message.pb.h"
13 #include "blimp/net/blimp_connection.h"
14 #include "blimp/net/blimp_transport.h"
15 #include "blimp/net/common.h"
16 #include "blimp/net/connection_error_observer.h"
17 #include "blimp/net/engine_authentication_handler.h"
18 #include "blimp/net/test_common.h"
19 #include "net/base/completion_callback.h"
20 #include "net/base/net_errors.h"
21 #include "net/base/test_completion_callback.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 using testing::_;
26 using testing::Eq;
27 using testing::SaveArg;
28
29 namespace blimp {
30
31 class EngineAuthenticationHandlerTest : public testing::Test {
32 public:
33 EngineAuthenticationHandlerTest()
34 : runner_(new base::TestMockTimeTaskRunner),
35 runner_handle_(runner_),
36 auth_handler_(new EngineAuthenticationHandler(&connection_handler_)),
37 connection_(new testing::StrictMock<MockBlimpConnection>()) {}
38
39 ~EngineAuthenticationHandlerTest() override {}
40
41 protected:
42 void ExpectOnConnection() {
43 EXPECT_CALL(*connection_, SetConnectionErrorObserver(_))
44 .Times(2)
45 .WillRepeatedly(SaveArg<0>(&error_observer_));
46 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_))
47 .Times(2)
48 .WillRepeatedly(SaveArg<0>(&incoming_message_processor_));
49 }
50
51 scoped_refptr<base::TestMockTimeTaskRunner> runner_;
52 base::ThreadTaskRunnerHandle runner_handle_;
53 testing::StrictMock<MockConnectionHandler> connection_handler_;
54 scoped_ptr<EngineAuthenticationHandler> auth_handler_;
55 scoped_ptr<testing::StrictMock<MockBlimpConnection>> connection_;
56 ConnectionErrorObserver* error_observer_ = nullptr;
57 BlimpMessageProcessor* incoming_message_processor_ = nullptr;
58 };
59
60 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) {
61 ExpectOnConnection();
62 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get())));
63 auth_handler_->HandleConnection(std::move(connection_));
64 EXPECT_NE(nullptr, error_observer_);
65 EXPECT_NE(nullptr, incoming_message_processor_);
66
67 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0);
68 net::TestCompletionCallback process_message_cb;
69 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
70 process_message_cb.callback());
71 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
72 EXPECT_EQ(nullptr, error_observer_);
73 EXPECT_EQ(nullptr, incoming_message_processor_);
74 }
75
76 TEST_F(EngineAuthenticationHandlerTest, WrongMessageReceived) {
77 ExpectOnConnection();
78 auth_handler_->HandleConnection(std::move(connection_));
79
80 InputMessage* input_message;
81 scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&input_message);
82 net::TestCompletionCallback process_message_cb;
83 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
84 process_message_cb.callback());
85 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
86 EXPECT_EQ(nullptr, error_observer_);
87 EXPECT_EQ(nullptr, incoming_message_processor_);
88 }
89
90 TEST_F(EngineAuthenticationHandlerTest, ConnectionError) {
91 ExpectOnConnection();
92 auth_handler_->HandleConnection(std::move(connection_));
93 EXPECT_NE(nullptr, error_observer_);
94 EXPECT_NE(nullptr, incoming_message_processor_);
95 error_observer_->OnConnectionError(net::ERR_FAILED);
96 EXPECT_EQ(nullptr, error_observer_);
97 EXPECT_EQ(nullptr, incoming_message_processor_);
98 }
99
100 TEST_F(EngineAuthenticationHandlerTest, TimeOut) {
Wez 2015/12/08 22:59:59 nit: Timeout or TimesOut
haibinlu 2015/12/09 00:02:33 Done.
101 ExpectOnConnection();
102 auth_handler_->HandleConnection(std::move(connection_));
103 EXPECT_NE(nullptr, error_observer_);
104 EXPECT_NE(nullptr, incoming_message_processor_);
105
106 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11));
107 EXPECT_EQ(nullptr, error_observer_);
108 EXPECT_EQ(nullptr, incoming_message_processor_);
109 }
110
111 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeleteFirst) {
Wez 2015/12/08 22:59:59 nit: Delete -> Deleted
haibinlu 2015/12/09 00:02:33 Done.
112 ExpectOnConnection();
113 auth_handler_->HandleConnection(std::move(connection_));
114 auth_handler_.reset();
115
116 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0);
117 net::TestCompletionCallback process_message_cb;
118 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
119 process_message_cb.callback());
120 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
121 }
122
123 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698