OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace remoting { | 22 namespace remoting { |
23 namespace protocol { | 23 namespace protocol { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 using testing::_; | 27 using testing::_; |
28 using testing::Return; | 28 using testing::Return; |
29 | 29 |
30 typedef ValidatingAuthenticator::Result ValidationResult; | 30 typedef ValidatingAuthenticator::Result ValidationResult; |
31 | 31 |
32 const char kRemoteTestJid[] = "ficticious_jid_for_testing"; | 32 constexpr char kRemoteTestJid[] = "ficticious_jid_for_testing"; |
33 | 33 |
34 // testing::InvokeArgument<N> does not work with base::Callback, fortunately | 34 // testing::InvokeArgument<N> does not work with base::Callback, fortunately |
35 // gmock makes it simple to create action templates that do for the various | 35 // gmock makes it simple to create action templates that do for the various |
36 // possible numbers of arguments. | 36 // possible numbers of arguments. |
37 ACTION_TEMPLATE(InvokeCallbackArgument, | 37 ACTION_TEMPLATE(InvokeCallbackArgument, |
38 HAS_1_TEMPLATE_PARAMS(int, k), | 38 HAS_1_TEMPLATE_PARAMS(int, k), |
39 AND_0_VALUE_PARAMS()) { | 39 AND_0_VALUE_PARAMS()) { |
40 ::std::tr1::get<k>(args).Run(); | 40 ::std::tr1::get<k>(args).Run(); |
41 } | 41 } |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class ValidatingAuthenticatorTest : public testing::Test { | 45 class ValidatingAuthenticatorTest : public testing::Test { |
46 public: | 46 public: |
47 ValidatingAuthenticatorTest(); | 47 ValidatingAuthenticatorTest(); |
48 ~ValidatingAuthenticatorTest() override; | 48 ~ValidatingAuthenticatorTest() override; |
49 | 49 |
50 void ValidateCallback( | 50 void ValidateCallback( |
| 51 ValidationResult* validation_result, |
| 52 bool* callback_called, |
51 const std::string& remote_jid, | 53 const std::string& remote_jid, |
52 const ValidatingAuthenticator::ResultCallback& callback); | 54 const ValidatingAuthenticator::ResultCallback& callback); |
53 | 55 |
54 protected: | 56 protected: |
55 // testing::Test overrides. | 57 // testing::Test overrides. |
56 void SetUp() override; | 58 void SetUp() override; |
57 | 59 |
58 // Calls ProcessMessage() on |validating_authenticator_| and blocks until | 60 // Calls ProcessMessage() on |validating_authenticator_| and blocks until |
59 // the result callback is called. | 61 // the result callback is called. |
60 void SendMessageAndWaitForCallback(); | 62 void SendMessageAndWaitForCallback(); |
61 | 63 |
62 // Used to set up our mock behaviors on the MockAuthenticator object passed | 64 // Used to set up our mock behaviors on the MockAuthenticator object passed |
63 // to |validating_authenticator_|. Lifetime of the object is controlled by | 65 // to |validating_authenticator_|. Lifetime of the object is controlled by |
64 // |validating_authenticator_| so this pointer is no longer valid once | 66 // |validating_authenticator_| so this pointer is no longer valid once |
65 // the owner is destroyed. | 67 // the owner is destroyed. |
66 MockAuthenticator* mock_authenticator_ = nullptr; | 68 testing::NiceMock<MockAuthenticator>* mock_authenticator_ = nullptr; |
67 | 69 |
68 // This member is used to drive behavior in |validating_authenticator_| when | 70 // This member is used to drive behavior in |validating_authenticator_| when |
69 // it's validation complete callback is run. | 71 // its incoming validation complete callback is run. |
70 ValidationResult validation_result_ = ValidationResult::SUCCESS; | 72 ValidationResult incoming_validation_result_ = ValidationResult::SUCCESS; |
71 | 73 |
72 // Tracks whether our ValidateCallback has been called or not. | 74 // Tracks whether our 'incoming' callback has been called or not. |
73 bool validate_complete_called_ = false; | 75 bool incoming_complete_called_ = false; |
| 76 |
| 77 // This member is used to drive behavior in |validating_authenticator_| when |
| 78 // its accepted validation complete callback is run. |
| 79 ValidationResult accepted_validation_result_ = ValidationResult::SUCCESS; |
| 80 |
| 81 // Tracks whether our 'accepted' callback has been called or not. |
| 82 bool accepted_complete_called_ = false; |
74 | 83 |
75 // The object under test. | 84 // The object under test. |
76 std::unique_ptr<ValidatingAuthenticator> validating_authenticator_; | 85 std::unique_ptr<ValidatingAuthenticator> validating_authenticator_; |
77 | 86 |
78 private: | 87 private: |
79 base::MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
80 | 89 |
81 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticatorTest); | 90 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticatorTest); |
82 }; | 91 }; |
83 | 92 |
84 ValidatingAuthenticatorTest::ValidatingAuthenticatorTest() {} | 93 ValidatingAuthenticatorTest::ValidatingAuthenticatorTest() {} |
85 | 94 |
86 ValidatingAuthenticatorTest::~ValidatingAuthenticatorTest() {} | 95 ValidatingAuthenticatorTest::~ValidatingAuthenticatorTest() {} |
87 | 96 |
88 void ValidatingAuthenticatorTest::ValidateCallback( | 97 void ValidatingAuthenticatorTest::ValidateCallback( |
| 98 ValidationResult* validation_result, |
| 99 bool* callback_called, |
89 const std::string& remote_jid, | 100 const std::string& remote_jid, |
90 const ValidatingAuthenticator::ResultCallback& callback) { | 101 const ValidatingAuthenticator::ResultCallback& callback) { |
91 validate_complete_called_ = true; | 102 *callback_called = true; |
92 callback.Run(validation_result_); | 103 callback.Run(*validation_result); |
93 } | 104 } |
94 | 105 |
95 void ValidatingAuthenticatorTest::SetUp() { | 106 void ValidatingAuthenticatorTest::SetUp() { |
96 mock_authenticator_ = new MockAuthenticator(); | 107 mock_authenticator_ = new testing::NiceMock<MockAuthenticator>(); |
97 std::unique_ptr<Authenticator> authenticator(mock_authenticator_); | 108 std::unique_ptr<Authenticator> authenticator(mock_authenticator_); |
98 | 109 |
99 validating_authenticator_.reset(new ValidatingAuthenticator( | 110 validating_authenticator_.reset(new ValidatingAuthenticator( |
100 kRemoteTestJid, base::Bind(&ValidatingAuthenticatorTest::ValidateCallback, | 111 kRemoteTestJid, |
101 base::Unretained(this)), | 112 base::Bind(&ValidatingAuthenticatorTest::ValidateCallback, |
| 113 base::Unretained(this), &incoming_validation_result_, |
| 114 &incoming_complete_called_), |
| 115 base::Bind(&ValidatingAuthenticatorTest::ValidateCallback, |
| 116 base::Unretained(this), &accepted_validation_result_, |
| 117 &accepted_complete_called_), |
102 std::move(authenticator))); | 118 std::move(authenticator))); |
103 } | 119 } |
104 | 120 |
105 void ValidatingAuthenticatorTest::SendMessageAndWaitForCallback() { | 121 void ValidatingAuthenticatorTest::SendMessageAndWaitForCallback() { |
106 base::RunLoop run_loop; | 122 base::RunLoop run_loop; |
107 std::unique_ptr<buzz::XmlElement> first_message( | 123 std::unique_ptr<buzz::XmlElement> first_message( |
108 Authenticator::CreateEmptyAuthenticatorMessage()); | 124 Authenticator::CreateEmptyAuthenticatorMessage()); |
109 validating_authenticator_->ProcessMessage(first_message.get(), | 125 validating_authenticator_->ProcessMessage(first_message.get(), |
110 run_loop.QuitClosure()); | 126 run_loop.QuitClosure()); |
111 run_loop.Run(); | 127 run_loop.Run(); |
112 } | 128 } |
113 | 129 |
114 TEST_F(ValidatingAuthenticatorTest, ValidConnection_SingleMessage) { | 130 TEST_F(ValidatingAuthenticatorTest, ValidConnection_SingleMessage) { |
115 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) | 131 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
116 .Times(1) | 132 .Times(1) |
117 .WillOnce(InvokeCallbackArgument<1>()); | 133 .WillOnce(InvokeCallbackArgument<1>()); |
118 | 134 |
119 ON_CALL(*mock_authenticator_, state()) | 135 ON_CALL(*mock_authenticator_, state()) |
120 .WillByDefault(Return(Authenticator::ACCEPTED)); | 136 .WillByDefault(Return(Authenticator::ACCEPTED)); |
121 | 137 |
122 SendMessageAndWaitForCallback(); | 138 SendMessageAndWaitForCallback(); |
123 ASSERT_TRUE(validate_complete_called_); | 139 ASSERT_TRUE(incoming_complete_called_); |
| 140 ASSERT_TRUE(accepted_complete_called_); |
124 ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED); | 141 ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED); |
125 } | 142 } |
126 | 143 |
127 TEST_F(ValidatingAuthenticatorTest, ValidConnection_TwoMessages) { | 144 TEST_F(ValidatingAuthenticatorTest, ValidConnection_TwoMessages) { |
128 // Send the first message to the authenticator, set the mock up to act | 145 // Send the first message to the authenticator, set the mock up to act |
129 // like it is waiting for a second message. | 146 // like it is waiting for a second message. |
130 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) | 147 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
131 .Times(2) | 148 .Times(2) |
132 .WillRepeatedly(InvokeCallbackArgument<1>()); | 149 .WillRepeatedly(InvokeCallbackArgument<1>()); |
133 | 150 |
134 EXPECT_CALL(*mock_authenticator_, state()) | 151 EXPECT_CALL(*mock_authenticator_, state()) |
135 .WillRepeatedly(Return(Authenticator::MESSAGE_READY)); | 152 .WillRepeatedly(Return(Authenticator::MESSAGE_READY)); |
136 | 153 |
137 SendMessageAndWaitForCallback(); | 154 SendMessageAndWaitForCallback(); |
138 ASSERT_TRUE(validate_complete_called_); | 155 ASSERT_TRUE(incoming_complete_called_); |
| 156 ASSERT_FALSE(accepted_complete_called_); |
139 ASSERT_EQ(validating_authenticator_->state(), Authenticator::MESSAGE_READY); | 157 ASSERT_EQ(validating_authenticator_->state(), Authenticator::MESSAGE_READY); |
140 | 158 |
141 // Now 'retrieve' the message for the client which resets the state. | 159 // Now 'retrieve' the message for the client which resets the state. |
142 EXPECT_CALL(*mock_authenticator_, state()) | 160 EXPECT_CALL(*mock_authenticator_, state()) |
143 .WillRepeatedly(Return(Authenticator::WAITING_MESSAGE)); | 161 .WillRepeatedly(Return(Authenticator::WAITING_MESSAGE)); |
144 | 162 |
145 // This dance is needed because GMock doesn't handle unique_ptrs very well. | 163 // This dance is needed because GMock doesn't handle unique_ptrs very well. |
146 // The mock method receives a raw pointer which it wraps and returns when | 164 // The mock method receives a raw pointer which it wraps and returns when |
147 // GetNextMessage() is called. | 165 // GetNextMessage() is called. |
148 std::unique_ptr<buzz::XmlElement> next_message( | 166 std::unique_ptr<buzz::XmlElement> next_message( |
149 Authenticator::CreateEmptyAuthenticatorMessage()); | 167 Authenticator::CreateEmptyAuthenticatorMessage()); |
150 EXPECT_CALL(*mock_authenticator_, GetNextMessagePtr()) | 168 EXPECT_CALL(*mock_authenticator_, GetNextMessagePtr()) |
151 .Times(1) | 169 .Times(1) |
152 .WillOnce(Return(next_message.release())); | 170 .WillOnce(Return(next_message.release())); |
153 | 171 |
154 validating_authenticator_->GetNextMessage(); | 172 validating_authenticator_->GetNextMessage(); |
155 ASSERT_EQ(validating_authenticator_->state(), Authenticator::WAITING_MESSAGE); | 173 ASSERT_EQ(validating_authenticator_->state(), Authenticator::WAITING_MESSAGE); |
156 | 174 |
157 // Now send the second message for processing. | 175 // Now send the second message for processing. |
158 EXPECT_CALL(*mock_authenticator_, state()) | 176 EXPECT_CALL(*mock_authenticator_, state()) |
159 .WillRepeatedly(Return(Authenticator::ACCEPTED)); | 177 .WillRepeatedly(Return(Authenticator::ACCEPTED)); |
160 | 178 |
161 // Reset the callback state, we don't expect the validate function to be | 179 // Reset the callback state, we don't expect the validate function to be |
162 // called for the second message. | 180 // called for the second message, but the accepted callback should. |
163 validate_complete_called_ = false; | 181 incoming_complete_called_ = false; |
164 SendMessageAndWaitForCallback(); | 182 SendMessageAndWaitForCallback(); |
165 ASSERT_FALSE(validate_complete_called_); | 183 ASSERT_FALSE(incoming_complete_called_); |
| 184 ASSERT_TRUE(accepted_complete_called_); |
166 ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED); | 185 ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED); |
167 } | 186 } |
168 | 187 |
169 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_RejectedByUser) { | 188 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_RejectedByUser) { |
170 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); | 189 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); |
171 EXPECT_CALL(*mock_authenticator_, state()).Times(0); | 190 EXPECT_CALL(*mock_authenticator_, state()).Times(0); |
172 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); | 191 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); |
173 | 192 |
174 validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER; | 193 incoming_validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER; |
175 | 194 |
176 SendMessageAndWaitForCallback(); | 195 SendMessageAndWaitForCallback(); |
177 ASSERT_TRUE(validate_complete_called_); | 196 ASSERT_TRUE(incoming_complete_called_); |
| 197 ASSERT_FALSE(accepted_complete_called_); |
178 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 198 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
179 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 199 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
180 Authenticator::REJECTED_BY_USER); | 200 Authenticator::REJECTED_BY_USER); |
181 } | 201 } |
182 | 202 |
183 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidCredentials) { | 203 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidCredentials) { |
184 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); | 204 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); |
185 EXPECT_CALL(*mock_authenticator_, state()).Times(0); | 205 EXPECT_CALL(*mock_authenticator_, state()).Times(0); |
186 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); | 206 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); |
187 | 207 |
188 validation_result_ = ValidationResult::ERROR_INVALID_CREDENTIALS; | 208 incoming_validation_result_ = ValidationResult::ERROR_INVALID_CREDENTIALS; |
189 | 209 |
190 SendMessageAndWaitForCallback(); | 210 SendMessageAndWaitForCallback(); |
191 ASSERT_TRUE(validate_complete_called_); | 211 ASSERT_TRUE(incoming_complete_called_); |
| 212 ASSERT_FALSE(accepted_complete_called_); |
192 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 213 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
193 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 214 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
194 Authenticator::INVALID_CREDENTIALS); | 215 Authenticator::INVALID_CREDENTIALS); |
195 } | 216 } |
196 | 217 |
197 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidAccount) { | 218 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidAccount) { |
198 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); | 219 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); |
199 EXPECT_CALL(*mock_authenticator_, state()).Times(0); | 220 EXPECT_CALL(*mock_authenticator_, state()).Times(0); |
200 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); | 221 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); |
201 | 222 |
202 validation_result_ = ValidationResult::ERROR_INVALID_ACCOUNT; | 223 incoming_validation_result_ = ValidationResult::ERROR_INVALID_ACCOUNT; |
203 | 224 |
204 SendMessageAndWaitForCallback(); | 225 SendMessageAndWaitForCallback(); |
205 ASSERT_TRUE(validate_complete_called_); | 226 ASSERT_TRUE(incoming_complete_called_); |
| 227 ASSERT_FALSE(accepted_complete_called_); |
206 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 228 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
207 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 229 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
208 Authenticator::INVALID_ACCOUNT); | 230 Authenticator::INVALID_ACCOUNT); |
209 } | 231 } |
210 | 232 |
| 233 TEST_F(ValidatingAuthenticatorTest, InvalidConnection_TooManyConnections) { |
| 234 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0); |
| 235 EXPECT_CALL(*mock_authenticator_, state()).Times(0); |
| 236 EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0); |
| 237 |
| 238 incoming_validation_result_ = ValidationResult::ERROR_TOO_MANY_CONNECTIONS; |
| 239 |
| 240 SendMessageAndWaitForCallback(); |
| 241 ASSERT_TRUE(incoming_complete_called_); |
| 242 ASSERT_FALSE(accepted_complete_called_); |
| 243 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
| 244 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
| 245 Authenticator::TOO_MANY_CONNECTIONS); |
| 246 } |
| 247 |
| 248 TEST_F(ValidatingAuthenticatorTest, AcceptedConnection_RejectedByUser) { |
| 249 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
| 250 .Times(1) |
| 251 .WillOnce(InvokeCallbackArgument<1>()); |
| 252 |
| 253 ON_CALL(*mock_authenticator_, state()) |
| 254 .WillByDefault(Return(Authenticator::ACCEPTED)); |
| 255 |
| 256 accepted_validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER; |
| 257 |
| 258 SendMessageAndWaitForCallback(); |
| 259 ASSERT_TRUE(incoming_complete_called_); |
| 260 ASSERT_TRUE(accepted_complete_called_); |
| 261 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
| 262 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
| 263 Authenticator::REJECTED_BY_USER); |
| 264 } |
| 265 |
211 TEST_F(ValidatingAuthenticatorTest, | 266 TEST_F(ValidatingAuthenticatorTest, |
212 WrappedAuthenticatorRejectsConnection_InvalidCredentials) { | 267 WrappedAuthenticatorRejectsConnection_InvalidCredentials) { |
213 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) | 268 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
214 .Times(1) | 269 .Times(1) |
215 .WillOnce(InvokeCallbackArgument<1>()); | 270 .WillOnce(InvokeCallbackArgument<1>()); |
216 | 271 |
217 ON_CALL(*mock_authenticator_, state()) | 272 ON_CALL(*mock_authenticator_, state()) |
218 .WillByDefault(Return(Authenticator::REJECTED)); | 273 .WillByDefault(Return(Authenticator::REJECTED)); |
219 | 274 |
220 ON_CALL(*mock_authenticator_, rejection_reason()) | 275 ON_CALL(*mock_authenticator_, rejection_reason()) |
221 .WillByDefault(Return(Authenticator::REJECTED_BY_USER)); | 276 .WillByDefault(Return(Authenticator::REJECTED_BY_USER)); |
222 | 277 |
223 SendMessageAndWaitForCallback(); | 278 SendMessageAndWaitForCallback(); |
224 ASSERT_TRUE(validate_complete_called_); | 279 ASSERT_TRUE(incoming_complete_called_); |
| 280 ASSERT_FALSE(accepted_complete_called_); |
225 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 281 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
226 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 282 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
227 Authenticator::REJECTED_BY_USER); | 283 Authenticator::REJECTED_BY_USER); |
228 } | 284 } |
229 | 285 |
230 TEST_F(ValidatingAuthenticatorTest, | 286 TEST_F(ValidatingAuthenticatorTest, |
231 WrappedAuthenticatorRejectsConnection_InvalidAccount) { | 287 WrappedAuthenticatorRejectsConnection_InvalidAccount) { |
232 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) | 288 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
233 .Times(1) | 289 .Times(1) |
234 .WillOnce(InvokeCallbackArgument<1>()); | 290 .WillOnce(InvokeCallbackArgument<1>()); |
235 | 291 |
236 ON_CALL(*mock_authenticator_, state()) | 292 ON_CALL(*mock_authenticator_, state()) |
237 .WillByDefault(Return(Authenticator::REJECTED)); | 293 .WillByDefault(Return(Authenticator::REJECTED)); |
238 | 294 |
239 ON_CALL(*mock_authenticator_, rejection_reason()) | 295 ON_CALL(*mock_authenticator_, rejection_reason()) |
240 .WillByDefault(Return(Authenticator::INVALID_CREDENTIALS)); | 296 .WillByDefault(Return(Authenticator::INVALID_CREDENTIALS)); |
241 | 297 |
242 SendMessageAndWaitForCallback(); | 298 SendMessageAndWaitForCallback(); |
243 ASSERT_TRUE(validate_complete_called_); | 299 ASSERT_TRUE(incoming_complete_called_); |
| 300 ASSERT_FALSE(accepted_complete_called_); |
244 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 301 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
245 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 302 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
246 Authenticator::INVALID_CREDENTIALS); | 303 Authenticator::INVALID_CREDENTIALS); |
247 } | 304 } |
248 | 305 |
249 TEST_F(ValidatingAuthenticatorTest, | 306 TEST_F(ValidatingAuthenticatorTest, |
250 WrappedAuthenticatorRejectsConnection_PROTOCOL_ERROR) { | 307 WrappedAuthenticatorRejectsConnection_ProtocolError) { |
251 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) | 308 EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)) |
252 .Times(1) | 309 .Times(1) |
253 .WillOnce(InvokeCallbackArgument<1>()); | 310 .WillOnce(InvokeCallbackArgument<1>()); |
254 | 311 |
255 ON_CALL(*mock_authenticator_, state()) | 312 ON_CALL(*mock_authenticator_, state()) |
256 .WillByDefault(Return(Authenticator::REJECTED)); | 313 .WillByDefault(Return(Authenticator::REJECTED)); |
257 | 314 |
258 ON_CALL(*mock_authenticator_, rejection_reason()) | 315 ON_CALL(*mock_authenticator_, rejection_reason()) |
259 .WillByDefault(Return(Authenticator::PROTOCOL_ERROR)); | 316 .WillByDefault(Return(Authenticator::PROTOCOL_ERROR)); |
260 | 317 |
261 SendMessageAndWaitForCallback(); | 318 SendMessageAndWaitForCallback(); |
262 ASSERT_TRUE(validate_complete_called_); | 319 ASSERT_TRUE(incoming_complete_called_); |
| 320 ASSERT_FALSE(accepted_complete_called_); |
263 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); | 321 ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED); |
264 ASSERT_EQ(validating_authenticator_->rejection_reason(), | 322 ASSERT_EQ(validating_authenticator_->rejection_reason(), |
265 Authenticator::PROTOCOL_ERROR); | 323 Authenticator::PROTOCOL_ERROR); |
266 } | 324 } |
267 | 325 |
268 } // namespace protocol | 326 } // namespace protocol |
269 } // namespace remoting | 327 } // namespace remoting |
OLD | NEW |