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

Side by Side Diff: webrtc/p2p/base/transport_unittest.cc

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Set media engine on voice channel Created 5 years, 4 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 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/fakesslidentity.h" 11 #include "webrtc/base/fakesslidentity.h"
12 #include "webrtc/base/gunit.h" 12 #include "webrtc/base/gunit.h"
13 #include "webrtc/base/network.h" 13 #include "webrtc/base/network.h"
14 #include "webrtc/base/thread.h" 14 #include "webrtc/p2p/base/faketransportcontroller.h"
15 #include "webrtc/p2p/base/fakesession.h"
16 #include "webrtc/p2p/base/p2ptransport.h" 15 #include "webrtc/p2p/base/p2ptransport.h"
17 16
18 using cricket::Candidate; 17 using cricket::Candidate;
19 using cricket::Candidates; 18 using cricket::Candidates;
20 using cricket::Transport; 19 using cricket::Transport;
21 using cricket::FakeTransport; 20 using cricket::FakeTransport;
22 using cricket::TransportChannel; 21 using cricket::TransportChannel;
23 using cricket::FakeTransportChannel; 22 using cricket::FakeTransportChannel;
24 using cricket::IceRole; 23 using cricket::IceRole;
25 using cricket::TransportDescription; 24 using cricket::TransportDescription;
26 using rtc::SocketAddress; 25 using rtc::SocketAddress;
27 26
28 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; 27 static const char kIceUfrag1[] = "TESTICEUFRAG0001";
29 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; 28 static const char kIcePwd1[] = "TESTICEPWD00000000000001";
30 29
31 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; 30 static const char kIceUfrag2[] = "TESTICEUFRAG0002";
32 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; 31 static const char kIcePwd2[] = "TESTICEPWD00000000000002";
33 32
34 class TransportTest : public testing::Test, 33 class TransportTest : public testing::Test,
35 public sigslot::has_slots<> { 34 public sigslot::has_slots<> {
36 public: 35 public:
37 TransportTest() 36 TransportTest()
38 : thread_(rtc::Thread::Current()), 37 : transport_(new FakeTransport("test content name", NULL)),
39 transport_(new FakeTransport(
40 thread_, thread_, "test content name", NULL)),
41 channel_(NULL), 38 channel_(NULL),
42 connecting_signalled_(false), 39 connecting_signalled_(false),
43 completed_(false), 40 completed_(false),
44 failed_(false) { 41 failed_(false) {
45 transport_->SignalConnecting.connect(this, &TransportTest::OnConnecting); 42 transport_->SignalConnecting.connect(this, &TransportTest::OnConnecting);
46 transport_->SignalCompleted.connect(this, &TransportTest::OnCompleted); 43 transport_->SignalCompleted.connect(this, &TransportTest::OnCompleted);
47 transport_->SignalFailed.connect(this, &TransportTest::OnFailed); 44 transport_->SignalFailed.connect(this, &TransportTest::OnFailed);
48 } 45 }
49 ~TransportTest() { 46 ~TransportTest() {
50 transport_->DestroyAllChannels(); 47 transport_->DestroyAllChannels();
(...skipping 15 matching lines...) Expand all
66 void OnConnecting(Transport* transport) { 63 void OnConnecting(Transport* transport) {
67 connecting_signalled_ = true; 64 connecting_signalled_ = true;
68 } 65 }
69 void OnCompleted(Transport* transport) { 66 void OnCompleted(Transport* transport) {
70 completed_ = true; 67 completed_ = true;
71 } 68 }
72 void OnFailed(Transport* transport) { 69 void OnFailed(Transport* transport) {
73 failed_ = true; 70 failed_ = true;
74 } 71 }
75 72
76 rtc::Thread* thread_;
77 rtc::scoped_ptr<FakeTransport> transport_; 73 rtc::scoped_ptr<FakeTransport> transport_;
78 FakeTransportChannel* channel_; 74 FakeTransportChannel* channel_;
79 bool connecting_signalled_; 75 bool connecting_signalled_;
80 bool completed_; 76 bool completed_;
81 bool failed_; 77 bool failed_;
82 }; 78 };
83 79
84 // Test that calling ConnectChannels triggers an OnConnecting signal. 80 // Test that calling ConnectChannels triggers an OnConnecting signal.
85 TEST_F(TransportTest, TestConnectChannelsDoesSignal) { 81 TEST_F(TransportTest, TestConnectChannelsDoesSignal) {
86 EXPECT_TRUE(SetupChannel()); 82 EXPECT_TRUE(SetupChannel());
87 transport_->ConnectChannels(); 83 transport_->ConnectChannels();
88 EXPECT_FALSE(connecting_signalled_); 84 EXPECT_TRUE(connecting_signalled_);
89
90 EXPECT_TRUE_WAIT(connecting_signalled_, 100);
91 }
92
93 // Test that DestroyAllChannels kills any pending OnConnecting signals.
94 TEST_F(TransportTest, TestDestroyAllClearsPosts) {
95 EXPECT_TRUE(transport_->CreateChannel(1) != NULL);
96
97 transport_->ConnectChannels();
98 transport_->DestroyAllChannels();
99
100 thread_->ProcessMessages(0);
101 EXPECT_FALSE(connecting_signalled_);
102 } 85 }
103 86
104 // This test verifies channels are created with proper ICE 87 // This test verifies channels are created with proper ICE
105 // role, tiebreaker and remote ice mode and credentials after offer and 88 // role, tiebreaker and remote ice mode and credentials after offer and
106 // answer negotiations. 89 // answer negotiations.
107 TEST_F(TransportTest, TestChannelIceParameters) { 90 TEST_F(TransportTest, TestChannelIceParameters) {
108 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); 91 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
109 transport_->SetIceTiebreaker(99U); 92 transport_->SetIceTiebreaker(99U);
110 cricket::TransportDescription local_desc( 93 cricket::TransportDescription local_desc(
111 cricket::NS_JINGLE_ICE_UDP, kIceUfrag1, kIcePwd1); 94 cricket::NS_JINGLE_ICE_UDP, kIceUfrag1, kIcePwd1);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 NULL)); 218 NULL));
236 EXPECT_TRUE(SetupChannel()); 219 EXPECT_TRUE(SetupChannel());
237 220
238 cricket::TransportDescription remote_desc( 221 cricket::TransportDescription remote_desc(
239 cricket::NS_JINGLE_ICE_UDP, kIceUfrag1, kIcePwd1); 222 cricket::NS_JINGLE_ICE_UDP, kIceUfrag1, kIcePwd1);
240 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, 223 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
241 cricket::CA_ANSWER, 224 cricket::CA_ANSWER,
242 NULL)); 225 NULL));
243 226
244 channel_->SetConnectionCount(2); 227 channel_->SetConnectionCount(2);
245 channel_->SignalCandidatesAllocationDone(channel_); 228 channel_->SetCandidatesAllocationDone();
246 channel_->SetWritable(true); 229 channel_->SetWritable(true);
247 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100); 230 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100);
248 // ICE is not yet completed because there is still more than one connection. 231 // ICE is not yet completed because there is still more than one connection.
249 EXPECT_FALSE(completed_); 232 EXPECT_FALSE(completed_);
250 EXPECT_FALSE(failed_); 233 EXPECT_FALSE(failed_);
251 234
252 // When the connection count drops to 1, SignalCompleted should be emitted, 235 // When the connection count drops to 1, SignalCompleted should be emitted,
253 // and completed() should be true. 236 // and completed() should be true.
254 channel_->SetConnectionCount(1); 237 channel_->SetConnectionCount(1);
255 EXPECT_TRUE_WAIT(completed_, 100); 238 EXPECT_TRUE_WAIT(completed_, 100);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); 318 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100);
336 319
337 channel2->SetReceiving(false); 320 channel2->SetReceiving(false);
338 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); 321 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100);
339 322
340 // After both channels become not receiving, the transport receiving state 323 // After both channels become not receiving, the transport receiving state
341 // becomes TRANSPORT_STATE_NONE. 324 // becomes TRANSPORT_STATE_NONE.
342 channel_->SetReceiving(false); 325 channel_->SetReceiving(false);
343 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100); 326 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100);
344 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698