OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 class MockSessionEventHandler : public Session::EventHandler { | 62 class MockSessionEventHandler : public Session::EventHandler { |
63 public: | 63 public: |
64 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); | 64 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); |
65 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, | 65 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, |
66 const TransportRoute& route)); | 66 const TransportRoute& route)); |
67 }; | 67 }; |
68 | 68 |
69 class FakeTransport : public Transport { | 69 class FakeTransport : public Transport { |
70 public: | 70 public: |
| 71 SendTransportInfoCallback send_transport_info_callback() { |
| 72 return send_transport_info_callback_; |
| 73 } |
| 74 |
| 75 const std::vector<std::unique_ptr<buzz::XmlElement>>& received_messages() { |
| 76 return received_messages_; |
| 77 } |
| 78 |
| 79 void set_on_message_callback(const base::Closure& on_message_callback) { |
| 80 on_message_callback_ = on_message_callback; |
| 81 } |
| 82 |
| 83 // Transport interface. |
71 void Start(Authenticator* authenticator, | 84 void Start(Authenticator* authenticator, |
72 SendTransportInfoCallback send_transport_info_callback) override { | 85 SendTransportInfoCallback send_transport_info_callback) override { |
73 send_transport_info_callback_ = send_transport_info_callback; | 86 send_transport_info_callback_ = send_transport_info_callback; |
74 } | 87 } |
75 | 88 |
76 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override { | 89 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override { |
77 received_messages_.push_back( | 90 received_messages_.push_back( |
78 base::MakeUnique<buzz::XmlElement>(*transport_info)); | 91 base::MakeUnique<buzz::XmlElement>(*transport_info)); |
| 92 if (!on_message_callback_.is_null()) |
| 93 on_message_callback_.Run(); |
79 return true; | 94 return true; |
80 } | 95 } |
81 | 96 |
82 SendTransportInfoCallback send_transport_info_callback() { | |
83 return send_transport_info_callback_; | |
84 } | |
85 | |
86 const std::vector<std::unique_ptr<buzz::XmlElement>>& received_messages() { | |
87 return received_messages_; | |
88 } | |
89 | |
90 private: | 97 private: |
91 SendTransportInfoCallback send_transport_info_callback_; | 98 SendTransportInfoCallback send_transport_info_callback_; |
92 std::vector<std::unique_ptr<buzz::XmlElement>> received_messages_; | 99 std::vector<std::unique_ptr<buzz::XmlElement>> received_messages_; |
| 100 base::Closure on_message_callback_; |
93 }; | 101 }; |
94 | 102 |
95 std::unique_ptr<buzz::XmlElement> CreateTransportInfo(const std::string& id) { | 103 std::unique_ptr<buzz::XmlElement> CreateTransportInfo(const std::string& id) { |
96 std::unique_ptr<buzz::XmlElement> result( | 104 std::unique_ptr<buzz::XmlElement> result( |
97 buzz::XmlElement::ForStr("<transport xmlns='google:remoting:ice'/>")); | 105 buzz::XmlElement::ForStr("<transport xmlns='google:remoting:ice'/>")); |
98 result->AddAttr(buzz::QN_ID, id); | 106 result->AddAttr(buzz::QN_ID, id); |
99 return result; | 107 return result; |
100 } | 108 } |
101 | 109 |
102 } // namespace | 110 } // namespace |
103 | 111 |
104 class JingleSessionTest : public testing::Test { | 112 class JingleSessionTest : public testing::Test { |
105 public: | 113 public: |
106 JingleSessionTest() { | 114 JingleSessionTest() { |
107 message_loop_.reset(new base::MessageLoopForIO()); | 115 message_loop_.reset(new base::MessageLoopForIO()); |
108 network_settings_ = | 116 network_settings_ = |
109 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 117 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
110 } | 118 } |
111 | 119 |
112 // Helper method that handles OnIncomingSession(). | 120 // Helper method that handles OnIncomingSession(). |
113 void SetHostSession(Session* session) { | 121 void SetHostSession(Session* session) { |
114 DCHECK(session); | 122 DCHECK(session); |
115 host_session_.reset(session); | 123 host_session_.reset(session); |
116 host_session_->SetEventHandler(&host_session_event_handler_); | 124 host_session_->SetEventHandler(&host_session_event_handler_); |
117 host_session_->SetTransport(&host_transport_); | 125 host_session_->SetTransport(&host_transport_); |
118 } | 126 } |
119 | 127 |
120 void DeleteSession() { | 128 void DeleteHostSession() { host_session_.reset(); } |
121 host_session_.reset(); | 129 |
122 } | 130 void DeleteClientSession() { client_session_.reset(); } |
123 | 131 |
124 protected: | 132 protected: |
125 void TearDown() override { | 133 void TearDown() override { |
126 CloseSessions(); | 134 CloseSessions(); |
127 CloseSessionManager(); | 135 CloseSessionManager(); |
128 base::RunLoop().RunUntilIdle(); | 136 base::RunLoop().RunUntilIdle(); |
129 } | 137 } |
130 | 138 |
131 void CloseSessions() { | 139 void CloseSessions() { |
132 host_session_.reset(); | 140 host_session_.reset(); |
(...skipping 26 matching lines...) Expand all Loading... |
159 CreateSessionManagers(auth_round_trips, 0, auth_action); | 167 CreateSessionManagers(auth_round_trips, 0, auth_action); |
160 } | 168 } |
161 | 169 |
162 void CloseSessionManager() { | 170 void CloseSessionManager() { |
163 host_server_.reset(); | 171 host_server_.reset(); |
164 client_server_.reset(); | 172 client_server_.reset(); |
165 host_signal_strategy_.reset(); | 173 host_signal_strategy_.reset(); |
166 client_signal_strategy_.reset(); | 174 client_signal_strategy_.reset(); |
167 } | 175 } |
168 | 176 |
169 void InitiateConnection(int auth_round_trips, | 177 void SetHostExpectation(bool expect_fail) { |
170 FakeAuthenticator::Action auth_action, | |
171 bool expect_fail) { | |
172 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 178 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
173 .WillOnce(DoAll( | 179 .WillOnce( |
174 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 180 DoAll(WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
175 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 181 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
176 | 182 |
177 { | 183 { |
178 InSequence dummy; | 184 InSequence dummy; |
179 | 185 |
180 EXPECT_CALL(host_session_event_handler_, | 186 EXPECT_CALL(host_session_event_handler_, |
181 OnSessionStateChange(Session::ACCEPTED)) | 187 OnSessionStateChange(Session::ACCEPTED)) |
182 .Times(AtMost(1)); | 188 .Times(AtMost(1)); |
183 EXPECT_CALL(host_session_event_handler_, | 189 EXPECT_CALL(host_session_event_handler_, |
184 OnSessionStateChange(Session::AUTHENTICATING)) | 190 OnSessionStateChange(Session::AUTHENTICATING)) |
185 .Times(AtMost(1)); | 191 .Times(AtMost(1)); |
186 if (expect_fail) { | 192 if (expect_fail) { |
187 EXPECT_CALL(host_session_event_handler_, | 193 EXPECT_CALL(host_session_event_handler_, |
188 OnSessionStateChange(Session::FAILED)) | 194 OnSessionStateChange(Session::FAILED)) |
189 .Times(1); | 195 .Times(1); |
190 } else { | 196 } else { |
191 EXPECT_CALL(host_session_event_handler_, | 197 EXPECT_CALL(host_session_event_handler_, |
192 OnSessionStateChange(Session::AUTHENTICATED)) | 198 OnSessionStateChange(Session::AUTHENTICATED)) |
193 .Times(1); | 199 .Times(1); |
194 // Expect that the connection will be closed eventually. | 200 // Expect that the connection will be closed eventually. |
195 EXPECT_CALL(host_session_event_handler_, | 201 EXPECT_CALL(host_session_event_handler_, |
196 OnSessionStateChange(Session::CLOSED)) | 202 OnSessionStateChange(Session::CLOSED)) |
197 .Times(AtMost(1)); | 203 .Times(AtMost(1)); |
198 } | 204 } |
199 } | 205 } |
| 206 } |
200 | 207 |
201 { | 208 void SetClientExpectation(bool expect_fail) { |
202 InSequence dummy; | 209 InSequence dummy; |
203 | 210 |
| 211 EXPECT_CALL(client_session_event_handler_, |
| 212 OnSessionStateChange(Session::ACCEPTED)) |
| 213 .Times(AtMost(1)); |
| 214 EXPECT_CALL(client_session_event_handler_, |
| 215 OnSessionStateChange(Session::AUTHENTICATING)) |
| 216 .Times(AtMost(1)); |
| 217 if (expect_fail) { |
204 EXPECT_CALL(client_session_event_handler_, | 218 EXPECT_CALL(client_session_event_handler_, |
205 OnSessionStateChange(Session::ACCEPTED)) | 219 OnSessionStateChange(Session::FAILED)) |
| 220 .Times(1); |
| 221 } else { |
| 222 EXPECT_CALL(client_session_event_handler_, |
| 223 OnSessionStateChange(Session::AUTHENTICATED)) |
| 224 .Times(1); |
| 225 // Expect that the connection will be closed eventually. |
| 226 EXPECT_CALL(client_session_event_handler_, |
| 227 OnSessionStateChange(Session::CLOSED)) |
206 .Times(AtMost(1)); | 228 .Times(AtMost(1)); |
207 EXPECT_CALL(client_session_event_handler_, | |
208 OnSessionStateChange(Session::AUTHENTICATING)) | |
209 .Times(AtMost(1)); | |
210 if (expect_fail) { | |
211 EXPECT_CALL(client_session_event_handler_, | |
212 OnSessionStateChange(Session::FAILED)) | |
213 .Times(1); | |
214 } else { | |
215 EXPECT_CALL(client_session_event_handler_, | |
216 OnSessionStateChange(Session::AUTHENTICATED)) | |
217 .Times(1); | |
218 // Expect that the connection will be closed eventually. | |
219 EXPECT_CALL(client_session_event_handler_, | |
220 OnSessionStateChange(Session::CLOSED)) | |
221 .Times(AtMost(1)); | |
222 } | |
223 } | 229 } |
| 230 } |
224 | 231 |
225 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 232 void ConnectClient(std::unique_ptr<Authenticator> authenticator) { |
226 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | |
227 | |
228 client_session_ = | 233 client_session_ = |
229 client_server_->Connect(kHostJid, std::move(authenticator)); | 234 client_server_->Connect(kHostJid, std::move(authenticator)); |
230 client_session_->SetEventHandler(&client_session_event_handler_); | 235 client_session_->SetEventHandler(&client_session_event_handler_); |
231 client_session_->SetTransport(&client_transport_); | 236 client_session_->SetTransport(&client_transport_); |
| 237 base::RunLoop().RunUntilIdle(); |
| 238 } |
232 | 239 |
233 base::RunLoop().RunUntilIdle(); | 240 void InitiateConnection(int auth_round_trips, |
| 241 FakeAuthenticator::Action auth_action, |
| 242 bool expect_fail) { |
| 243 SetHostExpectation(expect_fail); |
| 244 SetClientExpectation(expect_fail); |
| 245 ConnectClient(base::MakeUnique<FakeAuthenticator>( |
| 246 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); |
234 } | 247 } |
235 | 248 |
236 void ExpectRouteChange(const std::string& channel_name) { | 249 void ExpectRouteChange(const std::string& channel_name) { |
237 EXPECT_CALL(host_session_event_handler_, | 250 EXPECT_CALL(host_session_event_handler_, |
238 OnSessionRouteChange(channel_name, _)) | 251 OnSessionRouteChange(channel_name, _)) |
239 .Times(AtLeast(1)); | 252 .Times(AtLeast(1)); |
240 EXPECT_CALL(client_session_event_handler_, | 253 EXPECT_CALL(client_session_event_handler_, |
241 OnSessionRouteChange(channel_name, _)) | 254 OnSessionRouteChange(channel_name, _)) |
242 .Times(AtLeast(1)); | 255 .Times(AtLeast(1)); |
243 } | 256 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 ASSERT_EQ(kClientJid, | 320 ASSERT_EQ(kClientJid, |
308 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); | 321 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); |
309 } | 322 } |
310 | 323 |
311 // Verify that we can connect two endpoints with multi-step authentication. | 324 // Verify that we can connect two endpoints with multi-step authentication. |
312 TEST_F(JingleSessionTest, ConnectWithMultistep) { | 325 TEST_F(JingleSessionTest, ConnectWithMultistep) { |
313 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 326 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
314 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); | 327 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); |
315 } | 328 } |
316 | 329 |
317 TEST_F(JingleSessionTest, ConnectWithOutofOrderIqs) { | 330 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqs) { |
318 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 331 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
319 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 332 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
320 client_signal_strategy_->SimulatePackgeReordering(); | 333 client_signal_strategy_->SimulatePackgeReordering(); |
| 334 |
321 // Verify that out of order transport messages are received correctly. | 335 // Verify that out of order transport messages are received correctly. |
322 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); | 336 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
323 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); | 337 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
324 base::RunLoop().RunUntilIdle(); | 338 base::RunLoop().RunUntilIdle(); |
325 EXPECT_EQ(client_transport_.received_messages()[0]->Attr(buzz::QN_ID), "1"); | 339 |
326 EXPECT_EQ(client_transport_.received_messages()[1]->Attr(buzz::QN_ID), "2"); | 340 ASSERT_EQ(client_transport_.received_messages().size(), 2U); |
| 341 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
| 342 EXPECT_EQ("2", client_transport_.received_messages()[1]->Attr(buzz::QN_ID)); |
| 343 } |
| 344 |
| 345 // Verify that out-of-order messages are handled correctly when the session is |
| 346 // torn down after the first message. |
| 347 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqsDestroyOnFirstMessage) { |
| 348 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 349 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
| 350 client_signal_strategy_->SimulatePackgeReordering(); |
| 351 |
| 352 // Verify that out of order transport messages are received correctly. |
| 353 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
| 354 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
| 355 |
| 356 // Destroy the session as soon as the first message is received. |
| 357 client_transport_.set_on_message_callback(base::Bind( |
| 358 &JingleSessionTest::DeleteClientSession, base::Unretained(this))); |
| 359 |
| 360 base::RunLoop().RunUntilIdle(); |
| 361 |
| 362 ASSERT_EQ(client_transport_.received_messages().size(), 1U); |
| 363 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
327 } | 364 } |
328 | 365 |
329 // Verify that connection is terminated when single-step auth fails. | 366 // Verify that connection is terminated when single-step auth fails. |
330 TEST_F(JingleSessionTest, ConnectWithBadAuth) { | 367 TEST_F(JingleSessionTest, ConnectWithBadAuth) { |
331 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 368 CreateSessionManagers(1, FakeAuthenticator::REJECT); |
332 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 369 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); |
333 } | 370 } |
334 | 371 |
335 // Verify that connection is terminated when multi-step auth fails. | 372 // Verify that connection is terminated when multi-step auth fails. |
336 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { | 373 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 434 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
398 .WillOnce(DoAll( | 435 .WillOnce(DoAll( |
399 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 436 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
400 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 437 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
401 | 438 |
402 EXPECT_CALL(host_session_event_handler_, | 439 EXPECT_CALL(host_session_event_handler_, |
403 OnSessionStateChange(Session::ACCEPTED)) | 440 OnSessionStateChange(Session::ACCEPTED)) |
404 .Times(AtMost(1)); | 441 .Times(AtMost(1)); |
405 | 442 |
406 EXPECT_CALL(host_session_event_handler_, | 443 EXPECT_CALL(host_session_event_handler_, |
407 OnSessionStateChange(Session::AUTHENTICATING)) | 444 OnSessionStateChange(Session::AUTHENTICATING)) |
408 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); | 445 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); |
409 | 446 |
410 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 447 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( |
411 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | 448 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); |
412 | 449 |
413 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); | 450 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
414 | 451 |
415 base::RunLoop().RunUntilIdle(); | 452 base::RunLoop().RunUntilIdle(); |
416 } | 453 } |
417 | 454 |
418 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { | 455 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { |
419 // Same as the previous test, but set messages_till_started to 2 in | 456 // Same as the previous test, but set messages_till_started to 2 in |
420 // CreateSessionManagers so that the session will goes into the | 457 // CreateSessionManagers so that the session will goes into the |
421 // AUTHENTICATING state after two message exchanges. | 458 // AUTHENTICATING state after two message exchanges. |
422 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); | 459 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); |
423 | 460 |
424 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 461 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
425 .WillOnce(DoAll( | 462 .WillOnce( |
426 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 463 DoAll(WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
427 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 464 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
428 | 465 |
429 EXPECT_CALL(host_session_event_handler_, | 466 EXPECT_CALL(host_session_event_handler_, |
430 OnSessionStateChange(Session::ACCEPTED)) | 467 OnSessionStateChange(Session::ACCEPTED)) |
431 .Times(AtMost(1)); | 468 .Times(AtMost(1)); |
432 | 469 |
433 EXPECT_CALL(host_session_event_handler_, | 470 EXPECT_CALL(host_session_event_handler_, |
434 OnSessionStateChange(Session::AUTHENTICATING)) | 471 OnSessionStateChange(Session::AUTHENTICATING)) |
435 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); | 472 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); |
436 | 473 |
437 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 474 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( |
438 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | 475 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); |
439 | 476 |
440 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); | 477 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
441 base::RunLoop().RunUntilIdle(); | 478 base::RunLoop().RunUntilIdle(); |
442 } | 479 } |
443 | 480 |
444 // Verify that we can connect with multistep authentication. | 481 // Verify that we can connect with multistep authentication. |
445 TEST_F(JingleSessionTest, TestMultistepAuth) { | 482 TEST_F(JingleSessionTest, TestMultistepAuth) { |
446 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 483 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
447 ASSERT_NO_FATAL_FAILURE( | 484 ASSERT_NO_FATAL_FAILURE( |
448 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 485 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
449 } | 486 } |
450 | 487 |
| 488 // Verify that incoming transport-info messages are handled correctly while in |
| 489 // AUTHENTICATING state. |
| 490 TEST_F(JingleSessionTest, TransportInfoDuringAuthentication) { |
| 491 CreateSessionManagers(2, FakeAuthenticator::ACCEPT); |
| 492 |
| 493 SetHostExpectation(false); |
| 494 { |
| 495 InSequence dummy; |
| 496 |
| 497 EXPECT_CALL(client_session_event_handler_, |
| 498 OnSessionStateChange(Session::ACCEPTED)) |
| 499 .Times(AtMost(1)); |
| 500 EXPECT_CALL(client_session_event_handler_, |
| 501 OnSessionStateChange(Session::AUTHENTICATING)) |
| 502 .Times(AtMost(1)); |
| 503 } |
| 504 |
| 505 // Create connection and pause it before authentication is finished. |
| 506 FakeAuthenticator* authenticator = new FakeAuthenticator( |
| 507 FakeAuthenticator::CLIENT, 2, FakeAuthenticator::ACCEPT, true); |
| 508 authenticator->set_pause_message_index(4); |
| 509 ConnectClient(base::WrapUnique(authenticator)); |
| 510 |
| 511 // Send 2 transport messages. |
| 512 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
| 513 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
| 514 |
| 515 base::RunLoop().RunUntilIdle(); |
| 516 |
| 517 // The transport-info messages should not be received here because |
| 518 // authentication hasn't finished. |
| 519 EXPECT_TRUE(client_transport_.received_messages().empty()); |
| 520 |
| 521 // Destroy the session as soon as the first message is received. |
| 522 client_transport_.set_on_message_callback(base::Bind( |
| 523 &JingleSessionTest::DeleteClientSession, base::Unretained(this))); |
| 524 |
| 525 // Resume authentication. |
| 526 authenticator->Resume(); |
| 527 base::RunLoop().RunUntilIdle(); |
| 528 |
| 529 // Verify that transport-info that the first transport-info message was |
| 530 // received. |
| 531 ASSERT_EQ(client_transport_.received_messages().size(), 1U); |
| 532 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
| 533 } |
| 534 |
451 } // namespace protocol | 535 } // namespace protocol |
452 } // namespace remoting | 536 } // namespace remoting |
OLD | NEW |