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

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

Issue 1413813006: Revert of Add TransportSession interface to prepare for WebRTC-based transport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/channel_multiplexer.h" 5 #include "remoting/protocol/channel_multiplexer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 void DeleteAfterSessionFail() { 67 void DeleteAfterSessionFail() {
68 host_mux_->CancelChannelCreation(kTestChannelName2); 68 host_mux_->CancelChannelCreation(kTestChannelName2);
69 DeleteAll(); 69 DeleteAll();
70 } 70 }
71 71
72 protected: 72 protected:
73 void SetUp() override { 73 void SetUp() override {
74 // Create pair of multiplexers and connect them to each other. 74 // Create pair of multiplexers and connect them to each other.
75 host_mux_.reset(new ChannelMultiplexer( 75 host_mux_.reset(new ChannelMultiplexer(
76 host_session_.GetTransportSession()->GetStreamChannelFactory(), 76 host_session_.GetTransportChannelFactory(), kMuxChannelName));
77 kMuxChannelName));
78 client_mux_.reset(new ChannelMultiplexer( 77 client_mux_.reset(new ChannelMultiplexer(
79 client_session_.GetTransportSession()->GetStreamChannelFactory(), 78 client_session_.GetTransportChannelFactory(), kMuxChannelName));
80 kMuxChannelName));
81 } 79 }
82 80
83 // Connect sockets to each other. Must be called after we've created at least 81 // Connect sockets to each other. Must be called after we've created at least
84 // one channel with each multiplexer. 82 // one channel with each multiplexer.
85 void ConnectSockets() { 83 void ConnectSockets() {
86 FakeStreamSocket* host_socket = 84 FakeStreamSocket* host_socket =
87 host_session_.GetTransportSession() 85 host_session_.fake_channel_factory().GetFakeChannel(
88 ->GetStreamChannelFactory() 86 ChannelMultiplexer::kMuxChannelName);
89 ->GetFakeChannel(ChannelMultiplexer::kMuxChannelName);
90 FakeStreamSocket* client_socket = 87 FakeStreamSocket* client_socket =
91 client_session_.GetTransportSession() 88 client_session_.fake_channel_factory().GetFakeChannel(
92 ->GetStreamChannelFactory() 89 ChannelMultiplexer::kMuxChannelName);
93 ->GetFakeChannel(ChannelMultiplexer::kMuxChannelName);
94 host_socket->PairWith(client_socket); 90 host_socket->PairWith(client_socket);
95 91
96 // Make writes asynchronous in one direction. 92 // Make writes asynchronous in one direction.
97 host_socket->set_async_write(true); 93 host_socket->set_async_write(true);
98 } 94 }
99 95
100 void CreateChannel(const std::string& name, 96 void CreateChannel(const std::string& name,
101 scoped_ptr<P2PStreamSocket>* host_socket, 97 scoped_ptr<P2PStreamSocket>* host_socket,
102 scoped_ptr<P2PStreamSocket>* client_socket) { 98 scoped_ptr<P2PStreamSocket>* client_socket) {
103 int counter = 2; 99 int counter = 2;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ASSERT_NO_FATAL_FAILURE( 238 ASSERT_NO_FATAL_FAILURE(
243 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); 239 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_));
244 240
245 scoped_ptr<P2PStreamSocket> host_socket2_; 241 scoped_ptr<P2PStreamSocket> host_socket2_;
246 scoped_ptr<P2PStreamSocket> client_socket2_; 242 scoped_ptr<P2PStreamSocket> client_socket2_;
247 ASSERT_NO_FATAL_FAILURE( 243 ASSERT_NO_FATAL_FAILURE(
248 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); 244 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
249 245
250 ConnectSockets(); 246 ConnectSockets();
251 247
252 FakeStreamSocket* socket = host_session_.GetTransportSession() 248 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
253 ->GetStreamChannelFactory() 249 set_next_write_error(net::ERR_FAILED);
254 ->GetFakeChannel(kMuxChannelName); 250 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
255 socket->set_next_write_error(net::ERR_FAILED); 251 set_async_write(false);
256 socket->set_async_write(false);
257 252
258 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100); 253 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100);
259 254
260 MockSocketCallback cb1; 255 MockSocketCallback cb1;
261 MockSocketCallback cb2; 256 MockSocketCallback cb2;
262 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED)); 257 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED));
263 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED)); 258 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED));
264 259
265 EXPECT_EQ(net::ERR_IO_PENDING, 260 EXPECT_EQ(net::ERR_IO_PENDING,
266 host_socket1_->Write(buf.get(), 261 host_socket1_->Write(buf.get(),
(...skipping 11 matching lines...) Expand all
278 273
279 TEST_F(ChannelMultiplexerTest, WriteFailAsync) { 274 TEST_F(ChannelMultiplexerTest, WriteFailAsync) {
280 ASSERT_NO_FATAL_FAILURE( 275 ASSERT_NO_FATAL_FAILURE(
281 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); 276 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_));
282 277
283 ASSERT_NO_FATAL_FAILURE( 278 ASSERT_NO_FATAL_FAILURE(
284 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); 279 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
285 280
286 ConnectSockets(); 281 ConnectSockets();
287 282
288 FakeStreamSocket* socket = host_session_.GetTransportSession() 283 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
289 ->GetStreamChannelFactory() 284 set_next_write_error(net::ERR_FAILED);
290 ->GetFakeChannel(kMuxChannelName); 285 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
291 socket->set_next_write_error(net::ERR_FAILED); 286 set_async_write(true);
292 socket->set_async_write(true);
293 287
294 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100); 288 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100);
295 289
296 MockSocketCallback cb1; 290 MockSocketCallback cb1;
297 MockSocketCallback cb2; 291 MockSocketCallback cb2;
298 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED)); 292 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED));
299 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED)); 293 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED));
300 294
301 EXPECT_EQ(net::ERR_IO_PENDING, 295 EXPECT_EQ(net::ERR_IO_PENDING,
302 host_socket1_->Write(buf.get(), 296 host_socket1_->Write(buf.get(),
(...skipping 10 matching lines...) Expand all
313 } 307 }
314 308
315 TEST_F(ChannelMultiplexerTest, DeleteWhenFailed) { 309 TEST_F(ChannelMultiplexerTest, DeleteWhenFailed) {
316 ASSERT_NO_FATAL_FAILURE( 310 ASSERT_NO_FATAL_FAILURE(
317 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); 311 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_));
318 ASSERT_NO_FATAL_FAILURE( 312 ASSERT_NO_FATAL_FAILURE(
319 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); 313 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
320 314
321 ConnectSockets(); 315 ConnectSockets();
322 316
323 FakeStreamSocket* socket = host_session_.GetTransportSession() 317 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
324 ->GetStreamChannelFactory() 318 set_next_write_error(net::ERR_FAILED);
325 ->GetFakeChannel(kMuxChannelName); 319 host_session_.fake_channel_factory().GetFakeChannel(kMuxChannelName)->
326 socket->set_next_write_error(net::ERR_FAILED); 320 set_async_write(true);
327 socket->set_async_write(true);
328 321
329 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100); 322 scoped_refptr<net::IOBufferWithSize> buf = CreateTestBuffer(100);
330 323
331 MockSocketCallback cb1; 324 MockSocketCallback cb1;
332 MockSocketCallback cb2; 325 MockSocketCallback cb2;
333 326
334 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED)) 327 EXPECT_CALL(cb1, OnDone(net::ERR_FAILED))
335 .Times(AtMost(1)) 328 .Times(AtMost(1))
336 .WillOnce(InvokeWithoutArgs(this, &ChannelMultiplexerTest::DeleteAll)); 329 .WillOnce(InvokeWithoutArgs(this, &ChannelMultiplexerTest::DeleteAll));
337 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED)) 330 EXPECT_CALL(cb2, OnDone(net::ERR_FAILED))
(...skipping 11 matching lines...) Expand all
349 base::Bind(&MockSocketCallback::OnDone, 342 base::Bind(&MockSocketCallback::OnDone,
350 base::Unretained(&cb2)))); 343 base::Unretained(&cb2))));
351 344
352 base::RunLoop().RunUntilIdle(); 345 base::RunLoop().RunUntilIdle();
353 346
354 // Check that the sockets were destroyed. 347 // Check that the sockets were destroyed.
355 EXPECT_FALSE(host_mux_.get()); 348 EXPECT_FALSE(host_mux_.get());
356 } 349 }
357 350
358 TEST_F(ChannelMultiplexerTest, SessionFail) { 351 TEST_F(ChannelMultiplexerTest, SessionFail) {
359 host_session_.GetTransportSession()->GetStreamChannelFactory() 352 host_session_.fake_channel_factory().set_asynchronous_create(true);
360 ->set_asynchronous_create(true); 353 host_session_.fake_channel_factory().set_fail_create(true);
361 host_session_.GetTransportSession()->GetStreamChannelFactory()
362 ->set_fail_create(true);
363 354
364 MockConnectCallback cb1; 355 MockConnectCallback cb1;
365 MockConnectCallback cb2; 356 MockConnectCallback cb2;
366 357
367 host_mux_->CreateChannel(kTestChannelName, base::Bind( 358 host_mux_->CreateChannel(kTestChannelName, base::Bind(
368 &MockConnectCallback::OnConnected, base::Unretained(&cb1))); 359 &MockConnectCallback::OnConnected, base::Unretained(&cb1)));
369 host_mux_->CreateChannel(kTestChannelName2, base::Bind( 360 host_mux_->CreateChannel(kTestChannelName2, base::Bind(
370 &MockConnectCallback::OnConnected, base::Unretained(&cb2))); 361 &MockConnectCallback::OnConnected, base::Unretained(&cb2)));
371 362
372 EXPECT_CALL(cb1, OnConnectedPtr(nullptr)) 363 EXPECT_CALL(cb1, OnConnectedPtr(nullptr))
373 .Times(AtMost(1)) 364 .Times(AtMost(1))
374 .WillOnce(InvokeWithoutArgs( 365 .WillOnce(InvokeWithoutArgs(
375 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); 366 this, &ChannelMultiplexerTest::DeleteAfterSessionFail));
376 EXPECT_CALL(cb2, OnConnectedPtr(_)) 367 EXPECT_CALL(cb2, OnConnectedPtr(_))
377 .Times(0); 368 .Times(0);
378 369
379 base::RunLoop().RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
380 } 371 }
381 372
382 } // namespace protocol 373 } // namespace protocol
383 } // namespace remoting 374 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/channel_dispatcher_base.cc ('k') | remoting/protocol/client_video_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698