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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); 110 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid));
111 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); 111 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid));
112 FakeSignalStrategy::Connect(host_signal_strategy_.get(), 112 FakeSignalStrategy::Connect(host_signal_strategy_.get(),
113 client_signal_strategy_.get()); 113 client_signal_strategy_.get());
114 114
115 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); 115 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get()));
116 host_server_->AcceptIncoming( 116 host_server_->AcceptIncoming(
117 base::Bind(&MockSessionManagerListener::OnIncomingSession, 117 base::Bind(&MockSessionManagerListener::OnIncomingSession,
118 base::Unretained(&host_server_listener_))); 118 base::Unretained(&host_server_listener_)));
119 119
120 scoped_ptr<AuthenticatorFactory> factory( 120 std::unique_ptr<AuthenticatorFactory> factory(
121 new FakeHostAuthenticatorFactory(auth_round_trips, 121 new FakeHostAuthenticatorFactory(auth_round_trips, messages_till_start,
122 messages_till_start, auth_action, true)); 122 auth_action, true));
123 host_server_->set_authenticator_factory(std::move(factory)); 123 host_server_->set_authenticator_factory(std::move(factory));
124 124
125 client_server_.reset( 125 client_server_.reset(
126 new JingleSessionManager(client_signal_strategy_.get())); 126 new JingleSessionManager(client_signal_strategy_.get()));
127 } 127 }
128 128
129 void CreateSessionManagers(int auth_round_trips, 129 void CreateSessionManagers(int auth_round_trips,
130 FakeAuthenticator::Action auth_action) { 130 FakeAuthenticator::Action auth_action) {
131 CreateSessionManagers(auth_round_trips, 0, auth_action); 131 CreateSessionManagers(auth_round_trips, 0, auth_action);
132 } 132 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 OnSessionStateChange(Session::AUTHENTICATED)) 191 OnSessionStateChange(Session::AUTHENTICATED))
192 .Times(1); 192 .Times(1);
193 193
194 // Expect that the connection will be closed eventually. 194 // Expect that the connection will be closed eventually.
195 EXPECT_CALL(client_session_event_handler_, 195 EXPECT_CALL(client_session_event_handler_,
196 OnSessionStateChange(Session::CLOSED)) 196 OnSessionStateChange(Session::CLOSED))
197 .Times(AtMost(1)); 197 .Times(AtMost(1));
198 } 198 }
199 } 199 }
200 200
201 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 201 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
202 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 202 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
203 203
204 client_session_ = 204 client_session_ =
205 client_server_->Connect(kHostJid, std::move(authenticator)); 205 client_server_->Connect(kHostJid, std::move(authenticator));
206 client_session_->SetEventHandler(&client_session_event_handler_); 206 client_session_->SetEventHandler(&client_session_event_handler_);
207 client_session_->SetTransport(&client_transport_); 207 client_session_->SetTransport(&client_transport_);
208 208
209 base::RunLoop().RunUntilIdle(); 209 base::RunLoop().RunUntilIdle();
210 } 210 }
211 211
212 void ExpectRouteChange(const std::string& channel_name) { 212 void ExpectRouteChange(const std::string& channel_name) {
213 EXPECT_CALL(host_session_event_handler_, 213 EXPECT_CALL(host_session_event_handler_,
214 OnSessionRouteChange(channel_name, _)) 214 OnSessionRouteChange(channel_name, _))
215 .Times(AtLeast(1)); 215 .Times(AtLeast(1));
216 EXPECT_CALL(client_session_event_handler_, 216 EXPECT_CALL(client_session_event_handler_,
217 OnSessionRouteChange(channel_name, _)) 217 OnSessionRouteChange(channel_name, _))
218 .Times(AtLeast(1)); 218 .Times(AtLeast(1));
219 } 219 }
220 220
221 scoped_ptr<base::MessageLoopForIO> message_loop_; 221 std::unique_ptr<base::MessageLoopForIO> message_loop_;
222 222
223 NetworkSettings network_settings_; 223 NetworkSettings network_settings_;
224 224
225 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; 225 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_;
226 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; 226 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_;
227 227
228 scoped_ptr<JingleSessionManager> host_server_; 228 std::unique_ptr<JingleSessionManager> host_server_;
229 MockSessionManagerListener host_server_listener_; 229 MockSessionManagerListener host_server_listener_;
230 scoped_ptr<JingleSessionManager> client_server_; 230 std::unique_ptr<JingleSessionManager> client_server_;
231 231
232 scoped_ptr<Session> host_session_; 232 std::unique_ptr<Session> host_session_;
233 MockSessionEventHandler host_session_event_handler_; 233 MockSessionEventHandler host_session_event_handler_;
234 MockTransport host_transport_; 234 MockTransport host_transport_;
235 scoped_ptr<Session> client_session_; 235 std::unique_ptr<Session> client_session_;
236 MockSessionEventHandler client_session_event_handler_; 236 MockSessionEventHandler client_session_event_handler_;
237 MockTransport client_transport_; 237 MockTransport client_transport_;
238 }; 238 };
239 239
240 240
241 // Verify that we can create and destroy session managers without a 241 // Verify that we can create and destroy session managers without a
242 // connection. 242 // connection.
243 TEST_F(JingleSessionTest, CreateAndDestoy) { 243 TEST_F(JingleSessionTest, CreateAndDestoy) {
244 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 244 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
245 } 245 }
246 246
247 // Verify that an incoming session can be rejected, and that the 247 // Verify that an incoming session can be rejected, and that the
248 // status of the connection is set to FAILED in this case. 248 // status of the connection is set to FAILED in this case.
249 TEST_F(JingleSessionTest, RejectConnection) { 249 TEST_F(JingleSessionTest, RejectConnection) {
250 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 250 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
251 251
252 // Reject incoming session. 252 // Reject incoming session.
253 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) 253 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
254 .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE)); 254 .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE));
255 255
256 { 256 {
257 InSequence dummy; 257 InSequence dummy;
258 EXPECT_CALL(client_session_event_handler_, 258 EXPECT_CALL(client_session_event_handler_,
259 OnSessionStateChange(Session::FAILED)) 259 OnSessionStateChange(Session::FAILED))
260 .Times(1); 260 .Times(1);
261 } 261 }
262 262
263 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 263 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
264 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); 264 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true));
265 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); 265 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator));
266 client_session_->SetEventHandler(&client_session_event_handler_); 266 client_session_->SetEventHandler(&client_session_event_handler_);
267 267
268 base::RunLoop().RunUntilIdle(); 268 base::RunLoop().RunUntilIdle();
269 } 269 }
270 270
271 // Verify that we can connect two endpoints with single-step authentication. 271 // Verify that we can connect two endpoints with single-step authentication.
272 TEST_F(JingleSessionTest, Connect) { 272 TEST_F(JingleSessionTest, Connect) {
273 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 273 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Verify that incompatible protocol configuration is handled properly. 305 // Verify that incompatible protocol configuration is handled properly.
306 TEST_F(JingleSessionTest, TestIncompatibleProtocol) { 306 TEST_F(JingleSessionTest, TestIncompatibleProtocol) {
307 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 307 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
308 308
309 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); 309 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0);
310 310
311 EXPECT_CALL(client_session_event_handler_, 311 EXPECT_CALL(client_session_event_handler_,
312 OnSessionStateChange(Session::FAILED)) 312 OnSessionStateChange(Session::FAILED))
313 .Times(1); 313 .Times(1);
314 314
315 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 315 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
316 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); 316 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true));
317 317
318 scoped_ptr<CandidateSessionConfig> config = 318 std::unique_ptr<CandidateSessionConfig> config =
319 CandidateSessionConfig::CreateDefault(); 319 CandidateSessionConfig::CreateDefault();
320 // Disable all video codecs so the host will reject connection. 320 // Disable all video codecs so the host will reject connection.
321 config->mutable_video_configs()->clear(); 321 config->mutable_video_configs()->clear();
322 client_server_->set_protocol_config(std::move(config)); 322 client_server_->set_protocol_config(std::move(config));
323 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); 323 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator));
324 client_session_->SetEventHandler(&client_session_event_handler_); 324 client_session_->SetEventHandler(&client_session_event_handler_);
325 325
326 base::RunLoop().RunUntilIdle(); 326 base::RunLoop().RunUntilIdle();
327 327
328 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); 328 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error());
329 EXPECT_FALSE(host_session_); 329 EXPECT_FALSE(host_session_);
330 } 330 }
331 331
332 // Verify that GICE-only client is rejected with an appropriate error code. 332 // Verify that GICE-only client is rejected with an appropriate error code.
333 TEST_F(JingleSessionTest, TestLegacyIceConnection) { 333 TEST_F(JingleSessionTest, TestLegacyIceConnection) {
334 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 334 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
335 335
336 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); 336 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0);
337 337
338 EXPECT_CALL(client_session_event_handler_, 338 EXPECT_CALL(client_session_event_handler_,
339 OnSessionStateChange(Session::FAILED)) 339 OnSessionStateChange(Session::FAILED))
340 .Times(1); 340 .Times(1);
341 341
342 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 342 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
343 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); 343 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true));
344 344
345 scoped_ptr<CandidateSessionConfig> config = 345 std::unique_ptr<CandidateSessionConfig> config =
346 CandidateSessionConfig::CreateDefault(); 346 CandidateSessionConfig::CreateDefault();
347 config->set_ice_supported(false); 347 config->set_ice_supported(false);
348 client_server_->set_protocol_config(std::move(config)); 348 client_server_->set_protocol_config(std::move(config));
349 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); 349 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator));
350 client_session_->SetEventHandler(&client_session_event_handler_); 350 client_session_->SetEventHandler(&client_session_event_handler_);
351 351
352 base::RunLoop().RunUntilIdle(); 352 base::RunLoop().RunUntilIdle();
353 353
354 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); 354 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error());
355 EXPECT_FALSE(host_session_); 355 EXPECT_FALSE(host_session_);
356 } 356 }
357 357
358 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) { 358 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) {
359 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 359 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
360 360
361 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) 361 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
362 .WillOnce(DoAll( 362 .WillOnce(DoAll(
363 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), 363 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)),
364 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); 364 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT)));
365 365
366 EXPECT_CALL(host_session_event_handler_, 366 EXPECT_CALL(host_session_event_handler_,
367 OnSessionStateChange(Session::ACCEPTED)) 367 OnSessionStateChange(Session::ACCEPTED))
368 .Times(AtMost(1)); 368 .Times(AtMost(1));
369 369
370 EXPECT_CALL(host_session_event_handler_, 370 EXPECT_CALL(host_session_event_handler_,
371 OnSessionStateChange(Session::AUTHENTICATING)) 371 OnSessionStateChange(Session::AUTHENTICATING))
372 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); 372 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession));
373 373
374 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 374 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
375 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); 375 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true));
376 376
377 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); 377 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator));
378 378
379 base::RunLoop().RunUntilIdle(); 379 base::RunLoop().RunUntilIdle();
380 } 380 }
381 381
382 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { 382 TEST_F(JingleSessionTest, DeleteSessionOnAuth) {
383 // Same as the previous test, but set messages_till_started to 2 in 383 // Same as the previous test, but set messages_till_started to 2 in
384 // CreateSessionManagers so that the session will goes into the 384 // CreateSessionManagers so that the session will goes into the
385 // AUTHENTICATING state after two message exchanges. 385 // AUTHENTICATING state after two message exchanges.
386 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); 386 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT);
387 387
388 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) 388 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
389 .WillOnce(DoAll( 389 .WillOnce(DoAll(
390 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), 390 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)),
391 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); 391 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT)));
392 392
393 EXPECT_CALL(host_session_event_handler_, 393 EXPECT_CALL(host_session_event_handler_,
394 OnSessionStateChange(Session::ACCEPTED)) 394 OnSessionStateChange(Session::ACCEPTED))
395 .Times(AtMost(1)); 395 .Times(AtMost(1));
396 396
397 EXPECT_CALL(host_session_event_handler_, 397 EXPECT_CALL(host_session_event_handler_,
398 OnSessionStateChange(Session::AUTHENTICATING)) 398 OnSessionStateChange(Session::AUTHENTICATING))
399 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); 399 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession));
400 400
401 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 401 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator(
402 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); 402 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true));
403 403
404 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); 404 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator));
405 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
406 } 406 }
407 407
408 // Verify that we can connect with multistep authentication. 408 // Verify that we can connect with multistep authentication.
409 TEST_F(JingleSessionTest, TestMultistepAuth) { 409 TEST_F(JingleSessionTest, TestMultistepAuth) {
410 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 410 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
411 ASSERT_NO_FATAL_FAILURE( 411 ASSERT_NO_FATAL_FAILURE(
412 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); 412 InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
413 } 413 }
414 414
415 } // namespace protocol 415 } // namespace protocol
416 } // namespace remoting 416 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_session_manager.cc ('k') | remoting/protocol/me2me_host_authenticator_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698