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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the memory leak. Created 3 years, 11 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/transportcontroller.cc ('k') | webrtc/p2p/base/udptransport.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 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 transport_controller_->SignalConnectionState.connect( 64 transport_controller_->SignalConnectionState.connect(
65 this, &TransportControllerTest::OnConnectionState); 65 this, &TransportControllerTest::OnConnectionState);
66 transport_controller_->SignalReceiving.connect( 66 transport_controller_->SignalReceiving.connect(
67 this, &TransportControllerTest::OnReceiving); 67 this, &TransportControllerTest::OnReceiving);
68 transport_controller_->SignalGatheringState.connect( 68 transport_controller_->SignalGatheringState.connect(
69 this, &TransportControllerTest::OnGatheringState); 69 this, &TransportControllerTest::OnGatheringState);
70 transport_controller_->SignalCandidatesGathered.connect( 70 transport_controller_->SignalCandidatesGathered.connect(
71 this, &TransportControllerTest::OnCandidatesGathered); 71 this, &TransportControllerTest::OnCandidatesGathered);
72 } 72 }
73 73
74 FakeTransportChannel* CreateChannel(const std::string& content, 74 FakeDtlsTransport* CreateChannel(const std::string& content, int component) {
75 int component) { 75 DtlsTransportInternal* channel =
76 TransportChannel* channel = 76 transport_controller_->CreateDtlsTransport_n(content, component);
77 transport_controller_->CreateTransportChannel_n(content, component); 77 return static_cast<FakeDtlsTransport*>(channel);
78 return static_cast<FakeTransportChannel*>(channel);
79 } 78 }
80 79
81 void DestroyChannel(const std::string& content, int component) { 80 void DestroyChannel(const std::string& content, int component) {
82 transport_controller_->DestroyTransportChannel_n(content, component); 81 transport_controller_->DestroyDtlsTransport_n(content, component);
83 } 82 }
84 83
85 Candidate CreateCandidate(int component) { 84 Candidate CreateCandidate(int component) {
86 Candidate c; 85 Candidate c;
87 c.set_address(rtc::SocketAddress("192.168.1.1", 8000)); 86 c.set_address(rtc::SocketAddress("192.168.1.1", 8000));
88 c.set_component(1); 87 c.set_component(1);
89 c.set_protocol(UDP_PROTOCOL_NAME); 88 c.set_protocol(UDP_PROTOCOL_NAME);
90 c.set_priority(1); 89 c.set_priority(1);
91 return c; 90 return c;
92 } 91 }
93 92
94 // Used for thread hopping test. 93 // Used for thread hopping test.
95 void CreateChannelsAndCompleteConnectionOnNetworkThread() { 94 void CreateChannelsAndCompleteConnectionOnNetworkThread() {
96 network_thread_->Invoke<void>( 95 network_thread_->Invoke<void>(
97 RTC_FROM_HERE, 96 RTC_FROM_HERE,
98 rtc::Bind( 97 rtc::Bind(
99 &TransportControllerTest::CreateChannelsAndCompleteConnection_w, 98 &TransportControllerTest::CreateChannelsAndCompleteConnection_w,
100 this)); 99 this));
101 } 100 }
102 101
103 void CreateChannelsAndCompleteConnection_w() { 102 void CreateChannelsAndCompleteConnection_w() {
104 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 103 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
105 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 104 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
106 ASSERT_NE(nullptr, channel1); 105 ASSERT_NE(nullptr, channel1);
107 FakeTransportChannel* channel2 = CreateChannel("video", 1); 106 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
108 ASSERT_NE(nullptr, channel2); 107 ASSERT_NE(nullptr, channel2);
109 108
110 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, 109 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1,
111 kIcePwd1, ICEMODE_FULL, 110 kIcePwd1, ICEMODE_FULL,
112 CONNECTIONROLE_ACTPASS, nullptr); 111 CONNECTIONROLE_ACTPASS, nullptr);
113 std::string err; 112 std::string err;
114 transport_controller_->SetLocalTransportDescription("audio", local_desc, 113 transport_controller_->SetLocalTransportDescription("audio", local_desc,
115 CA_OFFER, &err); 114 CA_OFFER, &err);
116 transport_controller_->SetLocalTransportDescription("video", local_desc, 115 transport_controller_->SetLocalTransportDescription("video", local_desc,
117 CA_OFFER, &err); 116 CA_OFFER, &err);
118 transport_controller_->MaybeStartGathering(); 117 transport_controller_->MaybeStartGathering();
119 channel1->SignalCandidateGathered(channel1, CreateCandidate(1)); 118 channel1->ice_transport()->SignalCandidateGathered(
120 channel2->SignalCandidateGathered(channel2, CreateCandidate(1)); 119 channel1->ice_transport(), CreateCandidate(1));
120 channel2->ice_transport()->SignalCandidateGathered(
121 channel2->ice_transport(), CreateCandidate(1));
121 channel1->SetCandidatesGatheringComplete(); 122 channel1->SetCandidatesGatheringComplete();
122 channel2->SetCandidatesGatheringComplete(); 123 channel2->SetCandidatesGatheringComplete();
123 channel1->SetConnectionCount(2); 124 channel1->SetConnectionCount(2);
124 channel2->SetConnectionCount(2); 125 channel2->SetConnectionCount(2);
125 channel1->SetReceiving(true); 126 channel1->SetReceiving(true);
126 channel2->SetReceiving(true); 127 channel2->SetReceiving(true);
127 channel1->SetWritable(true); 128 channel1->SetWritable(true);
128 channel2->SetWritable(true); 129 channel2->SetWritable(true);
129 channel1->SetConnectionCount(1); 130 channel1->SetConnectionCount(1);
130 channel2->SetConnectionCount(1); 131 channel2->SetConnectionCount(1);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 int receiving_signal_count_ = 0; 189 int receiving_signal_count_ = 0;
189 int gathering_state_signal_count_ = 0; 190 int gathering_state_signal_count_ = 0;
190 int candidates_signal_count_ = 0; 191 int candidates_signal_count_ = 0;
191 192
192 // Used to make sure signals only come on signaling thread. 193 // Used to make sure signals only come on signaling thread.
193 rtc::Thread* const signaling_thread_ = nullptr; 194 rtc::Thread* const signaling_thread_ = nullptr;
194 bool signaled_on_non_signaling_thread_ = false; 195 bool signaled_on_non_signaling_thread_ = false;
195 }; 196 };
196 197
197 TEST_F(TransportControllerTest, TestSetIceConfig) { 198 TEST_F(TransportControllerTest, TestSetIceConfig) {
198 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 199 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
199 ASSERT_NE(nullptr, channel1); 200 ASSERT_NE(nullptr, channel1);
200 201
201 transport_controller_->SetIceConfig( 202 transport_controller_->SetIceConfig(
202 CreateIceConfig(1000, GATHER_CONTINUALLY)); 203 CreateIceConfig(1000, GATHER_CONTINUALLY));
203 EXPECT_EQ(1000, channel1->receiving_timeout()); 204 EXPECT_EQ(1000, channel1->receiving_timeout());
204 EXPECT_TRUE(channel1->gather_continually()); 205 EXPECT_TRUE(channel1->gather_continually());
205 206
206 transport_controller_->SetIceConfig( 207 transport_controller_->SetIceConfig(
207 CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER)); 208 CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER));
208 // Test that value stored in controller is applied to new channels. 209 // Test that value stored in controller is applied to new channels.
209 FakeTransportChannel* channel2 = CreateChannel("video", 1); 210 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
210 ASSERT_NE(nullptr, channel2); 211 ASSERT_NE(nullptr, channel2);
211 EXPECT_EQ(1000, channel2->receiving_timeout()); 212 EXPECT_EQ(1000, channel2->receiving_timeout());
212 EXPECT_TRUE(channel2->gather_continually()); 213 EXPECT_TRUE(channel2->gather_continually());
213 } 214 }
214 215
215 TEST_F(TransportControllerTest, TestSetSslMaxProtocolVersion) { 216 TEST_F(TransportControllerTest, TestSetSslMaxProtocolVersion) {
216 EXPECT_TRUE(transport_controller_->SetSslMaxProtocolVersion( 217 EXPECT_TRUE(transport_controller_->SetSslMaxProtocolVersion(
217 rtc::SSL_PROTOCOL_DTLS_12)); 218 rtc::SSL_PROTOCOL_DTLS_12));
218 FakeTransportChannel* channel = CreateChannel("audio", 1); 219 FakeDtlsTransport* channel = CreateChannel("audio", 1);
219 220
220 ASSERT_NE(nullptr, channel); 221 ASSERT_NE(nullptr, channel);
221 EXPECT_EQ(rtc::SSL_PROTOCOL_DTLS_12, channel->ssl_max_protocol_version()); 222 EXPECT_EQ(rtc::SSL_PROTOCOL_DTLS_12, channel->ssl_max_protocol_version());
222 223
223 // Setting max version after transport is created should fail. 224 // Setting max version after transport is created should fail.
224 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion( 225 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion(
225 rtc::SSL_PROTOCOL_DTLS_10)); 226 rtc::SSL_PROTOCOL_DTLS_10));
226 } 227 }
227 228
228 TEST_F(TransportControllerTest, TestSetIceRole) { 229 TEST_F(TransportControllerTest, TestSetIceRole) {
229 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 230 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
230 ASSERT_NE(nullptr, channel1); 231 ASSERT_NE(nullptr, channel1);
231 232
232 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 233 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
233 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); 234 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole());
234 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); 235 transport_controller_->SetIceRole(ICEROLE_CONTROLLED);
235 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); 236 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole());
236 237
237 // Test that value stored in controller is applied to new channels. 238 // Test that value stored in controller is applied to new channels.
238 FakeTransportChannel* channel2 = CreateChannel("video", 1); 239 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
239 ASSERT_NE(nullptr, channel2); 240 ASSERT_NE(nullptr, channel2);
240 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); 241 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole());
241 } 242 }
242 243
243 // Test that when one channel encounters a role conflict, the ICE role is 244 // Test that when one channel encounters a role conflict, the ICE role is
244 // swapped on every channel. 245 // swapped on every channel.
245 TEST_F(TransportControllerTest, TestIceRoleConflict) { 246 TEST_F(TransportControllerTest, TestIceRoleConflict) {
246 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 247 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
247 ASSERT_NE(nullptr, channel1); 248 ASSERT_NE(nullptr, channel1);
248 FakeTransportChannel* channel2 = CreateChannel("video", 1); 249 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
249 ASSERT_NE(nullptr, channel2); 250 ASSERT_NE(nullptr, channel2);
250 251
251 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 252 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
252 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); 253 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole());
253 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); 254 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole());
254 255
255 channel1->SignalRoleConflict(channel1); 256 channel1->ice_transport()->SignalRoleConflict(channel1->ice_transport());
256 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); 257 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole());
257 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); 258 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole());
258 259
259 // Should be able to handle a second role conflict. The remote endpoint can 260 // Should be able to handle a second role conflict. The remote endpoint can
260 // change its role/tie-breaker when it does an ICE restart. 261 // change its role/tie-breaker when it does an ICE restart.
261 channel2->SignalRoleConflict(channel2); 262 channel2->ice_transport()->SignalRoleConflict(channel2->ice_transport());
262 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); 263 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole());
263 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); 264 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole());
264 } 265 }
265 266
266 TEST_F(TransportControllerTest, TestGetSslRole) { 267 TEST_F(TransportControllerTest, TestGetSslRole) {
267 FakeTransportChannel* channel = CreateChannel("audio", 1); 268 FakeDtlsTransport* channel = CreateChannel("audio", 1);
268 ASSERT_NE(nullptr, channel); 269 ASSERT_NE(nullptr, channel);
269 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT)); 270 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT));
270 rtc::SSLRole role; 271 rtc::SSLRole role;
271 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role)); 272 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role));
272 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role)); 273 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role));
273 EXPECT_EQ(rtc::SSL_CLIENT, role); 274 EXPECT_EQ(rtc::SSL_CLIENT, role);
274 } 275 }
275 276
276 TEST_F(TransportControllerTest, TestSetAndGetLocalCertificate) { 277 TEST_F(TransportControllerTest, TestSetAndGetLocalCertificate) {
277 rtc::scoped_refptr<rtc::RTCCertificate> certificate1 = 278 rtc::scoped_refptr<rtc::RTCCertificate> certificate1 =
278 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( 279 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
279 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))); 280 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)));
280 rtc::scoped_refptr<rtc::RTCCertificate> certificate2 = 281 rtc::scoped_refptr<rtc::RTCCertificate> certificate2 =
281 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( 282 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
282 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))); 283 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)));
283 rtc::scoped_refptr<rtc::RTCCertificate> returned_certificate; 284 rtc::scoped_refptr<rtc::RTCCertificate> returned_certificate;
284 285
285 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 286 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
286 ASSERT_NE(nullptr, channel1); 287 ASSERT_NE(nullptr, channel1);
287 288
288 EXPECT_TRUE(transport_controller_->SetLocalCertificate(certificate1)); 289 EXPECT_TRUE(transport_controller_->SetLocalCertificate(certificate1));
289 EXPECT_TRUE(transport_controller_->GetLocalCertificate( 290 EXPECT_TRUE(transport_controller_->GetLocalCertificate(
290 "audio", &returned_certificate)); 291 "audio", &returned_certificate));
291 EXPECT_EQ(certificate1->identity()->certificate().ToPEMString(), 292 EXPECT_EQ(certificate1->identity()->certificate().ToPEMString(),
292 returned_certificate->identity()->certificate().ToPEMString()); 293 returned_certificate->identity()->certificate().ToPEMString());
293 294
294 // Should fail if called for a nonexistant transport. 295 // Should fail if called for a nonexistant transport.
295 EXPECT_FALSE(transport_controller_->GetLocalCertificate( 296 EXPECT_FALSE(transport_controller_->GetLocalCertificate(
296 "video", &returned_certificate)); 297 "video", &returned_certificate));
297 298
298 // Test that identity stored in controller is applied to new channels. 299 // Test that identity stored in controller is applied to new channels.
299 FakeTransportChannel* channel2 = CreateChannel("video", 1); 300 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
300 ASSERT_NE(nullptr, channel2); 301 ASSERT_NE(nullptr, channel2);
301 EXPECT_TRUE(transport_controller_->GetLocalCertificate( 302 EXPECT_TRUE(transport_controller_->GetLocalCertificate(
302 "video", &returned_certificate)); 303 "video", &returned_certificate));
303 EXPECT_EQ(certificate1->identity()->certificate().ToPEMString(), 304 EXPECT_EQ(certificate1->identity()->certificate().ToPEMString(),
304 returned_certificate->identity()->certificate().ToPEMString()); 305 returned_certificate->identity()->certificate().ToPEMString());
305 306
306 // Shouldn't be able to change the identity once set. 307 // Shouldn't be able to change the identity once set.
307 EXPECT_FALSE(transport_controller_->SetLocalCertificate(certificate2)); 308 EXPECT_FALSE(transport_controller_->SetLocalCertificate(certificate2));
308 } 309 }
309 310
310 TEST_F(TransportControllerTest, TestGetRemoteSSLCertificate) { 311 TEST_F(TransportControllerTest, TestGetRemoteSSLCertificate) {
311 rtc::FakeSSLCertificate fake_certificate("fake_data"); 312 rtc::FakeSSLCertificate fake_certificate("fake_data");
312 313
313 FakeTransportChannel* channel = CreateChannel("audio", 1); 314 FakeDtlsTransport* channel = CreateChannel("audio", 1);
314 ASSERT_NE(nullptr, channel); 315 ASSERT_NE(nullptr, channel);
315 316
316 channel->SetRemoteSSLCertificate(&fake_certificate); 317 channel->SetRemoteSSLCertificate(&fake_certificate);
317 std::unique_ptr<rtc::SSLCertificate> returned_certificate = 318 std::unique_ptr<rtc::SSLCertificate> returned_certificate =
318 transport_controller_->GetRemoteSSLCertificate("audio"); 319 transport_controller_->GetRemoteSSLCertificate("audio");
319 EXPECT_TRUE(returned_certificate); 320 EXPECT_TRUE(returned_certificate);
320 EXPECT_EQ(fake_certificate.ToPEMString(), 321 EXPECT_EQ(fake_certificate.ToPEMString(),
321 returned_certificate->ToPEMString()); 322 returned_certificate->ToPEMString());
322 323
323 // Should fail if called for a nonexistant transport. 324 // Should fail if called for a nonexistant transport.
324 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video")); 325 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video"));
325 } 326 }
326 327
327 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) { 328 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) {
328 FakeTransportChannel* channel = CreateChannel("audio", 1); 329 FakeDtlsTransport* channel = CreateChannel("audio", 1);
329 ASSERT_NE(nullptr, channel); 330 ASSERT_NE(nullptr, channel);
330 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, 331 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1,
331 kIcePwd1, ICEMODE_FULL, 332 kIcePwd1, ICEMODE_FULL,
332 CONNECTIONROLE_ACTPASS, nullptr); 333 CONNECTIONROLE_ACTPASS, nullptr);
333 std::string err; 334 std::string err;
334 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( 335 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription(
335 "audio", local_desc, CA_OFFER, &err)); 336 "audio", local_desc, CA_OFFER, &err));
336 // Check that ICE ufrag and pwd were propagated to channel. 337 // Check that ICE ufrag and pwd were propagated to channel.
337 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag()); 338 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag());
338 EXPECT_EQ(kIcePwd1, channel->ice_pwd()); 339 EXPECT_EQ(kIcePwd1, channel->ice_pwd());
339 // After setting local description, we should be able to start gathering 340 // After setting local description, we should be able to start gathering
340 // candidates. 341 // candidates.
341 transport_controller_->MaybeStartGathering(); 342 transport_controller_->MaybeStartGathering();
342 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); 343 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout);
343 EXPECT_EQ(1, gathering_state_signal_count_); 344 EXPECT_EQ(1, gathering_state_signal_count_);
344 } 345 }
345 346
346 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) { 347 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) {
347 FakeTransportChannel* channel = CreateChannel("audio", 1); 348 FakeDtlsTransport* channel = CreateChannel("audio", 1);
348 ASSERT_NE(nullptr, channel); 349 ASSERT_NE(nullptr, channel);
349 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, 350 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1,
350 kIcePwd1, ICEMODE_FULL, 351 kIcePwd1, ICEMODE_FULL,
351 CONNECTIONROLE_ACTPASS, nullptr); 352 CONNECTIONROLE_ACTPASS, nullptr);
352 std::string err; 353 std::string err;
353 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( 354 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription(
354 "audio", remote_desc, CA_OFFER, &err)); 355 "audio", remote_desc, CA_OFFER, &err));
355 // Check that ICE ufrag and pwd were propagated to channel. 356 // Check that ICE ufrag and pwd were propagated to channel.
356 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag()); 357 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag());
357 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd()); 358 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd());
358 } 359 }
359 360
360 TEST_F(TransportControllerTest, TestAddRemoteCandidates) { 361 TEST_F(TransportControllerTest, TestAddRemoteCandidates) {
361 FakeTransportChannel* channel = CreateChannel("audio", 1); 362 FakeDtlsTransport* channel = CreateChannel("audio", 1);
362 ASSERT_NE(nullptr, channel); 363 ASSERT_NE(nullptr, channel);
363 Candidates candidates; 364 Candidates candidates;
364 candidates.push_back(CreateCandidate(1)); 365 candidates.push_back(CreateCandidate(1));
365 std::string err; 366 std::string err;
366 EXPECT_TRUE( 367 EXPECT_TRUE(
367 transport_controller_->AddRemoteCandidates("audio", candidates, &err)); 368 transport_controller_->AddRemoteCandidates("audio", candidates, &err));
368 EXPECT_EQ(1U, channel->remote_candidates().size()); 369 EXPECT_EQ(1U, channel->remote_candidates().size());
369 } 370 }
370 371
371 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) { 372 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) {
372 FakeTransportChannel* channel = CreateChannel("audio", 1); 373 FakeDtlsTransport* channel = CreateChannel("audio", 1);
373 ASSERT_NE(nullptr, channel); 374 ASSERT_NE(nullptr, channel);
374 // We expect to be ready for remote candidates only after local and remote 375 // We expect to be ready for remote candidates only after local and remote
375 // descriptions are set. 376 // descriptions are set.
376 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); 377 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio"));
377 378
378 std::string err; 379 std::string err;
379 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, 380 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1,
380 kIcePwd1, ICEMODE_FULL, 381 kIcePwd1, ICEMODE_FULL,
381 CONNECTIONROLE_ACTPASS, nullptr); 382 CONNECTIONROLE_ACTPASS, nullptr);
382 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( 383 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription(
383 "audio", remote_desc, CA_OFFER, &err)); 384 "audio", remote_desc, CA_OFFER, &err));
384 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); 385 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio"));
385 386
386 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, 387 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2,
387 kIcePwd2, ICEMODE_FULL, 388 kIcePwd2, ICEMODE_FULL,
388 CONNECTIONROLE_ACTPASS, nullptr); 389 CONNECTIONROLE_ACTPASS, nullptr);
389 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( 390 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription(
390 "audio", local_desc, CA_ANSWER, &err)); 391 "audio", local_desc, CA_ANSWER, &err));
391 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio")); 392 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio"));
392 } 393 }
393 394
394 TEST_F(TransportControllerTest, TestGetStats) { 395 TEST_F(TransportControllerTest, TestGetStats) {
395 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 396 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
396 ASSERT_NE(nullptr, channel1); 397 ASSERT_NE(nullptr, channel1);
397 FakeTransportChannel* channel2 = CreateChannel("audio", 2); 398 FakeDtlsTransport* channel2 = CreateChannel("audio", 2);
398 ASSERT_NE(nullptr, channel2); 399 ASSERT_NE(nullptr, channel2);
399 FakeTransportChannel* channel3 = CreateChannel("video", 1); 400 FakeDtlsTransport* channel3 = CreateChannel("video", 1);
400 ASSERT_NE(nullptr, channel3); 401 ASSERT_NE(nullptr, channel3);
401 402
402 TransportStats stats; 403 TransportStats stats;
403 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); 404 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats));
404 EXPECT_EQ("audio", stats.transport_name); 405 EXPECT_EQ("audio", stats.transport_name);
405 EXPECT_EQ(2U, stats.channel_stats.size()); 406 EXPECT_EQ(2U, stats.channel_stats.size());
406 } 407 }
407 408
408 // Test that transport gets destroyed when it has no more channels. 409 // Test that transport gets destroyed when it has no more channels.
409 TEST_F(TransportControllerTest, TestCreateAndDestroyChannel) { 410 TEST_F(TransportControllerTest, TestCreateAndDestroyChannel) {
410 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 411 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
411 ASSERT_NE(nullptr, channel1); 412 ASSERT_NE(nullptr, channel1);
412 FakeTransportChannel* channel2 = CreateChannel("audio", 1); 413 FakeDtlsTransport* channel2 = CreateChannel("audio", 1);
413 ASSERT_NE(nullptr, channel2); 414 ASSERT_NE(nullptr, channel2);
414 ASSERT_EQ(channel1, channel2); 415 ASSERT_EQ(channel1, channel2);
415 FakeTransportChannel* channel3 = CreateChannel("audio", 2); 416 FakeDtlsTransport* channel3 = CreateChannel("audio", 2);
416 ASSERT_NE(nullptr, channel3); 417 ASSERT_NE(nullptr, channel3);
417 418
418 // Using GetStats to check if transport is destroyed from an outside class's 419 // Using GetStats to check if transport is destroyed from an outside class's
419 // perspective. 420 // perspective.
420 TransportStats stats; 421 TransportStats stats;
421 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); 422 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats));
422 DestroyChannel("audio", 2); 423 DestroyChannel("audio", 2);
423 DestroyChannel("audio", 1); 424 DestroyChannel("audio", 1);
424 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); 425 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats));
425 DestroyChannel("audio", 1); 426 DestroyChannel("audio", 1);
426 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats)); 427 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats));
427 } 428 }
428 429
429 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) { 430 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) {
430 // Need controlling ICE role to get in failed state. 431 // Need controlling ICE role to get in failed state.
431 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 432 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
432 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 433 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
433 ASSERT_NE(nullptr, channel1); 434 ASSERT_NE(nullptr, channel1);
434 FakeTransportChannel* channel2 = CreateChannel("video", 1); 435 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
435 ASSERT_NE(nullptr, channel2); 436 ASSERT_NE(nullptr, channel2);
436 437
437 // Should signal "failed" if any channel failed; channel is considered failed 438 // Should signal "failed" if any channel failed; channel is considered failed
438 // if it previously had a connection but now has none, and gathering is 439 // if it previously had a connection but now has none, and gathering is
439 // complete. 440 // complete.
440 channel1->SetCandidatesGatheringComplete(); 441 channel1->SetCandidatesGatheringComplete();
441 channel1->SetConnectionCount(1); 442 channel1->SetConnectionCount(1);
442 channel1->SetConnectionCount(0); 443 channel1->SetConnectionCount(0);
443 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); 444 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout);
444 EXPECT_EQ(1, connection_state_signal_count_); 445 EXPECT_EQ(1, connection_state_signal_count_);
445 } 446 }
446 447
447 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) { 448 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) {
448 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 449 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
449 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 450 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
450 ASSERT_NE(nullptr, channel1); 451 ASSERT_NE(nullptr, channel1);
451 FakeTransportChannel* channel2 = CreateChannel("video", 1); 452 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
452 ASSERT_NE(nullptr, channel2); 453 ASSERT_NE(nullptr, channel2);
453 FakeTransportChannel* channel3 = CreateChannel("video", 2); 454 FakeDtlsTransport* channel3 = CreateChannel("video", 2);
454 ASSERT_NE(nullptr, channel3); 455 ASSERT_NE(nullptr, channel3);
455 456
456 // First, have one channel connect, and another fail, to ensure that 457 // First, have one channel connect, and another fail, to ensure that
457 // the first channel connecting didn't trigger a "connected" state signal. 458 // the first channel connecting didn't trigger a "connected" state signal.
458 // We should only get a signal when all are connected. 459 // We should only get a signal when all are connected.
459 channel1->SetConnectionCount(2); 460 channel1->SetConnectionCount(2);
460 channel1->SetWritable(true); 461 channel1->SetWritable(true);
461 channel3->SetCandidatesGatheringComplete(); 462 channel3->SetCandidatesGatheringComplete();
462 channel3->SetConnectionCount(1); 463 channel3->SetConnectionCount(1);
463 channel3->SetConnectionCount(0); 464 channel3->SetConnectionCount(0);
464 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); 465 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout);
465 // Signal count of 1 means that the only signal emitted was "failed". 466 // Signal count of 1 means that the only signal emitted was "failed".
466 EXPECT_EQ(1, connection_state_signal_count_); 467 EXPECT_EQ(1, connection_state_signal_count_);
467 468
468 // Destroy the failed channel to return to "connecting" state. 469 // Destroy the failed channel to return to "connecting" state.
469 DestroyChannel("video", 2); 470 DestroyChannel("video", 2);
470 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); 471 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout);
471 EXPECT_EQ(2, connection_state_signal_count_); 472 EXPECT_EQ(2, connection_state_signal_count_);
472 473
473 // Make the remaining channel reach a connected state. 474 // Make the remaining channel reach a connected state.
474 channel2->SetConnectionCount(2); 475 channel2->SetConnectionCount(2);
475 channel2->SetWritable(true); 476 channel2->SetWritable(true);
476 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); 477 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout);
477 EXPECT_EQ(3, connection_state_signal_count_); 478 EXPECT_EQ(3, connection_state_signal_count_);
478 } 479 }
479 480
480 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) { 481 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) {
481 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 482 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
482 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 483 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
483 ASSERT_NE(nullptr, channel1); 484 ASSERT_NE(nullptr, channel1);
484 FakeTransportChannel* channel2 = CreateChannel("video", 1); 485 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
485 ASSERT_NE(nullptr, channel2); 486 ASSERT_NE(nullptr, channel2);
486 FakeTransportChannel* channel3 = CreateChannel("video", 2); 487 FakeDtlsTransport* channel3 = CreateChannel("video", 2);
487 ASSERT_NE(nullptr, channel3); 488 ASSERT_NE(nullptr, channel3);
488 489
489 // Similar to above test, but we're now reaching the completed state, which 490 // Similar to above test, but we're now reaching the completed state, which
490 // means only one connection per FakeTransportChannel. 491 // means only one connection per FakeDtlsTransport.
491 channel1->SetCandidatesGatheringComplete(); 492 channel1->SetCandidatesGatheringComplete();
492 channel1->SetConnectionCount(1); 493 channel1->SetConnectionCount(1);
493 channel1->SetWritable(true); 494 channel1->SetWritable(true);
494 channel3->SetCandidatesGatheringComplete(); 495 channel3->SetCandidatesGatheringComplete();
495 channel3->SetConnectionCount(1); 496 channel3->SetConnectionCount(1);
496 channel3->SetConnectionCount(0); 497 channel3->SetConnectionCount(0);
497 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); 498 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout);
498 // Signal count of 1 means that the only signal emitted was "failed". 499 // Signal count of 1 means that the only signal emitted was "failed".
499 EXPECT_EQ(1, connection_state_signal_count_); 500 EXPECT_EQ(1, connection_state_signal_count_);
500 501
(...skipping 11 matching lines...) Expand all
512 513
513 // Finally, transition to completed state. 514 // Finally, transition to completed state.
514 channel2->SetConnectionCount(1); 515 channel2->SetConnectionCount(1);
515 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); 516 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout);
516 EXPECT_EQ(4, connection_state_signal_count_); 517 EXPECT_EQ(4, connection_state_signal_count_);
517 } 518 }
518 519
519 // Make sure that if we're "connected" and remove a transport, we stay in the 520 // Make sure that if we're "connected" and remove a transport, we stay in the
520 // "connected" state. 521 // "connected" state.
521 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) { 522 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) {
522 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 523 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
523 ASSERT_NE(nullptr, channel1); 524 ASSERT_NE(nullptr, channel1);
524 FakeTransportChannel* channel2 = CreateChannel("video", 1); 525 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
525 ASSERT_NE(nullptr, channel2); 526 ASSERT_NE(nullptr, channel2);
526 527
527 channel1->SetCandidatesGatheringComplete(); 528 channel1->SetCandidatesGatheringComplete();
528 channel1->SetConnectionCount(2); 529 channel1->SetConnectionCount(2);
529 channel1->SetWritable(true); 530 channel1->SetWritable(true);
530 channel2->SetCandidatesGatheringComplete(); 531 channel2->SetCandidatesGatheringComplete();
531 channel2->SetConnectionCount(2); 532 channel2->SetConnectionCount(2);
532 channel2->SetWritable(true); 533 channel2->SetWritable(true);
533 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); 534 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout);
534 EXPECT_EQ(1, connection_state_signal_count_); 535 EXPECT_EQ(1, connection_state_signal_count_);
535 536
536 // Destroy one channel, then "complete" the other one, so we reach 537 // Destroy one channel, then "complete" the other one, so we reach
537 // a known state. 538 // a known state.
538 DestroyChannel("video", 1); 539 DestroyChannel("video", 1);
539 channel1->SetConnectionCount(1); 540 channel1->SetConnectionCount(1);
540 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); 541 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout);
541 // Signal count of 2 means the deletion didn't cause any unexpected signals 542 // Signal count of 2 means the deletion didn't cause any unexpected signals
542 EXPECT_EQ(2, connection_state_signal_count_); 543 EXPECT_EQ(2, connection_state_signal_count_);
543 } 544 }
544 545
545 // If we destroy the last/only transport, we should simply transition to 546 // If we destroy the last/only transport, we should simply transition to
546 // "connecting". 547 // "connecting".
547 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) { 548 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) {
548 FakeTransportChannel* channel = CreateChannel("audio", 1); 549 FakeDtlsTransport* channel = CreateChannel("audio", 1);
549 ASSERT_NE(nullptr, channel); 550 ASSERT_NE(nullptr, channel);
550 551
551 channel->SetCandidatesGatheringComplete(); 552 channel->SetCandidatesGatheringComplete();
552 channel->SetConnectionCount(2); 553 channel->SetConnectionCount(2);
553 channel->SetWritable(true); 554 channel->SetWritable(true);
554 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); 555 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout);
555 EXPECT_EQ(1, connection_state_signal_count_); 556 EXPECT_EQ(1, connection_state_signal_count_);
556 557
557 DestroyChannel("audio", 1); 558 DestroyChannel("audio", 1);
558 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); 559 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout);
559 // Signal count of 2 means the deletion didn't cause any unexpected signals 560 // Signal count of 2 means the deletion didn't cause any unexpected signals
560 EXPECT_EQ(2, connection_state_signal_count_); 561 EXPECT_EQ(2, connection_state_signal_count_);
561 } 562 }
562 563
563 TEST_F(TransportControllerTest, TestSignalReceiving) { 564 TEST_F(TransportControllerTest, TestSignalReceiving) {
564 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 565 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
565 ASSERT_NE(nullptr, channel1); 566 ASSERT_NE(nullptr, channel1);
566 FakeTransportChannel* channel2 = CreateChannel("video", 1); 567 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
567 ASSERT_NE(nullptr, channel2); 568 ASSERT_NE(nullptr, channel2);
568 569
569 // Should signal receiving as soon as any channel is receiving. 570 // Should signal receiving as soon as any channel is receiving.
570 channel1->SetReceiving(true); 571 channel1->SetReceiving(true);
571 EXPECT_TRUE_WAIT(receiving_, kTimeout); 572 EXPECT_TRUE_WAIT(receiving_, kTimeout);
572 EXPECT_EQ(1, receiving_signal_count_); 573 EXPECT_EQ(1, receiving_signal_count_);
573 574
574 channel2->SetReceiving(true); 575 channel2->SetReceiving(true);
575 channel1->SetReceiving(false); 576 channel1->SetReceiving(false);
576 channel2->SetReceiving(false); 577 channel2->SetReceiving(false);
577 EXPECT_TRUE_WAIT(!receiving_, kTimeout); 578 EXPECT_TRUE_WAIT(!receiving_, kTimeout);
578 EXPECT_EQ(2, receiving_signal_count_); 579 EXPECT_EQ(2, receiving_signal_count_);
579 } 580 }
580 581
581 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) { 582 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) {
582 FakeTransportChannel* channel = CreateChannel("audio", 1); 583 FakeDtlsTransport* channel = CreateChannel("audio", 1);
583 ASSERT_NE(nullptr, channel); 584 ASSERT_NE(nullptr, channel);
584 channel->MaybeStartGathering(); 585 channel->ice_transport()->MaybeStartGathering();
585 // Should be in the gathering state as soon as any transport starts gathering. 586 // Should be in the gathering state as soon as any transport starts gathering.
586 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); 587 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout);
587 EXPECT_EQ(1, gathering_state_signal_count_); 588 EXPECT_EQ(1, gathering_state_signal_count_);
588 } 589 }
589 590
590 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) { 591 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) {
591 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 592 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
592 ASSERT_NE(nullptr, channel1); 593 ASSERT_NE(nullptr, channel1);
593 FakeTransportChannel* channel2 = CreateChannel("video", 1); 594 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
594 ASSERT_NE(nullptr, channel2); 595 ASSERT_NE(nullptr, channel2);
595 FakeTransportChannel* channel3 = CreateChannel("data", 1); 596 FakeDtlsTransport* channel3 = CreateChannel("data", 1);
596 ASSERT_NE(nullptr, channel3); 597 ASSERT_NE(nullptr, channel3);
597 598
598 channel3->MaybeStartGathering(); 599 channel3->ice_transport()->MaybeStartGathering();
599 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); 600 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout);
600 EXPECT_EQ(1, gathering_state_signal_count_); 601 EXPECT_EQ(1, gathering_state_signal_count_);
601 602
602 // Have one channel finish gathering, then destroy it, to make sure gathering 603 // Have one channel finish gathering, then destroy it, to make sure gathering
603 // completion wasn't signalled if only one transport finished gathering. 604 // completion wasn't signalled if only one transport finished gathering.
604 channel3->SetCandidatesGatheringComplete(); 605 channel3->SetCandidatesGatheringComplete();
605 DestroyChannel("data", 1); 606 DestroyChannel("data", 1);
606 EXPECT_EQ_WAIT(kIceGatheringNew, gathering_state_, kTimeout); 607 EXPECT_EQ_WAIT(kIceGatheringNew, gathering_state_, kTimeout);
607 EXPECT_EQ(2, gathering_state_signal_count_); 608 EXPECT_EQ(2, gathering_state_signal_count_);
608 609
609 // Make remaining channels start and then finish gathering. 610 // Make remaining channels start and then finish gathering.
610 channel1->MaybeStartGathering(); 611 channel1->ice_transport()->MaybeStartGathering();
611 channel2->MaybeStartGathering(); 612 channel2->ice_transport()->MaybeStartGathering();
612 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); 613 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout);
613 EXPECT_EQ(3, gathering_state_signal_count_); 614 EXPECT_EQ(3, gathering_state_signal_count_);
614 615
615 channel1->SetCandidatesGatheringComplete(); 616 channel1->SetCandidatesGatheringComplete();
616 channel2->SetCandidatesGatheringComplete(); 617 channel2->SetCandidatesGatheringComplete();
617 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); 618 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout);
618 EXPECT_EQ(4, gathering_state_signal_count_); 619 EXPECT_EQ(4, gathering_state_signal_count_);
619 } 620 }
620 621
621 // Test that when the last transport that hasn't finished connecting and/or 622 // Test that when the last transport that hasn't finished connecting and/or
622 // gathering is destroyed, the aggregate state jumps to "completed". This can 623 // gathering is destroyed, the aggregate state jumps to "completed". This can
623 // happen if, for example, we have an audio and video transport, the audio 624 // happen if, for example, we have an audio and video transport, the audio
624 // transport completes, then we start bundling video on the audio transport. 625 // transport completes, then we start bundling video on the audio transport.
625 TEST_F(TransportControllerTest, 626 TEST_F(TransportControllerTest,
626 TestSignalingWhenLastIncompleteTransportDestroyed) { 627 TestSignalingWhenLastIncompleteTransportDestroyed) {
627 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 628 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
628 FakeTransportChannel* channel1 = CreateChannel("audio", 1); 629 FakeDtlsTransport* channel1 = CreateChannel("audio", 1);
629 ASSERT_NE(nullptr, channel1); 630 ASSERT_NE(nullptr, channel1);
630 FakeTransportChannel* channel2 = CreateChannel("video", 1); 631 FakeDtlsTransport* channel2 = CreateChannel("video", 1);
631 ASSERT_NE(nullptr, channel2); 632 ASSERT_NE(nullptr, channel2);
632 633
633 channel1->SetCandidatesGatheringComplete(); 634 channel1->SetCandidatesGatheringComplete();
634 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); 635 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout);
635 EXPECT_EQ(1, gathering_state_signal_count_); 636 EXPECT_EQ(1, gathering_state_signal_count_);
636 637
637 channel1->SetConnectionCount(1); 638 channel1->SetConnectionCount(1);
638 channel1->SetWritable(true); 639 channel1->SetWritable(true);
639 DestroyChannel("video", 1); 640 DestroyChannel("video", 1);
640 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); 641 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout);
641 EXPECT_EQ(1, connection_state_signal_count_); 642 EXPECT_EQ(1, connection_state_signal_count_);
642 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); 643 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout);
643 EXPECT_EQ(2, gathering_state_signal_count_); 644 EXPECT_EQ(2, gathering_state_signal_count_);
644 } 645 }
645 646
646 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) { 647 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) {
647 FakeTransportChannel* channel = CreateChannel("audio", 1); 648 FakeDtlsTransport* channel = CreateChannel("audio", 1);
648 ASSERT_NE(nullptr, channel); 649 ASSERT_NE(nullptr, channel);
649 650
650 // Transport won't signal candidates until it has a local description. 651 // Transport won't signal candidates until it has a local description.
651 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, 652 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1,
652 kIcePwd1, ICEMODE_FULL, 653 kIcePwd1, ICEMODE_FULL,
653 CONNECTIONROLE_ACTPASS, nullptr); 654 CONNECTIONROLE_ACTPASS, nullptr);
654 std::string err; 655 std::string err;
655 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( 656 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription(
656 "audio", local_desc, CA_OFFER, &err)); 657 "audio", local_desc, CA_OFFER, &err));
657 transport_controller_->MaybeStartGathering(); 658 transport_controller_->MaybeStartGathering();
658 659
659 channel->SignalCandidateGathered(channel, CreateCandidate(1)); 660 channel->ice_transport()->SignalCandidateGathered(channel->ice_transport(),
661 CreateCandidate(1));
660 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout); 662 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout);
661 EXPECT_EQ(1U, candidates_["audio"].size()); 663 EXPECT_EQ(1U, candidates_["audio"].size());
662 } 664 }
663 665
664 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) { 666 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) {
665 CreateTransportControllerWithNetworkThread(); 667 CreateTransportControllerWithNetworkThread();
666 CreateChannelsAndCompleteConnectionOnNetworkThread(); 668 CreateChannelsAndCompleteConnectionOnNetworkThread();
667 669
668 // connecting --> connected --> completed 670 // connecting --> connected --> completed
669 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); 671 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout);
(...skipping 13 matching lines...) Expand all
683 EXPECT_TRUE(!signaled_on_non_signaling_thread_); 685 EXPECT_TRUE(!signaled_on_non_signaling_thread_);
684 } 686 }
685 687
686 // Older versions of Chrome expect the ICE role to be re-determined when an 688 // Older versions of Chrome expect the ICE role to be re-determined when an
687 // ICE restart occurs, and also don't perform conflict resolution correctly, 689 // ICE restart occurs, and also don't perform conflict resolution correctly,
688 // so for now we can't safely stop doing this. 690 // so for now we can't safely stop doing this.
689 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=628676 691 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=628676
690 // TODO(deadbeef): Remove this when these old versions of Chrome reach a low 692 // TODO(deadbeef): Remove this when these old versions of Chrome reach a low
691 // enough population. 693 // enough population.
692 TEST_F(TransportControllerTest, IceRoleRedeterminedOnIceRestartByDefault) { 694 TEST_F(TransportControllerTest, IceRoleRedeterminedOnIceRestartByDefault) {
693 FakeTransportChannel* channel = CreateChannel("audio", 1); 695 FakeDtlsTransport* channel = CreateChannel("audio", 1);
694 ASSERT_NE(nullptr, channel); 696 ASSERT_NE(nullptr, channel);
695 std::string err; 697 std::string err;
696 // Do an initial offer answer, so that the next offer is an ICE restart. 698 // Do an initial offer answer, so that the next offer is an ICE restart.
697 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); 699 transport_controller_->SetIceRole(ICEROLE_CONTROLLED);
698 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, 700 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1,
699 kIcePwd1, ICEMODE_FULL, 701 kIcePwd1, ICEMODE_FULL,
700 CONNECTIONROLE_ACTPASS, nullptr); 702 CONNECTIONROLE_ACTPASS, nullptr);
701 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( 703 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription(
702 "audio", remote_desc, CA_OFFER, &err)); 704 "audio", remote_desc, CA_OFFER, &err));
703 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, 705 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2,
(...skipping 12 matching lines...) Expand all
716 "audio", ice_restart_desc, CA_OFFER, &err)); 718 "audio", ice_restart_desc, CA_OFFER, &err));
717 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole()); 719 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole());
718 } 720 }
719 721
720 // Test that if the TransportController was created with the 722 // Test that if the TransportController was created with the
721 // |redetermine_role_on_ice_restart| parameter set to false, the role is *not* 723 // |redetermine_role_on_ice_restart| parameter set to false, the role is *not*
722 // redetermined on an ICE restart. 724 // redetermined on an ICE restart.
723 TEST_F(TransportControllerTest, IceRoleNotRedetermined) { 725 TEST_F(TransportControllerTest, IceRoleNotRedetermined) {
724 bool redetermine_role = false; 726 bool redetermine_role = false;
725 transport_controller_.reset(new TransportControllerForTest(redetermine_role)); 727 transport_controller_.reset(new TransportControllerForTest(redetermine_role));
726 FakeTransportChannel* channel = CreateChannel("audio", 1); 728 FakeDtlsTransport* channel = CreateChannel("audio", 1);
727 ASSERT_NE(nullptr, channel); 729 ASSERT_NE(nullptr, channel);
728 std::string err; 730 std::string err;
729 // Do an initial offer answer, so that the next offer is an ICE restart. 731 // Do an initial offer answer, so that the next offer is an ICE restart.
730 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); 732 transport_controller_->SetIceRole(ICEROLE_CONTROLLED);
731 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, 733 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1,
732 kIcePwd1, ICEMODE_FULL, 734 kIcePwd1, ICEMODE_FULL,
733 CONNECTIONROLE_ACTPASS, nullptr); 735 CONNECTIONROLE_ACTPASS, nullptr);
734 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( 736 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription(
735 "audio", remote_desc, CA_OFFER, &err)); 737 "audio", remote_desc, CA_OFFER, &err));
736 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, 738 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2,
737 kIcePwd2, ICEMODE_FULL, 739 kIcePwd2, ICEMODE_FULL,
738 CONNECTIONROLE_ACTPASS, nullptr); 740 CONNECTIONROLE_ACTPASS, nullptr);
739 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( 741 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription(
740 "audio", local_desc, CA_ANSWER, &err)); 742 "audio", local_desc, CA_ANSWER, &err));
741 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole()); 743 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole());
742 744
743 // The endpoint that initiated an ICE restart should keep the existing role. 745 // The endpoint that initiated an ICE restart should keep the existing role.
744 TransportDescription ice_restart_desc(std::vector<std::string>(), kIceUfrag3, 746 TransportDescription ice_restart_desc(std::vector<std::string>(), kIceUfrag3,
745 kIcePwd3, ICEMODE_FULL, 747 kIcePwd3, ICEMODE_FULL,
746 CONNECTIONROLE_ACTPASS, nullptr); 748 CONNECTIONROLE_ACTPASS, nullptr);
747 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( 749 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription(
748 "audio", ice_restart_desc, CA_OFFER, &err)); 750 "audio", ice_restart_desc, CA_OFFER, &err));
749 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole()); 751 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole());
750 } 752 }
751 753
752 // Tests channel role is reversed after receiving ice-lite from remote. 754 // Tests channel role is reversed after receiving ice-lite from remote.
753 TEST_F(TransportControllerTest, TestSetRemoteIceLiteInOffer) { 755 TEST_F(TransportControllerTest, TestSetRemoteIceLiteInOffer) {
754 FakeTransportChannel* channel = CreateChannel("audio", 1); 756 FakeDtlsTransport* channel = CreateChannel("audio", 1);
755 ASSERT_NE(nullptr, channel); 757 ASSERT_NE(nullptr, channel);
756 std::string err; 758 std::string err;
757 759
758 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); 760 transport_controller_->SetIceRole(ICEROLE_CONTROLLED);
759 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, 761 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1,
760 kIcePwd1, ICEMODE_LITE, 762 kIcePwd1, ICEMODE_LITE,
761 CONNECTIONROLE_ACTPASS, nullptr); 763 CONNECTIONROLE_ACTPASS, nullptr);
762 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( 764 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription(
763 "audio", remote_desc, CA_OFFER, &err)); 765 "audio", remote_desc, CA_OFFER, &err));
764 TransportDescription local_desc(kIceUfrag1, kIcePwd1); 766 TransportDescription local_desc(kIceUfrag1, kIcePwd1);
765 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription( 767 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription(
766 "audio", local_desc, CA_ANSWER, nullptr)); 768 "audio", local_desc, CA_ANSWER, nullptr));
767 769
768 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole()); 770 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole());
769 EXPECT_EQ(ICEMODE_LITE, channel->remote_ice_mode()); 771 EXPECT_EQ(ICEMODE_LITE, channel->remote_ice_mode());
770 } 772 }
771 773
772 // Tests ice-lite in remote answer. 774 // Tests ice-lite in remote answer.
773 TEST_F(TransportControllerTest, TestSetRemoteIceLiteInAnswer) { 775 TEST_F(TransportControllerTest, TestSetRemoteIceLiteInAnswer) {
774 FakeTransportChannel* channel = CreateChannel("audio", 1); 776 FakeDtlsTransport* channel = CreateChannel("audio", 1);
775 ASSERT_NE(nullptr, channel); 777 ASSERT_NE(nullptr, channel);
776 std::string err; 778 std::string err;
777 779
778 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); 780 transport_controller_->SetIceRole(ICEROLE_CONTROLLING);
779 TransportDescription local_desc(kIceUfrag1, kIcePwd1); 781 TransportDescription local_desc(kIceUfrag1, kIcePwd1);
780 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription( 782 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription(
781 "audio", local_desc, CA_OFFER, nullptr)); 783 "audio", local_desc, CA_OFFER, nullptr));
782 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole()); 784 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole());
783 // Channels will be created in ICEFULL_MODE. 785 // Channels will be created in ICEFULL_MODE.
784 EXPECT_EQ(ICEMODE_FULL, channel->remote_ice_mode()); 786 EXPECT_EQ(ICEMODE_FULL, channel->remote_ice_mode());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription( 830 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription(
829 "audio", ice_restart_local_desc, CA_OFFER, nullptr)); 831 "audio", ice_restart_local_desc, CA_OFFER, nullptr));
830 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription( 832 ASSERT_TRUE(transport_controller_->SetLocalTransportDescription(
831 "video", local_desc, CA_OFFER, nullptr)); 833 "video", local_desc, CA_OFFER, nullptr));
832 // NeedsIceRestart should still be true for video. 834 // NeedsIceRestart should still be true for video.
833 EXPECT_FALSE(transport_controller_->NeedsIceRestart("audio")); 835 EXPECT_FALSE(transport_controller_->NeedsIceRestart("audio"));
834 EXPECT_TRUE(transport_controller_->NeedsIceRestart("video")); 836 EXPECT_TRUE(transport_controller_->NeedsIceRestart("video"));
835 } 837 }
836 838
837 } // namespace cricket { 839 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transportcontroller.cc ('k') | webrtc/p2p/base/udptransport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698