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

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

Issue 1350523003: TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Mac test. Created 5 years, 3 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
« no previous file with comments | « webrtc/p2p/base/transport.cc ('k') | webrtc/p2p/base/transportchannel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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")),
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(kIceUfrag1, kIcePwd1); 93 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1);
111 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, 94 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 cricket::CA_OFFER, 208 cricket::CA_OFFER,
226 NULL)); 209 NULL));
227 EXPECT_TRUE(SetupChannel()); 210 EXPECT_TRUE(SetupChannel());
228 211
229 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); 212 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1);
230 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, 213 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
231 cricket::CA_ANSWER, 214 cricket::CA_ANSWER,
232 NULL)); 215 NULL));
233 216
234 channel_->SetConnectionCount(2); 217 channel_->SetConnectionCount(2);
235 channel_->SignalCandidatesAllocationDone(channel_); 218 channel_->SetCandidatesGatheringComplete();
236 channel_->SetWritable(true); 219 channel_->SetWritable(true);
237 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100); 220 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100);
238 // ICE is not yet completed because there is still more than one connection. 221 // ICE is not yet completed because there is still more than one connection.
239 EXPECT_FALSE(completed_); 222 EXPECT_FALSE(completed_);
240 EXPECT_FALSE(failed_); 223 EXPECT_FALSE(failed_);
241 224
242 // When the connection count drops to 1, SignalCompleted should be emitted, 225 // When the connection count drops to 1, SignalCompleted should be emitted,
243 // and completed() should be true. 226 // and completed() should be true.
244 channel_->SetConnectionCount(1); 227 channel_->SetConnectionCount(1);
245 EXPECT_TRUE_WAIT(completed_, 100); 228 EXPECT_TRUE_WAIT(completed_, 100);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); 306 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100);
324 307
325 channel2->SetReceiving(false); 308 channel2->SetReceiving(false);
326 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); 309 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100);
327 310
328 // After both channels become not receiving, the transport receiving state 311 // After both channels become not receiving, the transport receiving state
329 // becomes TRANSPORT_STATE_NONE. 312 // becomes TRANSPORT_STATE_NONE.
330 channel_->SetReceiving(false); 313 channel_->SetReceiving(false);
331 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100); 314 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100);
332 } 315 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transport.cc ('k') | webrtc/p2p/base/transportchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698