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

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

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