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

Side by Side Diff: remoting/protocol/jingle_session_unittest.cc

Issue 2417913002: Process incoming IQs in the same order that they were sent. (Closed)
Patch Set: Reviewer's feedback Created 4 years, 2 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
OLDNEW
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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "net/socket/socket.h" 15 #include "net/socket/socket.h"
15 #include "net/socket/stream_socket.h" 16 #include "net/socket/stream_socket.h"
16 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
17 #include "remoting/base/constants.h" 18 #include "remoting/base/constants.h"
18 #include "remoting/protocol/authenticator.h" 19 #include "remoting/protocol/authenticator.h"
19 #include "remoting/protocol/channel_authenticator.h" 20 #include "remoting/protocol/channel_authenticator.h"
20 #include "remoting/protocol/chromium_port_allocator_factory.h" 21 #include "remoting/protocol/chromium_port_allocator_factory.h"
21 #include "remoting/protocol/connection_tester.h" 22 #include "remoting/protocol/connection_tester.h"
22 #include "remoting/protocol/fake_authenticator.h" 23 #include "remoting/protocol/fake_authenticator.h"
23 #include "remoting/protocol/jingle_session_manager.h" 24 #include "remoting/protocol/jingle_session_manager.h"
24 #include "remoting/protocol/network_settings.h" 25 #include "remoting/protocol/network_settings.h"
25 #include "remoting/protocol/transport.h" 26 #include "remoting/protocol/transport.h"
26 #include "remoting/protocol/transport_context.h" 27 #include "remoting/protocol/transport_context.h"
27 #include "remoting/signaling/fake_signal_strategy.h" 28 #include "remoting/signaling/fake_signal_strategy.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "third_party/webrtc/libjingle/xmpp/constants.h"
30 32
31 using testing::_; 33 using testing::_;
32 using testing::AtLeast; 34 using testing::AtLeast;
33 using testing::AtMost; 35 using testing::AtMost;
34 using testing::DeleteArg; 36 using testing::DeleteArg;
35 using testing::DoAll; 37 using testing::DoAll;
36 using testing::InSequence; 38 using testing::InSequence;
37 using testing::Invoke; 39 using testing::Invoke;
38 using testing::InvokeWithoutArgs; 40 using testing::InvokeWithoutArgs;
39 using testing::Return; 41 using testing::Return;
40 using testing::SaveArg; 42 using testing::SaveArg;
41 using testing::SetArgumentPointee; 43 using testing::SetArgumentPointee;
42 using testing::WithArg; 44 using testing::WithArg;
43 45
44 namespace remoting { 46 namespace remoting {
45 namespace protocol { 47 namespace protocol {
46 48
47 namespace { 49 namespace {
48 50
49 const char kHostJid[] = "host1@gmail.com/123"; 51 const char kHostJid[] = "host@gmail.com/123";
50 const char kClientJid[] = "host2@gmail.com/321"; 52 const char kClientJid[] = "client@gmail.com/321";
51 53
52 class MockSessionManagerListener { 54 class MockSessionManagerListener {
53 public: 55 public:
54 MOCK_METHOD2(OnIncomingSession, 56 MOCK_METHOD2(OnIncomingSession,
55 void(Session*, 57 void(Session*,
56 SessionManager::IncomingSessionResponse*)); 58 SessionManager::IncomingSessionResponse*));
57 }; 59 };
58 60
59 class MockSessionEventHandler : public Session::EventHandler { 61 class MockSessionEventHandler : public Session::EventHandler {
60 public: 62 public:
61 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); 63 MOCK_METHOD1(OnSessionStateChange, void(Session::State));
62 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, 64 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name,
63 const TransportRoute& route)); 65 const TransportRoute& route));
64 }; 66 };
65 67
66 class MockTransport : public Transport { 68 class MockTransport : public Transport {
Sergey Ulanov 2016/10/19 21:23:39 Maybe rename this to FakeTransport and stop using
kelvinp 2016/10/21 00:26:03 Done.
67 public: 69 public:
68 MOCK_METHOD2(Start, 70 void Start(Authenticator* authenticator,
71 SendTransportInfoCallback send_transport_info_callback) {
72 StartInternal(authenticator, send_transport_info_callback);
73 auto task_runner = base::ThreadTaskRunnerHandle::Get();
74 task_runner->PostTask(FROM_HERE,
75 base::Bind(send_transport_info_callback,
76 base::Passed(CreateTransportInfo("1"))));
Sergey Ulanov 2016/10/19 21:23:39 I think it's better to move this inside the test i
kelvinp 2016/10/21 00:26:03 Done.
77 }
78
79 MOCK_METHOD2(StartInternal,
69 void(Authenticator* authenticator, 80 void(Authenticator* authenticator,
70 SendTransportInfoCallback send_transport_info_callback)); 81 SendTransportInfoCallback send_transport_info_callback));
71 MOCK_METHOD1(ProcessTransportInfo, bool(buzz::XmlElement* transport_info)); 82 MOCK_METHOD1(ProcessTransportInfo, bool(buzz::XmlElement* transport_info));
83
84 private:
85 std::unique_ptr<buzz::XmlElement> CreateTransportInfo(std::string id) {
Sergey Ulanov 2016/10/19 21:23:39 const reference for the parameter.
kelvinp 2016/10/21 00:26:03 Done.
86 std::unique_ptr<buzz::XmlElement> result(
87 buzz::XmlElement::ForStr("<transport xmlns='google:remoting:ice'/>"));
88 result->AddAttr(buzz::QN_ID, id);
89 return result;
90 }
72 }; 91 };
73 92
93 MATCHER_P(WithId, expected, "") {
94 std::string actual = arg->Attr(buzz::QN_ID);
95 return actual == expected;
96 }
97
74 } // namespace 98 } // namespace
75 99
76 class JingleSessionTest : public testing::Test { 100 class JingleSessionTest : public testing::Test {
77 public: 101 public:
78 JingleSessionTest() { 102 JingleSessionTest() {
79 message_loop_.reset(new base::MessageLoopForIO()); 103 message_loop_.reset(new base::MessageLoopForIO());
80 network_settings_ = 104 network_settings_ =
81 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); 105 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING);
82 } 106 }
83 107
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 OnSessionStateChange(Session::ACCEPTED)) 177 OnSessionStateChange(Session::ACCEPTED))
154 .Times(AtMost(1)); 178 .Times(AtMost(1));
155 EXPECT_CALL(host_session_event_handler_, 179 EXPECT_CALL(host_session_event_handler_,
156 OnSessionStateChange(Session::AUTHENTICATING)) 180 OnSessionStateChange(Session::AUTHENTICATING))
157 .Times(AtMost(1)); 181 .Times(AtMost(1));
158 if (expect_fail) { 182 if (expect_fail) {
159 EXPECT_CALL(host_session_event_handler_, 183 EXPECT_CALL(host_session_event_handler_,
160 OnSessionStateChange(Session::FAILED)) 184 OnSessionStateChange(Session::FAILED))
161 .Times(1); 185 .Times(1);
162 } else { 186 } else {
163 EXPECT_CALL(host_transport_, Start(_, _)).Times(1); 187 EXPECT_CALL(host_transport_, StartInternal(_, _)).Times(1);
164 EXPECT_CALL(host_session_event_handler_, 188 EXPECT_CALL(host_session_event_handler_,
165 OnSessionStateChange(Session::AUTHENTICATED)) 189 OnSessionStateChange(Session::AUTHENTICATED))
166 .Times(1); 190 .Times(1);
191 EXPECT_CALL(host_transport_, ProcessTransportInfo(WithId("1")))
192 .Times(1)
193 .WillRepeatedly(Return(true));
167 194
168 // Expect that the connection will be closed eventually. 195 // Expect that the connection will be closed eventually.
169 EXPECT_CALL(host_session_event_handler_, 196 EXPECT_CALL(host_session_event_handler_,
170 OnSessionStateChange(Session::CLOSED)) 197 OnSessionStateChange(Session::CLOSED))
171 .Times(AtMost(1)); 198 .Times(AtMost(1));
172 } 199 }
173 } 200 }
174 201
175 { 202 {
176 InSequence dummy; 203 InSequence dummy;
177 204
178 EXPECT_CALL(client_session_event_handler_, 205 EXPECT_CALL(client_session_event_handler_,
179 OnSessionStateChange(Session::ACCEPTED)) 206 OnSessionStateChange(Session::ACCEPTED))
180 .Times(AtMost(1)); 207 .Times(AtMost(1));
181 EXPECT_CALL(client_session_event_handler_, 208 EXPECT_CALL(client_session_event_handler_,
182 OnSessionStateChange(Session::AUTHENTICATING)) 209 OnSessionStateChange(Session::AUTHENTICATING))
183 .Times(AtMost(1)); 210 .Times(AtMost(1));
184 if (expect_fail) { 211 if (expect_fail) {
185 EXPECT_CALL(client_session_event_handler_, 212 EXPECT_CALL(client_session_event_handler_,
186 OnSessionStateChange(Session::FAILED)) 213 OnSessionStateChange(Session::FAILED))
187 .Times(1); 214 .Times(1);
188 } else { 215 }
189 EXPECT_CALL(client_transport_, Start(_, _)).Times(1); 216 }
217
218 if (!expect_fail) {
219 EXPECT_CALL(client_transport_, StartInternal(_, _)).Times(1);
220 EXPECT_CALL(client_transport_, ProcessTransportInfo(WithId("1")))
221 .Times(1)
222 .WillRepeatedly(Return(true));
223 {
224 InSequence dummy;
190 EXPECT_CALL(client_session_event_handler_, 225 EXPECT_CALL(client_session_event_handler_,
191 OnSessionStateChange(Session::AUTHENTICATED)) 226 OnSessionStateChange(Session::AUTHENTICATED))
192 .Times(1); 227 .Times(1);
193
194 // Expect that the connection will be closed eventually. 228 // Expect that the connection will be closed eventually.
195 EXPECT_CALL(client_session_event_handler_, 229 EXPECT_CALL(client_session_event_handler_,
196 OnSessionStateChange(Session::CLOSED)) 230 OnSessionStateChange(Session::CLOSED))
197 .Times(AtMost(1)); 231 .Times(AtMost(1));
198 } 232 }
199 } 233 }
200 234
201 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( 235 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
202 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 236 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
203 237
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ASSERT_EQ(kClientJid, 317 ASSERT_EQ(kClientJid,
284 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); 318 jingle_element->Attr(buzz::QName(std::string(), "initiator")));
285 } 319 }
286 320
287 // Verify that we can connect two endpoints with multi-step authentication. 321 // Verify that we can connect two endpoints with multi-step authentication.
288 TEST_F(JingleSessionTest, ConnectWithMultistep) { 322 TEST_F(JingleSessionTest, ConnectWithMultistep) {
289 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 323 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
290 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); 324 InitiateConnection(3, FakeAuthenticator::ACCEPT, false);
291 } 325 }
292 326
327 TEST_F(JingleSessionTest, ConnectWithOutofOrderIqs) {
328 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
329 client_signal_strategy_->SimulatePackgeReordering();
330 InitiateConnection(3, FakeAuthenticator::ACCEPT, false);
331 }
332
293 // Verify that connection is terminated when single-step auth fails. 333 // Verify that connection is terminated when single-step auth fails.
294 TEST_F(JingleSessionTest, ConnectWithBadAuth) { 334 TEST_F(JingleSessionTest, ConnectWithBadAuth) {
295 CreateSessionManagers(1, FakeAuthenticator::REJECT); 335 CreateSessionManagers(1, FakeAuthenticator::REJECT);
296 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); 336 InitiateConnection(1, FakeAuthenticator::ACCEPT, true);
297 } 337 }
298 338
299 // Verify that connection is terminated when multi-step auth fails. 339 // Verify that connection is terminated when multi-step auth fails.
300 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { 340 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) {
301 CreateSessionManagers(3, FakeAuthenticator::REJECT); 341 CreateSessionManagers(3, FakeAuthenticator::REJECT);
302 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); 342 InitiateConnection(3, FakeAuthenticator::ACCEPT, true);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 447
408 // Verify that we can connect with multistep authentication. 448 // Verify that we can connect with multistep authentication.
409 TEST_F(JingleSessionTest, TestMultistepAuth) { 449 TEST_F(JingleSessionTest, TestMultistepAuth) {
410 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 450 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
411 ASSERT_NO_FATAL_FAILURE( 451 ASSERT_NO_FATAL_FAILURE(
412 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); 452 InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
413 } 453 }
414 454
415 } // namespace protocol 455 } // namespace protocol
416 } // namespace remoting 456 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698