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

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, 1 month 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 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 13 #include "base/run_loop.h"
12 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "net/socket/socket.h" 16 #include "net/socket/socket.h"
15 #include "net/socket/stream_socket.h" 17 #include "net/socket/stream_socket.h"
16 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
17 #include "remoting/base/constants.h" 19 #include "remoting/base/constants.h"
18 #include "remoting/protocol/authenticator.h" 20 #include "remoting/protocol/authenticator.h"
19 #include "remoting/protocol/channel_authenticator.h" 21 #include "remoting/protocol/channel_authenticator.h"
20 #include "remoting/protocol/chromium_port_allocator_factory.h" 22 #include "remoting/protocol/chromium_port_allocator_factory.h"
21 #include "remoting/protocol/connection_tester.h" 23 #include "remoting/protocol/connection_tester.h"
22 #include "remoting/protocol/fake_authenticator.h" 24 #include "remoting/protocol/fake_authenticator.h"
23 #include "remoting/protocol/jingle_session_manager.h" 25 #include "remoting/protocol/jingle_session_manager.h"
24 #include "remoting/protocol/network_settings.h" 26 #include "remoting/protocol/network_settings.h"
25 #include "remoting/protocol/transport.h" 27 #include "remoting/protocol/transport.h"
26 #include "remoting/protocol/transport_context.h" 28 #include "remoting/protocol/transport_context.h"
27 #include "remoting/signaling/fake_signal_strategy.h" 29 #include "remoting/signaling/fake_signal_strategy.h"
28 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/webrtc/libjingle/xmpp/constants.h"
30 33
31 using testing::_; 34 using testing::_;
32 using testing::AtLeast; 35 using testing::AtLeast;
33 using testing::AtMost; 36 using testing::AtMost;
34 using testing::DeleteArg; 37 using testing::DeleteArg;
35 using testing::DoAll; 38 using testing::DoAll;
36 using testing::InSequence; 39 using testing::InSequence;
37 using testing::Invoke; 40 using testing::Invoke;
38 using testing::InvokeWithoutArgs; 41 using testing::InvokeWithoutArgs;
39 using testing::Return; 42 using testing::Return;
40 using testing::SaveArg; 43 using testing::SaveArg;
41 using testing::SetArgumentPointee; 44 using testing::SetArgumentPointee;
42 using testing::WithArg; 45 using testing::WithArg;
43 46
44 namespace remoting { 47 namespace remoting {
45 namespace protocol { 48 namespace protocol {
46 49
47 namespace { 50 namespace {
48 51
49 const char kHostJid[] = "host1@gmail.com/123"; 52 const char kHostJid[] = "host@gmail.com/123";
50 const char kClientJid[] = "host2@gmail.com/321"; 53 const char kClientJid[] = "client@gmail.com/321";
51 54
52 class MockSessionManagerListener { 55 class MockSessionManagerListener {
53 public: 56 public:
54 MOCK_METHOD2(OnIncomingSession, 57 MOCK_METHOD2(OnIncomingSession,
55 void(Session*, 58 void(Session*,
56 SessionManager::IncomingSessionResponse*)); 59 SessionManager::IncomingSessionResponse*));
57 }; 60 };
58 61
59 class MockSessionEventHandler : public Session::EventHandler { 62 class MockSessionEventHandler : public Session::EventHandler {
60 public: 63 public:
61 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); 64 MOCK_METHOD1(OnSessionStateChange, void(Session::State));
62 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, 65 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name,
63 const TransportRoute& route)); 66 const TransportRoute& route));
64 }; 67 };
65 68
66 class MockTransport : public Transport { 69 class FakeTransport : public Transport {
67 public: 70 public:
68 MOCK_METHOD2(Start, 71 void Start(Authenticator* authenticator,
69 void(Authenticator* authenticator, 72 SendTransportInfoCallback send_transport_info_callback) override {
70 SendTransportInfoCallback send_transport_info_callback)); 73 send_transport_info_callback_ = send_transport_info_callback;
71 MOCK_METHOD1(ProcessTransportInfo, bool(buzz::XmlElement* transport_info)); 74 }
75
76 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override {
77 received_messages_.push_back(
78 base::MakeUnique<buzz::XmlElement>(*transport_info));
79 return true;
80 }
81
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:
91 SendTransportInfoCallback send_transport_info_callback_;
92 std::vector<std::unique_ptr<buzz::XmlElement>> received_messages_;
72 }; 93 };
73 94
95 std::unique_ptr<buzz::XmlElement> CreateTransportInfo(const std::string& id) {
96 std::unique_ptr<buzz::XmlElement> result(
97 buzz::XmlElement::ForStr("<transport xmlns='google:remoting:ice'/>"));
98 result->AddAttr(buzz::QN_ID, id);
99 return result;
100 }
101
74 } // namespace 102 } // namespace
75 103
76 class JingleSessionTest : public testing::Test { 104 class JingleSessionTest : public testing::Test {
77 public: 105 public:
78 JingleSessionTest() { 106 JingleSessionTest() {
79 message_loop_.reset(new base::MessageLoopForIO()); 107 message_loop_.reset(new base::MessageLoopForIO());
80 network_settings_ = 108 network_settings_ =
81 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); 109 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING);
82 } 110 }
83 111
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 OnSessionStateChange(Session::ACCEPTED)) 181 OnSessionStateChange(Session::ACCEPTED))
154 .Times(AtMost(1)); 182 .Times(AtMost(1));
155 EXPECT_CALL(host_session_event_handler_, 183 EXPECT_CALL(host_session_event_handler_,
156 OnSessionStateChange(Session::AUTHENTICATING)) 184 OnSessionStateChange(Session::AUTHENTICATING))
157 .Times(AtMost(1)); 185 .Times(AtMost(1));
158 if (expect_fail) { 186 if (expect_fail) {
159 EXPECT_CALL(host_session_event_handler_, 187 EXPECT_CALL(host_session_event_handler_,
160 OnSessionStateChange(Session::FAILED)) 188 OnSessionStateChange(Session::FAILED))
161 .Times(1); 189 .Times(1);
162 } else { 190 } else {
163 EXPECT_CALL(host_transport_, Start(_, _)).Times(1);
164 EXPECT_CALL(host_session_event_handler_, 191 EXPECT_CALL(host_session_event_handler_,
165 OnSessionStateChange(Session::AUTHENTICATED)) 192 OnSessionStateChange(Session::AUTHENTICATED))
166 .Times(1); 193 .Times(1);
167
168 // Expect that the connection will be closed eventually. 194 // Expect that the connection will be closed eventually.
169 EXPECT_CALL(host_session_event_handler_, 195 EXPECT_CALL(host_session_event_handler_,
170 OnSessionStateChange(Session::CLOSED)) 196 OnSessionStateChange(Session::CLOSED))
171 .Times(AtMost(1)); 197 .Times(AtMost(1));
172 } 198 }
173 } 199 }
174 200
175 { 201 {
176 InSequence dummy; 202 InSequence dummy;
177 203
178 EXPECT_CALL(client_session_event_handler_, 204 EXPECT_CALL(client_session_event_handler_,
179 OnSessionStateChange(Session::ACCEPTED)) 205 OnSessionStateChange(Session::ACCEPTED))
180 .Times(AtMost(1)); 206 .Times(AtMost(1));
181 EXPECT_CALL(client_session_event_handler_, 207 EXPECT_CALL(client_session_event_handler_,
182 OnSessionStateChange(Session::AUTHENTICATING)) 208 OnSessionStateChange(Session::AUTHENTICATING))
183 .Times(AtMost(1)); 209 .Times(AtMost(1));
184 if (expect_fail) { 210 if (expect_fail) {
185 EXPECT_CALL(client_session_event_handler_, 211 EXPECT_CALL(client_session_event_handler_,
186 OnSessionStateChange(Session::FAILED)) 212 OnSessionStateChange(Session::FAILED))
187 .Times(1); 213 .Times(1);
188 } else { 214 } else {
189 EXPECT_CALL(client_transport_, Start(_, _)).Times(1);
190 EXPECT_CALL(client_session_event_handler_, 215 EXPECT_CALL(client_session_event_handler_,
191 OnSessionStateChange(Session::AUTHENTICATED)) 216 OnSessionStateChange(Session::AUTHENTICATED))
192 .Times(1); 217 .Times(1);
193
194 // Expect that the connection will be closed eventually. 218 // Expect that the connection will be closed eventually.
195 EXPECT_CALL(client_session_event_handler_, 219 EXPECT_CALL(client_session_event_handler_,
196 OnSessionStateChange(Session::CLOSED)) 220 OnSessionStateChange(Session::CLOSED))
197 .Times(AtMost(1)); 221 .Times(AtMost(1));
198 } 222 }
199 } 223 }
200 224
201 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( 225 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
202 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 226 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
203 227
(...skipping 20 matching lines...) Expand all
224 248
225 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_; 249 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_;
226 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_; 250 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_;
227 251
228 std::unique_ptr<JingleSessionManager> host_server_; 252 std::unique_ptr<JingleSessionManager> host_server_;
229 MockSessionManagerListener host_server_listener_; 253 MockSessionManagerListener host_server_listener_;
230 std::unique_ptr<JingleSessionManager> client_server_; 254 std::unique_ptr<JingleSessionManager> client_server_;
231 255
232 std::unique_ptr<Session> host_session_; 256 std::unique_ptr<Session> host_session_;
233 MockSessionEventHandler host_session_event_handler_; 257 MockSessionEventHandler host_session_event_handler_;
234 MockTransport host_transport_; 258 FakeTransport host_transport_;
235 std::unique_ptr<Session> client_session_; 259 std::unique_ptr<Session> client_session_;
236 MockSessionEventHandler client_session_event_handler_; 260 MockSessionEventHandler client_session_event_handler_;
237 MockTransport client_transport_; 261 FakeTransport client_transport_;
238 }; 262 };
239 263
240 264
241 // Verify that we can create and destroy session managers without a 265 // Verify that we can create and destroy session managers without a
242 // connection. 266 // connection.
243 TEST_F(JingleSessionTest, CreateAndDestoy) { 267 TEST_F(JingleSessionTest, CreateAndDestoy) {
244 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 268 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
245 } 269 }
246 270
247 // Verify that an incoming session can be rejected, and that the 271 // Verify that an incoming session can be rejected, and that the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ASSERT_EQ(kClientJid, 307 ASSERT_EQ(kClientJid,
284 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); 308 jingle_element->Attr(buzz::QName(std::string(), "initiator")));
285 } 309 }
286 310
287 // Verify that we can connect two endpoints with multi-step authentication. 311 // Verify that we can connect two endpoints with multi-step authentication.
288 TEST_F(JingleSessionTest, ConnectWithMultistep) { 312 TEST_F(JingleSessionTest, ConnectWithMultistep) {
289 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 313 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
290 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); 314 InitiateConnection(3, FakeAuthenticator::ACCEPT, false);
291 } 315 }
292 316
317 TEST_F(JingleSessionTest, ConnectWithOutofOrderIqs) {
318 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
319 client_signal_strategy_->SimulatePackgeReordering();
Sergey Ulanov 2016/10/21 19:19:39 Move this after InitiateConnection(). Then FakeSig
kelvinp 2016/10/21 22:41:27 Done.
320 InitiateConnection(1, FakeAuthenticator::ACCEPT, false);
321 // Verify that out of order transport messages are received correctly.
322 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1"));
323 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2"));
324 base::RunLoop().RunUntilIdle();
325 EXPECT_EQ(client_transport_.received_messages()[0]->Attr(buzz::QN_ID), "1");
326 EXPECT_EQ(client_transport_.received_messages()[1]->Attr(buzz::QN_ID), "2");
327 }
328
293 // Verify that connection is terminated when single-step auth fails. 329 // Verify that connection is terminated when single-step auth fails.
294 TEST_F(JingleSessionTest, ConnectWithBadAuth) { 330 TEST_F(JingleSessionTest, ConnectWithBadAuth) {
295 CreateSessionManagers(1, FakeAuthenticator::REJECT); 331 CreateSessionManagers(1, FakeAuthenticator::REJECT);
296 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); 332 InitiateConnection(1, FakeAuthenticator::ACCEPT, true);
297 } 333 }
298 334
299 // Verify that connection is terminated when multi-step auth fails. 335 // Verify that connection is terminated when multi-step auth fails.
300 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { 336 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) {
301 CreateSessionManagers(3, FakeAuthenticator::REJECT); 337 CreateSessionManagers(3, FakeAuthenticator::REJECT);
302 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); 338 InitiateConnection(3, FakeAuthenticator::ACCEPT, true);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 443
408 // Verify that we can connect with multistep authentication. 444 // Verify that we can connect with multistep authentication.
409 TEST_F(JingleSessionTest, TestMultistepAuth) { 445 TEST_F(JingleSessionTest, TestMultistepAuth) {
410 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 446 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
411 ASSERT_NO_FATAL_FAILURE( 447 ASSERT_NO_FATAL_FAILURE(
412 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); 448 InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
413 } 449 }
414 450
415 } // namespace protocol 451 } // namespace protocol
416 } // namespace remoting 452 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698