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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
29 | 29 |
30 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; | 30 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
31 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; | 31 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
32 | 32 |
33 class TransportTest : public testing::Test, | 33 class TransportTest : public testing::Test, |
34 public sigslot::has_slots<> { | 34 public sigslot::has_slots<> { |
35 public: | 35 public: |
36 TransportTest() | 36 TransportTest() |
37 : transport_(new FakeTransport("test content name")), | 37 : transport_(new FakeTransport("test content name")), channel_(NULL) {} |
38 channel_(NULL), | |
39 connecting_signalled_(false), | |
40 completed_(false), | |
41 failed_(false) { | |
42 transport_->SignalConnecting.connect(this, &TransportTest::OnConnecting); | |
43 transport_->SignalCompleted.connect(this, &TransportTest::OnCompleted); | |
44 transport_->SignalFailed.connect(this, &TransportTest::OnFailed); | |
45 } | |
46 ~TransportTest() { | 38 ~TransportTest() { |
47 transport_->DestroyAllChannels(); | 39 transport_->DestroyAllChannels(); |
48 } | 40 } |
49 bool SetupChannel() { | 41 bool SetupChannel() { |
50 channel_ = CreateChannel(1); | 42 channel_ = CreateChannel(1); |
51 return (channel_ != NULL); | 43 return (channel_ != NULL); |
52 } | 44 } |
53 FakeTransportChannel* CreateChannel(int component) { | 45 FakeTransportChannel* CreateChannel(int component) { |
54 return static_cast<FakeTransportChannel*>( | 46 return static_cast<FakeTransportChannel*>( |
55 transport_->CreateChannel(component)); | 47 transport_->CreateChannel(component)); |
56 } | 48 } |
57 void DestroyChannel() { | 49 void DestroyChannel() { |
58 transport_->DestroyChannel(1); | 50 transport_->DestroyChannel(1); |
59 channel_ = NULL; | 51 channel_ = NULL; |
60 } | 52 } |
61 | 53 |
62 protected: | 54 protected: |
63 void OnConnecting(Transport* transport) { | |
64 connecting_signalled_ = true; | |
65 } | |
66 void OnCompleted(Transport* transport) { | |
67 completed_ = true; | |
68 } | |
69 void OnFailed(Transport* transport) { | |
70 failed_ = true; | |
71 } | |
72 | |
73 rtc::scoped_ptr<FakeTransport> transport_; | 55 rtc::scoped_ptr<FakeTransport> transport_; |
74 FakeTransportChannel* channel_; | 56 FakeTransportChannel* channel_; |
75 bool connecting_signalled_; | |
76 bool completed_; | |
77 bool failed_; | |
78 }; | 57 }; |
79 | 58 |
80 // Test that calling ConnectChannels triggers an OnConnecting signal. | |
81 TEST_F(TransportTest, TestConnectChannelsDoesSignal) { | |
82 EXPECT_TRUE(SetupChannel()); | |
83 transport_->ConnectChannels(); | |
84 EXPECT_TRUE(connecting_signalled_); | |
85 } | |
86 | |
87 // This test verifies channels are created with proper ICE | 59 // This test verifies channels are created with proper ICE |
88 // role, tiebreaker and remote ice mode and credentials after offer and | 60 // role, tiebreaker and remote ice mode and credentials after offer and |
89 // answer negotiations. | 61 // answer negotiations. |
90 TEST_F(TransportTest, TestChannelIceParameters) { | 62 TEST_F(TransportTest, TestChannelIceParameters) { |
91 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 63 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
92 transport_->SetIceTiebreaker(99U); | 64 transport_->SetIceTiebreaker(99U); |
93 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | 65 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); |
94 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, | 66 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, |
95 cricket::CA_OFFER, | 67 cricket::CA_OFFER, |
96 NULL)); | 68 NULL)); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 165 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
194 | 166 |
195 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2); | 167 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2); |
196 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc, | 168 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc, |
197 cricket::CA_ANSWER, | 169 cricket::CA_ANSWER, |
198 NULL)); | 170 NULL)); |
199 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 171 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
200 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); | 172 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); |
201 } | 173 } |
202 | 174 |
203 // This test verifies that the Completed and Failed states can be reached. | |
204 TEST_F(TransportTest, TestChannelCompletedAndFailed) { | |
205 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
206 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | |
207 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, | |
208 cricket::CA_OFFER, | |
209 NULL)); | |
210 EXPECT_TRUE(SetupChannel()); | |
211 | |
212 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); | |
213 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | |
214 cricket::CA_ANSWER, | |
215 NULL)); | |
216 | |
217 channel_->SetConnectionCount(2); | |
218 channel_->SetCandidatesGatheringComplete(); | |
219 channel_->SetWritable(true); | |
220 EXPECT_TRUE_WAIT(transport_->all_channels_writable(), 100); | |
221 // ICE is not yet completed because there is still more than one connection. | |
222 EXPECT_FALSE(completed_); | |
223 EXPECT_FALSE(failed_); | |
224 | |
225 // When the connection count drops to 1, SignalCompleted should be emitted, | |
226 // and completed() should be true. | |
227 channel_->SetConnectionCount(1); | |
228 EXPECT_TRUE_WAIT(completed_, 100); | |
229 completed_ = false; | |
230 | |
231 // When the connection count drops to 0, SignalFailed should be emitted, and | |
232 // completed() should be false. | |
233 channel_->SetConnectionCount(0); | |
234 EXPECT_TRUE_WAIT(failed_, 100); | |
235 EXPECT_FALSE(completed_); | |
236 } | |
237 | |
238 // Tests channel role is reversed after receiving ice-lite from remote. | 175 // Tests channel role is reversed after receiving ice-lite from remote. |
239 TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { | 176 TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { |
240 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 177 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
241 cricket::TransportDescription remote_desc( | 178 cricket::TransportDescription remote_desc( |
242 std::vector<std::string>(), | 179 std::vector<std::string>(), |
243 kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, | 180 kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, |
244 cricket::CONNECTIONROLE_ACTPASS, NULL, cricket::Candidates()); | 181 cricket::CONNECTIONROLE_ACTPASS, NULL, cricket::Candidates()); |
245 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | 182 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, |
246 cricket::CA_OFFER, | 183 cricket::CA_OFFER, |
247 NULL)); | 184 NULL)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 EXPECT_TRUE(transport_->GetStats(&stats)); | 223 EXPECT_TRUE(transport_->GetStats(&stats)); |
287 // Note that this tests the behavior of a FakeTransportChannel. | 224 // Note that this tests the behavior of a FakeTransportChannel. |
288 ASSERT_EQ(1U, stats.channel_stats.size()); | 225 ASSERT_EQ(1U, stats.channel_stats.size()); |
289 EXPECT_EQ(1, stats.channel_stats[0].component); | 226 EXPECT_EQ(1, stats.channel_stats[0].component); |
290 transport_->ConnectChannels(); | 227 transport_->ConnectChannels(); |
291 EXPECT_TRUE(transport_->GetStats(&stats)); | 228 EXPECT_TRUE(transport_->GetStats(&stats)); |
292 ASSERT_EQ(1U, stats.channel_stats.size()); | 229 ASSERT_EQ(1U, stats.channel_stats.size()); |
293 EXPECT_EQ(1, stats.channel_stats[0].component); | 230 EXPECT_EQ(1, stats.channel_stats[0].component); |
294 } | 231 } |
295 | 232 |
296 TEST_F(TransportTest, TestReceivingStateChange) { | |
297 ASSERT_TRUE(SetupChannel()); | |
298 channel_->SetConnectionCount(1); | |
299 transport_->ConnectChannels(); | |
300 EXPECT_FALSE(transport_->any_channel_receiving()); | |
301 | |
302 channel_->SetReceiving(true); | |
303 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); | |
304 FakeTransportChannel* channel2 = CreateChannel(2); | |
305 channel2->SetReceiving(true); | |
306 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); | |
307 | |
308 channel2->SetReceiving(false); | |
309 EXPECT_TRUE_WAIT(transport_->any_channel_receiving(), 100); | |
310 | |
311 // After both channels become not receiving, the transport receiving state | |
312 // becomes TRANSPORT_STATE_NONE. | |
313 channel_->SetReceiving(false); | |
314 EXPECT_TRUE_WAIT(!transport_->any_channel_receiving(), 100); | |
315 } | |
OLD | NEW |