OLD | NEW |
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/p2p/base/faketransportcontroller.h" | 14 #include "webrtc/base/thread.h" |
| 15 #include "webrtc/p2p/base/fakesession.h" |
15 #include "webrtc/p2p/base/p2ptransport.h" | 16 #include "webrtc/p2p/base/p2ptransport.h" |
16 | 17 |
17 using cricket::Candidate; | 18 using cricket::Candidate; |
18 using cricket::Candidates; | 19 using cricket::Candidates; |
19 using cricket::Transport; | 20 using cricket::Transport; |
20 using cricket::FakeTransport; | 21 using cricket::FakeTransport; |
21 using cricket::TransportChannel; | 22 using cricket::TransportChannel; |
22 using cricket::FakeTransportChannel; | 23 using cricket::FakeTransportChannel; |
23 using cricket::IceRole; | 24 using cricket::IceRole; |
24 using cricket::TransportDescription; | 25 using cricket::TransportDescription; |
25 using rtc::SocketAddress; | 26 using rtc::SocketAddress; |
26 | 27 |
27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 28 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 29 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
29 | 30 |
30 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; | 31 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
31 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; | 32 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
32 | 33 |
33 class TransportTest : public testing::Test, | 34 class TransportTest : public testing::Test, |
34 public sigslot::has_slots<> { | 35 public sigslot::has_slots<> { |
35 public: | 36 public: |
36 TransportTest() | 37 TransportTest() |
37 : transport_(new FakeTransport("test content name")), | 38 : thread_(rtc::Thread::Current()), |
| 39 transport_(new FakeTransport( |
| 40 thread_, thread_, "test content name", NULL)), |
38 channel_(NULL), | 41 channel_(NULL), |
39 connecting_signalled_(false), | 42 connecting_signalled_(false), |
40 completed_(false), | 43 completed_(false), |
41 failed_(false) { | 44 failed_(false) { |
42 transport_->SignalConnecting.connect(this, &TransportTest::OnConnecting); | 45 transport_->SignalConnecting.connect(this, &TransportTest::OnConnecting); |
43 transport_->SignalCompleted.connect(this, &TransportTest::OnCompleted); | 46 transport_->SignalCompleted.connect(this, &TransportTest::OnCompleted); |
44 transport_->SignalFailed.connect(this, &TransportTest::OnFailed); | 47 transport_->SignalFailed.connect(this, &TransportTest::OnFailed); |
45 } | 48 } |
46 ~TransportTest() { | 49 ~TransportTest() { |
47 transport_->DestroyAllChannels(); | 50 transport_->DestroyAllChannels(); |
(...skipping 15 matching lines...) Expand all Loading... |
63 void OnConnecting(Transport* transport) { | 66 void OnConnecting(Transport* transport) { |
64 connecting_signalled_ = true; | 67 connecting_signalled_ = true; |
65 } | 68 } |
66 void OnCompleted(Transport* transport) { | 69 void OnCompleted(Transport* transport) { |
67 completed_ = true; | 70 completed_ = true; |
68 } | 71 } |
69 void OnFailed(Transport* transport) { | 72 void OnFailed(Transport* transport) { |
70 failed_ = true; | 73 failed_ = true; |
71 } | 74 } |
72 | 75 |
| 76 rtc::Thread* thread_; |
73 rtc::scoped_ptr<FakeTransport> transport_; | 77 rtc::scoped_ptr<FakeTransport> transport_; |
74 FakeTransportChannel* channel_; | 78 FakeTransportChannel* channel_; |
75 bool connecting_signalled_; | 79 bool connecting_signalled_; |
76 bool completed_; | 80 bool completed_; |
77 bool failed_; | 81 bool failed_; |
78 }; | 82 }; |
79 | 83 |
80 // Test that calling ConnectChannels triggers an OnConnecting signal. | 84 // Test that calling ConnectChannels triggers an OnConnecting signal. |
81 TEST_F(TransportTest, TestConnectChannelsDoesSignal) { | 85 TEST_F(TransportTest, TestConnectChannelsDoesSignal) { |
82 EXPECT_TRUE(SetupChannel()); | 86 EXPECT_TRUE(SetupChannel()); |
83 transport_->ConnectChannels(); | 87 transport_->ConnectChannels(); |
84 EXPECT_TRUE(connecting_signalled_); | 88 EXPECT_FALSE(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_); |
85 } | 102 } |
86 | 103 |
87 // This test verifies channels are created with proper ICE | 104 // This test verifies channels are created with proper ICE |
88 // role, tiebreaker and remote ice mode and credentials after offer and | 105 // role, tiebreaker and remote ice mode and credentials after offer and |
89 // answer negotiations. | 106 // answer negotiations. |
90 TEST_F(TransportTest, TestChannelIceParameters) { | 107 TEST_F(TransportTest, TestChannelIceParameters) { |
91 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 108 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
92 transport_->SetIceTiebreaker(99U); | 109 transport_->SetIceTiebreaker(99U); |
93 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | 110 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); |
94 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, | 111 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 cricket::CA_OFFER, | 225 cricket::CA_OFFER, |
209 NULL)); | 226 NULL)); |
210 EXPECT_TRUE(SetupChannel()); | 227 EXPECT_TRUE(SetupChannel()); |
211 | 228 |
212 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); | 229 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); |
213 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | 230 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, |
214 cricket::CA_ANSWER, | 231 cricket::CA_ANSWER, |
215 NULL)); | 232 NULL)); |
216 | 233 |
217 channel_->SetConnectionCount(2); | 234 channel_->SetConnectionCount(2); |
218 channel_->SetCandidatesGatheringComplete(); | 235 channel_->SignalCandidatesAllocationDone(channel_); |
219 channel_->SetWritable(true); | 236 channel_->SetWritable(true); |
220 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100); | 237 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100); |
221 // ICE is not yet completed because there is still more than one connection. | 238 // ICE is not yet completed because there is still more than one connection. |
222 EXPECT_FALSE(completed_); | 239 EXPECT_FALSE(completed_); |
223 EXPECT_FALSE(failed_); | 240 EXPECT_FALSE(failed_); |
224 | 241 |
225 // When the connection count drops to 1, SignalCompleted should be emitted, | 242 // When the connection count drops to 1, SignalCompleted should be emitted, |
226 // and completed() should be true. | 243 // and completed() should be true. |
227 channel_->SetConnectionCount(1); | 244 channel_->SetConnectionCount(1); |
228 EXPECT_TRUE_WAIT(completed_, 100); | 245 EXPECT_TRUE_WAIT(completed_, 100); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); | 323 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); |
307 | 324 |
308 channel2->SetReceiving(false); | 325 channel2->SetReceiving(false); |
309 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); | 326 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); |
310 | 327 |
311 // After both channels become not receiving, the transport receiving state | 328 // After both channels become not receiving, the transport receiving state |
312 // becomes TRANSPORT_STATE_NONE. | 329 // becomes TRANSPORT_STATE_NONE. |
313 channel_->SetReceiving(false); | 330 channel_->SetReceiving(false); |
314 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100); | 331 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100); |
315 } | 332 } |
OLD | NEW |