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

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

Issue 2281783002: Changes client_token to be client_auth_token. (Closed)
Patch Set: Linting. Created 4 years, 3 months 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
« no previous file with comments | « blimp/net/engine_authentication_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <memory> 6 #include <memory>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 14 matching lines...) Expand all
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 using testing::_; 28 using testing::_;
29 using testing::Eq; 29 using testing::Eq;
30 using testing::Return; 30 using testing::Return;
31 using testing::SaveArg; 31 using testing::SaveArg;
32 32
33 namespace blimp { 33 namespace blimp {
34 namespace { 34 namespace {
35 const char client_token[] = "valid token"; 35 const char client_auth_token[] = "valid token";
36 } // namespace 36 } // namespace
37 37
38 class EngineAuthenticationHandlerTest : public testing::Test { 38 class EngineAuthenticationHandlerTest : public testing::Test {
39 public: 39 public:
40 EngineAuthenticationHandlerTest() 40 EngineAuthenticationHandlerTest()
41 : runner_(new base::TestMockTimeTaskRunner), 41 : runner_(new base::TestMockTimeTaskRunner),
42 runner_handle_(runner_), 42 runner_handle_(runner_),
43 auth_handler_(new EngineAuthenticationHandler(&connection_handler_, 43 auth_handler_(new EngineAuthenticationHandler(&connection_handler_,
44 client_token)), 44 client_auth_token)),
45 connection_(new testing::StrictMock<MockBlimpConnection>()) {} 45 connection_(new testing::StrictMock<MockBlimpConnection>()) {}
46 46
47 ~EngineAuthenticationHandlerTest() override {} 47 ~EngineAuthenticationHandlerTest() override {}
48 48
49 protected: 49 protected:
50 void ExpectOnConnection() { 50 void ExpectOnConnection() {
51 EXPECT_CALL(*connection_, AddConnectionErrorObserver(_)) 51 EXPECT_CALL(*connection_, AddConnectionErrorObserver(_))
52 .WillOnce(SaveArg<0>(&error_observer_)); 52 .WillOnce(SaveArg<0>(&error_observer_));
53 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_)) 53 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_))
54 .WillOnce(SaveArg<0>(&incoming_message_processor_)); 54 .WillOnce(SaveArg<0>(&incoming_message_processor_));
(...skipping 10 matching lines...) Expand all
65 65
66 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) { 66 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) {
67 ExpectOnConnection(); 67 ExpectOnConnection();
68 EXPECT_CALL(*connection_, RemoveConnectionErrorObserver(_)); 68 EXPECT_CALL(*connection_, RemoveConnectionErrorObserver(_));
69 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get()))); 69 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get())));
70 auth_handler_->HandleConnection(std::move(connection_)); 70 auth_handler_->HandleConnection(std::move(connection_));
71 EXPECT_NE(nullptr, error_observer_); 71 EXPECT_NE(nullptr, error_observer_);
72 EXPECT_NE(nullptr, incoming_message_processor_); 72 EXPECT_NE(nullptr, incoming_message_processor_);
73 73
74 std::unique_ptr<BlimpMessage> blimp_message = 74 std::unique_ptr<BlimpMessage> blimp_message =
75 CreateStartConnectionMessage(client_token, kProtocolVersion); 75 CreateStartConnectionMessage(client_auth_token, kProtocolVersion);
76 net::TestCompletionCallback process_message_cb; 76 net::TestCompletionCallback process_message_cb;
77 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 77 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
78 process_message_cb.callback()); 78 process_message_cb.callback());
79 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 79 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
80 } 80 }
81 81
82 TEST_F(EngineAuthenticationHandlerTest, ProtocolMismatch) { 82 TEST_F(EngineAuthenticationHandlerTest, ProtocolMismatch) {
83 const int kInvalidProtocolVersion = -1; 83 const int kInvalidProtocolVersion = -1;
84 84
85 BlimpMessage end_connection_message; 85 BlimpMessage end_connection_message;
86 MockBlimpMessageProcessor message_processor; 86 MockBlimpMessageProcessor message_processor;
87 EXPECT_CALL(message_processor, MockableProcessMessage(_, _)) 87 EXPECT_CALL(message_processor, MockableProcessMessage(_, _))
88 .WillOnce(SaveArg<0>(&end_connection_message)); 88 .WillOnce(SaveArg<0>(&end_connection_message));
89 EXPECT_CALL(*connection_, GetOutgoingMessageProcessor()) 89 EXPECT_CALL(*connection_, GetOutgoingMessageProcessor())
90 .WillOnce(Return(&message_processor)); 90 .WillOnce(Return(&message_processor));
91 91
92 ExpectOnConnection(); 92 ExpectOnConnection();
93 auth_handler_->HandleConnection(std::move(connection_)); 93 auth_handler_->HandleConnection(std::move(connection_));
94 94
95 std::unique_ptr<BlimpMessage> blimp_message = 95 std::unique_ptr<BlimpMessage> blimp_message =
96 CreateStartConnectionMessage(client_token, kInvalidProtocolVersion); 96 CreateStartConnectionMessage(client_auth_token, kInvalidProtocolVersion);
97 net::TestCompletionCallback process_message_cb; 97 net::TestCompletionCallback process_message_cb;
98 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 98 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
99 process_message_cb.callback()); 99 process_message_cb.callback());
100 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 100 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
101 101
102 EXPECT_EQ(BlimpMessage::kProtocolControl, 102 EXPECT_EQ(BlimpMessage::kProtocolControl,
103 end_connection_message.feature_case()); 103 end_connection_message.feature_case());
104 EXPECT_EQ( 104 EXPECT_EQ(
105 ProtocolControlMessage::kEndConnection, 105 ProtocolControlMessage::kEndConnection,
106 end_connection_message.protocol_control().connection_message_case()); 106 end_connection_message.protocol_control().connection_message_case());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11)); 151 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11));
152 } 152 }
153 153
154 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) { 154 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) {
155 ExpectOnConnection(); 155 ExpectOnConnection();
156 auth_handler_->HandleConnection(std::move(connection_)); 156 auth_handler_->HandleConnection(std::move(connection_));
157 auth_handler_.reset(); 157 auth_handler_.reset();
158 158
159 std::unique_ptr<BlimpMessage> blimp_message = 159 std::unique_ptr<BlimpMessage> blimp_message =
160 CreateStartConnectionMessage(client_token, kProtocolVersion); 160 CreateStartConnectionMessage(client_auth_token, kProtocolVersion);
161 net::TestCompletionCallback process_message_cb; 161 net::TestCompletionCallback process_message_cb;
162 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 162 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
163 process_message_cb.callback()); 163 process_message_cb.callback());
164 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 164 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
165 } 165 }
166 166
167 } // namespace blimp 167 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/engine_authentication_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698