OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 #include "webrtc/p2p/base/faketransportcontroller.h" | 21 #include "webrtc/p2p/base/faketransportcontroller.h" |
22 #include "webrtc/p2p/base/p2ptransportchannel.h" | 22 #include "webrtc/p2p/base/p2ptransportchannel.h" |
23 #include "webrtc/p2p/base/portallocator.h" | 23 #include "webrtc/p2p/base/portallocator.h" |
24 #include "webrtc/p2p/base/transportcontroller.h" | 24 #include "webrtc/p2p/base/transportcontroller.h" |
25 | 25 |
26 static const int kTimeout = 100; | 26 static const int kTimeout = 100; |
27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
29 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; | 29 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
30 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; | 30 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
| 31 static const char kIceUfrag3[] = "TESTICEUFRAG0003"; |
| 32 static const char kIcePwd3[] = "TESTICEPWD00000000000003"; |
31 | 33 |
32 using cricket::Candidate; | 34 namespace cricket { |
33 using cricket::Candidates; | |
34 using cricket::FakeTransportChannel; | |
35 using cricket::FakeTransportController; | |
36 using cricket::IceConnectionState; | |
37 using cricket::IceGatheringState; | |
38 using cricket::TransportChannel; | |
39 using cricket::TransportController; | |
40 using cricket::TransportDescription; | |
41 using cricket::TransportStats; | |
42 | 35 |
43 // Only subclassing from FakeTransportController because currently that's the | 36 // Only subclassing from FakeTransportController because currently that's the |
44 // only way to have a TransportController with fake TransportChannels. | 37 // only way to have a TransportController with fake TransportChannels. |
45 // | 38 // |
46 // TODO(deadbeef): Change this once the Transport/TransportChannel class | 39 // TODO(deadbeef): Change this once the Transport/TransportChannel class |
47 // heirarchy is cleaned up, and we can pass a "TransportChannelFactory" or | 40 // heirarchy is cleaned up, and we can pass a "TransportChannelFactory" or |
48 // something similar into TransportController. | 41 // something similar into TransportController. |
49 typedef FakeTransportController TransportControllerForTest; | 42 typedef FakeTransportController TransportControllerForTest; |
50 | 43 |
51 class TransportControllerTest : public testing::Test, | 44 class TransportControllerTest : public testing::Test, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 79 } |
87 | 80 |
88 void DestroyChannel(const std::string& content, int component) { | 81 void DestroyChannel(const std::string& content, int component) { |
89 transport_controller_->DestroyTransportChannel_n(content, component); | 82 transport_controller_->DestroyTransportChannel_n(content, component); |
90 } | 83 } |
91 | 84 |
92 Candidate CreateCandidate(int component) { | 85 Candidate CreateCandidate(int component) { |
93 Candidate c; | 86 Candidate c; |
94 c.set_address(rtc::SocketAddress("192.168.1.1", 8000)); | 87 c.set_address(rtc::SocketAddress("192.168.1.1", 8000)); |
95 c.set_component(1); | 88 c.set_component(1); |
96 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 89 c.set_protocol(UDP_PROTOCOL_NAME); |
97 c.set_priority(1); | 90 c.set_priority(1); |
98 return c; | 91 return c; |
99 } | 92 } |
100 | 93 |
101 // Used for thread hopping test. | 94 // Used for thread hopping test. |
102 void CreateChannelsAndCompleteConnectionOnWorkerThread() { | 95 void CreateChannelsAndCompleteConnectionOnWorkerThread() { |
103 worker_thread_->Invoke<void>( | 96 worker_thread_->Invoke<void>( |
104 RTC_FROM_HERE, | 97 RTC_FROM_HERE, |
105 rtc::Bind( | 98 rtc::Bind( |
106 &TransportControllerTest::CreateChannelsAndCompleteConnection_w, | 99 &TransportControllerTest::CreateChannelsAndCompleteConnection_w, |
107 this)); | 100 this)); |
108 } | 101 } |
109 | 102 |
110 void CreateChannelsAndCompleteConnection_w() { | 103 void CreateChannelsAndCompleteConnection_w() { |
111 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 104 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
112 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 105 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
113 ASSERT_NE(nullptr, channel1); | 106 ASSERT_NE(nullptr, channel1); |
114 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 107 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
115 ASSERT_NE(nullptr, channel2); | 108 ASSERT_NE(nullptr, channel2); |
116 | 109 |
117 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, | 110 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, |
118 kIcePwd1, cricket::ICEMODE_FULL, | 111 kIcePwd1, ICEMODE_FULL, |
119 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 112 CONNECTIONROLE_ACTPASS, nullptr); |
120 std::string err; | 113 std::string err; |
121 transport_controller_->SetLocalTransportDescription( | 114 transport_controller_->SetLocalTransportDescription("audio", local_desc, |
122 "audio", local_desc, cricket::CA_OFFER, &err); | 115 CA_OFFER, &err); |
123 transport_controller_->SetLocalTransportDescription( | 116 transport_controller_->SetLocalTransportDescription("video", local_desc, |
124 "video", local_desc, cricket::CA_OFFER, &err); | 117 CA_OFFER, &err); |
125 transport_controller_->MaybeStartGathering(); | 118 transport_controller_->MaybeStartGathering(); |
126 channel1->SignalCandidateGathered(channel1, CreateCandidate(1)); | 119 channel1->SignalCandidateGathered(channel1, CreateCandidate(1)); |
127 channel2->SignalCandidateGathered(channel2, CreateCandidate(1)); | 120 channel2->SignalCandidateGathered(channel2, CreateCandidate(1)); |
128 channel1->SetCandidatesGatheringComplete(); | 121 channel1->SetCandidatesGatheringComplete(); |
129 channel2->SetCandidatesGatheringComplete(); | 122 channel2->SetCandidatesGatheringComplete(); |
130 channel1->SetConnectionCount(2); | 123 channel1->SetConnectionCount(2); |
131 channel2->SetConnectionCount(2); | 124 channel2->SetConnectionCount(2); |
132 channel1->SetReceiving(true); | 125 channel1->SetReceiving(true); |
133 channel2->SetReceiving(true); | 126 channel2->SetReceiving(true); |
134 channel1->SetWritable(true); | 127 channel1->SetWritable(true); |
135 channel2->SetWritable(true); | 128 channel2->SetWritable(true); |
136 channel1->SetConnectionCount(1); | 129 channel1->SetConnectionCount(1); |
137 channel2->SetConnectionCount(1); | 130 channel2->SetConnectionCount(1); |
138 } | 131 } |
139 | 132 |
140 cricket::IceConfig CreateIceConfig( | 133 IceConfig CreateIceConfig( |
141 int receiving_timeout, | 134 int receiving_timeout, |
142 cricket::ContinualGatheringPolicy continual_gathering_policy) { | 135 ContinualGatheringPolicy continual_gathering_policy) { |
143 cricket::IceConfig config; | 136 IceConfig config; |
144 config.receiving_timeout = receiving_timeout; | 137 config.receiving_timeout = receiving_timeout; |
145 config.continual_gathering_policy = continual_gathering_policy; | 138 config.continual_gathering_policy = continual_gathering_policy; |
146 return config; | 139 return config; |
147 } | 140 } |
148 | 141 |
149 protected: | 142 protected: |
150 void OnConnectionState(IceConnectionState state) { | 143 void OnConnectionState(IceConnectionState state) { |
151 if (!signaling_thread_->IsCurrent()) { | 144 if (!signaling_thread_->IsCurrent()) { |
152 signaled_on_non_signaling_thread_ = true; | 145 signaled_on_non_signaling_thread_ = true; |
153 } | 146 } |
(...skipping 24 matching lines...) Expand all Loading... |
178 } | 171 } |
179 candidates_[transport_name].insert(candidates_[transport_name].end(), | 172 candidates_[transport_name].insert(candidates_[transport_name].end(), |
180 candidates.begin(), candidates.end()); | 173 candidates.begin(), candidates.end()); |
181 ++candidates_signal_count_; | 174 ++candidates_signal_count_; |
182 } | 175 } |
183 | 176 |
184 std::unique_ptr<rtc::Thread> worker_thread_; // Not used for most tests. | 177 std::unique_ptr<rtc::Thread> worker_thread_; // Not used for most tests. |
185 std::unique_ptr<TransportControllerForTest> transport_controller_; | 178 std::unique_ptr<TransportControllerForTest> transport_controller_; |
186 | 179 |
187 // Information received from signals from transport controller. | 180 // Information received from signals from transport controller. |
188 IceConnectionState connection_state_ = cricket::kIceConnectionConnecting; | 181 IceConnectionState connection_state_ = kIceConnectionConnecting; |
189 bool receiving_ = false; | 182 bool receiving_ = false; |
190 IceGatheringState gathering_state_ = cricket::kIceGatheringNew; | 183 IceGatheringState gathering_state_ = kIceGatheringNew; |
191 // transport_name => candidates | 184 // transport_name => candidates |
192 std::map<std::string, Candidates> candidates_; | 185 std::map<std::string, Candidates> candidates_; |
193 // Counts of each signal emitted. | 186 // Counts of each signal emitted. |
194 int connection_state_signal_count_ = 0; | 187 int connection_state_signal_count_ = 0; |
195 int receiving_signal_count_ = 0; | 188 int receiving_signal_count_ = 0; |
196 int gathering_state_signal_count_ = 0; | 189 int gathering_state_signal_count_ = 0; |
197 int candidates_signal_count_ = 0; | 190 int candidates_signal_count_ = 0; |
198 | 191 |
199 // Used to make sure signals only come on signaling thread. | 192 // Used to make sure signals only come on signaling thread. |
200 rtc::Thread* const signaling_thread_ = nullptr; | 193 rtc::Thread* const signaling_thread_ = nullptr; |
201 bool signaled_on_non_signaling_thread_ = false; | 194 bool signaled_on_non_signaling_thread_ = false; |
202 }; | 195 }; |
203 | 196 |
204 TEST_F(TransportControllerTest, TestSetIceConfig) { | 197 TEST_F(TransportControllerTest, TestSetIceConfig) { |
205 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 198 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
206 ASSERT_NE(nullptr, channel1); | 199 ASSERT_NE(nullptr, channel1); |
207 | 200 |
208 transport_controller_->SetIceConfig( | 201 transport_controller_->SetIceConfig( |
209 CreateIceConfig(1000, cricket::GATHER_CONTINUALLY)); | 202 CreateIceConfig(1000, GATHER_CONTINUALLY)); |
210 EXPECT_EQ(1000, channel1->receiving_timeout()); | 203 EXPECT_EQ(1000, channel1->receiving_timeout()); |
211 EXPECT_TRUE(channel1->gather_continually()); | 204 EXPECT_TRUE(channel1->gather_continually()); |
212 | 205 |
213 transport_controller_->SetIceConfig( | 206 transport_controller_->SetIceConfig( |
214 CreateIceConfig(1000, cricket::GATHER_CONTINUALLY_AND_RECOVER)); | 207 CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER)); |
215 // Test that value stored in controller is applied to new channels. | 208 // Test that value stored in controller is applied to new channels. |
216 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 209 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
217 ASSERT_NE(nullptr, channel2); | 210 ASSERT_NE(nullptr, channel2); |
218 EXPECT_EQ(1000, channel2->receiving_timeout()); | 211 EXPECT_EQ(1000, channel2->receiving_timeout()); |
219 EXPECT_TRUE(channel2->gather_continually()); | 212 EXPECT_TRUE(channel2->gather_continually()); |
220 } | 213 } |
221 | 214 |
222 TEST_F(TransportControllerTest, TestSetSslMaxProtocolVersion) { | 215 TEST_F(TransportControllerTest, TestSetSslMaxProtocolVersion) { |
223 EXPECT_TRUE(transport_controller_->SetSslMaxProtocolVersion( | 216 EXPECT_TRUE(transport_controller_->SetSslMaxProtocolVersion( |
224 rtc::SSL_PROTOCOL_DTLS_12)); | 217 rtc::SSL_PROTOCOL_DTLS_12)); |
225 FakeTransportChannel* channel = CreateChannel("audio", 1); | 218 FakeTransportChannel* channel = CreateChannel("audio", 1); |
226 | 219 |
227 ASSERT_NE(nullptr, channel); | 220 ASSERT_NE(nullptr, channel); |
228 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()); |
229 | 222 |
230 // Setting max version after transport is created should fail. | 223 // Setting max version after transport is created should fail. |
231 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion( | 224 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion( |
232 rtc::SSL_PROTOCOL_DTLS_10)); | 225 rtc::SSL_PROTOCOL_DTLS_10)); |
233 } | 226 } |
234 | 227 |
235 TEST_F(TransportControllerTest, TestSetIceRole) { | 228 TEST_F(TransportControllerTest, TestSetIceRole) { |
236 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 229 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
237 ASSERT_NE(nullptr, channel1); | 230 ASSERT_NE(nullptr, channel1); |
238 | 231 |
239 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 232 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
240 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 233 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
241 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 234 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); |
242 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); | 235 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); |
243 | 236 |
244 // Test that value stored in controller is applied to new channels. | 237 // Test that value stored in controller is applied to new channels. |
245 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 238 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
246 ASSERT_NE(nullptr, channel2); | 239 ASSERT_NE(nullptr, channel2); |
247 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 240 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); |
248 } | 241 } |
249 | 242 |
250 // 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 |
251 // swapped on every channel. | 244 // swapped on every channel. |
252 TEST_F(TransportControllerTest, TestIceRoleConflict) { | 245 TEST_F(TransportControllerTest, TestIceRoleConflict) { |
253 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 246 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
254 ASSERT_NE(nullptr, channel1); | 247 ASSERT_NE(nullptr, channel1); |
255 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 248 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
256 ASSERT_NE(nullptr, channel2); | 249 ASSERT_NE(nullptr, channel2); |
257 | 250 |
258 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 251 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
259 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 252 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
260 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); | 253 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); |
261 | 254 |
262 channel1->SignalRoleConflict(channel1); | 255 channel1->SignalRoleConflict(channel1); |
263 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); | 256 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); |
264 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 257 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); |
265 | 258 |
266 // 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 |
267 // change its role/tie-breaker when it does an ICE restart. | 260 // change its role/tie-breaker when it does an ICE restart. |
268 channel2->SignalRoleConflict(channel2); | 261 channel2->SignalRoleConflict(channel2); |
269 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 262 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
270 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); | 263 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); |
271 } | 264 } |
272 | 265 |
273 TEST_F(TransportControllerTest, TestGetSslRole) { | 266 TEST_F(TransportControllerTest, TestGetSslRole) { |
274 FakeTransportChannel* channel = CreateChannel("audio", 1); | 267 FakeTransportChannel* channel = CreateChannel("audio", 1); |
275 ASSERT_NE(nullptr, channel); | 268 ASSERT_NE(nullptr, channel); |
276 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT)); | 269 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT)); |
277 rtc::SSLRole role; | 270 rtc::SSLRole role; |
278 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role)); | 271 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role)); |
279 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role)); | 272 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role)); |
280 EXPECT_EQ(rtc::SSL_CLIENT, role); | 273 EXPECT_EQ(rtc::SSL_CLIENT, role); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 returned_certificate->ToPEMString()); | 321 returned_certificate->ToPEMString()); |
329 | 322 |
330 // Should fail if called for a nonexistant transport. | 323 // Should fail if called for a nonexistant transport. |
331 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video")); | 324 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video")); |
332 } | 325 } |
333 | 326 |
334 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) { | 327 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) { |
335 FakeTransportChannel* channel = CreateChannel("audio", 1); | 328 FakeTransportChannel* channel = CreateChannel("audio", 1); |
336 ASSERT_NE(nullptr, channel); | 329 ASSERT_NE(nullptr, channel); |
337 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, | 330 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, |
338 kIcePwd1, cricket::ICEMODE_FULL, | 331 kIcePwd1, ICEMODE_FULL, |
339 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 332 CONNECTIONROLE_ACTPASS, nullptr); |
340 std::string err; | 333 std::string err; |
341 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 334 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
342 "audio", local_desc, cricket::CA_OFFER, &err)); | 335 "audio", local_desc, CA_OFFER, &err)); |
343 // Check that ICE ufrag and pwd were propagated to channel. | 336 // Check that ICE ufrag and pwd were propagated to channel. |
344 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag()); | 337 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag()); |
345 EXPECT_EQ(kIcePwd1, channel->ice_pwd()); | 338 EXPECT_EQ(kIcePwd1, channel->ice_pwd()); |
346 // After setting local description, we should be able to start gathering | 339 // After setting local description, we should be able to start gathering |
347 // candidates. | 340 // candidates. |
348 transport_controller_->MaybeStartGathering(); | 341 transport_controller_->MaybeStartGathering(); |
349 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 342 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
350 EXPECT_EQ(1, gathering_state_signal_count_); | 343 EXPECT_EQ(1, gathering_state_signal_count_); |
351 } | 344 } |
352 | 345 |
353 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) { | 346 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) { |
354 FakeTransportChannel* channel = CreateChannel("audio", 1); | 347 FakeTransportChannel* channel = CreateChannel("audio", 1); |
355 ASSERT_NE(nullptr, channel); | 348 ASSERT_NE(nullptr, channel); |
356 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, | 349 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
357 kIcePwd1, cricket::ICEMODE_FULL, | 350 kIcePwd1, ICEMODE_FULL, |
358 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 351 CONNECTIONROLE_ACTPASS, nullptr); |
359 std::string err; | 352 std::string err; |
360 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( | 353 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
361 "audio", remote_desc, cricket::CA_OFFER, &err)); | 354 "audio", remote_desc, CA_OFFER, &err)); |
362 // Check that ICE ufrag and pwd were propagated to channel. | 355 // Check that ICE ufrag and pwd were propagated to channel. |
363 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag()); | 356 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag()); |
364 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd()); | 357 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd()); |
365 } | 358 } |
366 | 359 |
367 TEST_F(TransportControllerTest, TestAddRemoteCandidates) { | 360 TEST_F(TransportControllerTest, TestAddRemoteCandidates) { |
368 FakeTransportChannel* channel = CreateChannel("audio", 1); | 361 FakeTransportChannel* channel = CreateChannel("audio", 1); |
369 ASSERT_NE(nullptr, channel); | 362 ASSERT_NE(nullptr, channel); |
370 Candidates candidates; | 363 Candidates candidates; |
371 candidates.push_back(CreateCandidate(1)); | 364 candidates.push_back(CreateCandidate(1)); |
372 std::string err; | 365 std::string err; |
373 EXPECT_TRUE( | 366 EXPECT_TRUE( |
374 transport_controller_->AddRemoteCandidates("audio", candidates, &err)); | 367 transport_controller_->AddRemoteCandidates("audio", candidates, &err)); |
375 EXPECT_EQ(1U, channel->remote_candidates().size()); | 368 EXPECT_EQ(1U, channel->remote_candidates().size()); |
376 } | 369 } |
377 | 370 |
378 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) { | 371 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) { |
379 FakeTransportChannel* channel = CreateChannel("audio", 1); | 372 FakeTransportChannel* channel = CreateChannel("audio", 1); |
380 ASSERT_NE(nullptr, channel); | 373 ASSERT_NE(nullptr, channel); |
381 // 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 |
382 // descriptions are set. | 375 // descriptions are set. |
383 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); | 376 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); |
384 | 377 |
385 std::string err; | 378 std::string err; |
386 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, | 379 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
387 kIcePwd1, cricket::ICEMODE_FULL, | 380 kIcePwd1, ICEMODE_FULL, |
388 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 381 CONNECTIONROLE_ACTPASS, nullptr); |
389 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( | 382 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
390 "audio", remote_desc, cricket::CA_OFFER, &err)); | 383 "audio", remote_desc, CA_OFFER, &err)); |
391 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); | 384 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); |
392 | 385 |
393 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, | 386 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, |
394 kIcePwd2, cricket::ICEMODE_FULL, | 387 kIcePwd2, ICEMODE_FULL, |
395 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 388 CONNECTIONROLE_ACTPASS, nullptr); |
396 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 389 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
397 "audio", local_desc, cricket::CA_ANSWER, &err)); | 390 "audio", local_desc, CA_ANSWER, &err)); |
398 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio")); | 391 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio")); |
399 } | 392 } |
400 | 393 |
401 TEST_F(TransportControllerTest, TestGetStats) { | 394 TEST_F(TransportControllerTest, TestGetStats) { |
402 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 395 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
403 ASSERT_NE(nullptr, channel1); | 396 ASSERT_NE(nullptr, channel1); |
404 FakeTransportChannel* channel2 = CreateChannel("audio", 2); | 397 FakeTransportChannel* channel2 = CreateChannel("audio", 2); |
405 ASSERT_NE(nullptr, channel2); | 398 ASSERT_NE(nullptr, channel2); |
406 FakeTransportChannel* channel3 = CreateChannel("video", 1); | 399 FakeTransportChannel* channel3 = CreateChannel("video", 1); |
407 ASSERT_NE(nullptr, channel3); | 400 ASSERT_NE(nullptr, channel3); |
(...skipping 20 matching lines...) Expand all Loading... |
428 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); | 421 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); |
429 DestroyChannel("audio", 2); | 422 DestroyChannel("audio", 2); |
430 DestroyChannel("audio", 1); | 423 DestroyChannel("audio", 1); |
431 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); | 424 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); |
432 DestroyChannel("audio", 1); | 425 DestroyChannel("audio", 1); |
433 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats)); | 426 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats)); |
434 } | 427 } |
435 | 428 |
436 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) { | 429 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) { |
437 // Need controlling ICE role to get in failed state. | 430 // Need controlling ICE role to get in failed state. |
438 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 431 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
439 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 432 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
440 ASSERT_NE(nullptr, channel1); | 433 ASSERT_NE(nullptr, channel1); |
441 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 434 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
442 ASSERT_NE(nullptr, channel2); | 435 ASSERT_NE(nullptr, channel2); |
443 | 436 |
444 // Should signal "failed" if any channel failed; channel is considered failed | 437 // Should signal "failed" if any channel failed; channel is considered failed |
445 // 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 |
446 // complete. | 439 // complete. |
447 channel1->SetCandidatesGatheringComplete(); | 440 channel1->SetCandidatesGatheringComplete(); |
448 channel1->SetConnectionCount(1); | 441 channel1->SetConnectionCount(1); |
449 channel1->SetConnectionCount(0); | 442 channel1->SetConnectionCount(0); |
450 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 443 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
451 EXPECT_EQ(1, connection_state_signal_count_); | 444 EXPECT_EQ(1, connection_state_signal_count_); |
452 } | 445 } |
453 | 446 |
454 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) { | 447 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) { |
455 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 448 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
456 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 449 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
457 ASSERT_NE(nullptr, channel1); | 450 ASSERT_NE(nullptr, channel1); |
458 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 451 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
459 ASSERT_NE(nullptr, channel2); | 452 ASSERT_NE(nullptr, channel2); |
460 FakeTransportChannel* channel3 = CreateChannel("video", 2); | 453 FakeTransportChannel* channel3 = CreateChannel("video", 2); |
461 ASSERT_NE(nullptr, channel3); | 454 ASSERT_NE(nullptr, channel3); |
462 | 455 |
463 // First, have one channel connect, and another fail, to ensure that | 456 // First, have one channel connect, and another fail, to ensure that |
464 // the first channel connecting didn't trigger a "connected" state signal. | 457 // the first channel connecting didn't trigger a "connected" state signal. |
465 // We should only get a signal when all are connected. | 458 // We should only get a signal when all are connected. |
466 channel1->SetConnectionCount(2); | 459 channel1->SetConnectionCount(2); |
467 channel1->SetWritable(true); | 460 channel1->SetWritable(true); |
468 channel3->SetCandidatesGatheringComplete(); | 461 channel3->SetCandidatesGatheringComplete(); |
469 channel3->SetConnectionCount(1); | 462 channel3->SetConnectionCount(1); |
470 channel3->SetConnectionCount(0); | 463 channel3->SetConnectionCount(0); |
471 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 464 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
472 // 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". |
473 EXPECT_EQ(1, connection_state_signal_count_); | 466 EXPECT_EQ(1, connection_state_signal_count_); |
474 | 467 |
475 // Destroy the failed channel to return to "connecting" state. | 468 // Destroy the failed channel to return to "connecting" state. |
476 DestroyChannel("video", 2); | 469 DestroyChannel("video", 2); |
477 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 470 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
478 kTimeout); | |
479 EXPECT_EQ(2, connection_state_signal_count_); | 471 EXPECT_EQ(2, connection_state_signal_count_); |
480 | 472 |
481 // Make the remaining channel reach a connected state. | 473 // Make the remaining channel reach a connected state. |
482 channel2->SetConnectionCount(2); | 474 channel2->SetConnectionCount(2); |
483 channel2->SetWritable(true); | 475 channel2->SetWritable(true); |
484 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 476 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
485 EXPECT_EQ(3, connection_state_signal_count_); | 477 EXPECT_EQ(3, connection_state_signal_count_); |
486 } | 478 } |
487 | 479 |
488 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) { | 480 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) { |
489 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 481 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
490 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 482 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
491 ASSERT_NE(nullptr, channel1); | 483 ASSERT_NE(nullptr, channel1); |
492 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 484 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
493 ASSERT_NE(nullptr, channel2); | 485 ASSERT_NE(nullptr, channel2); |
494 FakeTransportChannel* channel3 = CreateChannel("video", 2); | 486 FakeTransportChannel* channel3 = CreateChannel("video", 2); |
495 ASSERT_NE(nullptr, channel3); | 487 ASSERT_NE(nullptr, channel3); |
496 | 488 |
497 // 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 |
498 // means only one connection per FakeTransportChannel. | 490 // means only one connection per FakeTransportChannel. |
499 channel1->SetCandidatesGatheringComplete(); | 491 channel1->SetCandidatesGatheringComplete(); |
500 channel1->SetConnectionCount(1); | 492 channel1->SetConnectionCount(1); |
501 channel1->SetWritable(true); | 493 channel1->SetWritable(true); |
502 channel3->SetCandidatesGatheringComplete(); | 494 channel3->SetCandidatesGatheringComplete(); |
503 channel3->SetConnectionCount(1); | 495 channel3->SetConnectionCount(1); |
504 channel3->SetConnectionCount(0); | 496 channel3->SetConnectionCount(0); |
505 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 497 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
506 // 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". |
507 EXPECT_EQ(1, connection_state_signal_count_); | 499 EXPECT_EQ(1, connection_state_signal_count_); |
508 | 500 |
509 // Destroy the failed channel to return to "connecting" state. | 501 // Destroy the failed channel to return to "connecting" state. |
510 DestroyChannel("video", 2); | 502 DestroyChannel("video", 2); |
511 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 503 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
512 kTimeout); | |
513 EXPECT_EQ(2, connection_state_signal_count_); | 504 EXPECT_EQ(2, connection_state_signal_count_); |
514 | 505 |
515 // Make the remaining channel reach a connected state. | 506 // Make the remaining channel reach a connected state. |
516 channel2->SetCandidatesGatheringComplete(); | 507 channel2->SetCandidatesGatheringComplete(); |
517 channel2->SetConnectionCount(2); | 508 channel2->SetConnectionCount(2); |
518 channel2->SetWritable(true); | 509 channel2->SetWritable(true); |
519 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 510 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
520 EXPECT_EQ(3, connection_state_signal_count_); | 511 EXPECT_EQ(3, connection_state_signal_count_); |
521 | 512 |
522 // Finally, transition to completed state. | 513 // Finally, transition to completed state. |
523 channel2->SetConnectionCount(1); | 514 channel2->SetConnectionCount(1); |
524 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 515 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
525 EXPECT_EQ(4, connection_state_signal_count_); | 516 EXPECT_EQ(4, connection_state_signal_count_); |
526 } | 517 } |
527 | 518 |
528 // 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 |
529 // "connected" state. | 520 // "connected" state. |
530 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) { | 521 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) { |
531 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 522 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
532 ASSERT_NE(nullptr, channel1); | 523 ASSERT_NE(nullptr, channel1); |
533 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 524 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
534 ASSERT_NE(nullptr, channel2); | 525 ASSERT_NE(nullptr, channel2); |
535 | 526 |
536 channel1->SetCandidatesGatheringComplete(); | 527 channel1->SetCandidatesGatheringComplete(); |
537 channel1->SetConnectionCount(2); | 528 channel1->SetConnectionCount(2); |
538 channel1->SetWritable(true); | 529 channel1->SetWritable(true); |
539 channel2->SetCandidatesGatheringComplete(); | 530 channel2->SetCandidatesGatheringComplete(); |
540 channel2->SetConnectionCount(2); | 531 channel2->SetConnectionCount(2); |
541 channel2->SetWritable(true); | 532 channel2->SetWritable(true); |
542 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 533 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
543 EXPECT_EQ(1, connection_state_signal_count_); | 534 EXPECT_EQ(1, connection_state_signal_count_); |
544 | 535 |
545 // Destroy one channel, then "complete" the other one, so we reach | 536 // Destroy one channel, then "complete" the other one, so we reach |
546 // a known state. | 537 // a known state. |
547 DestroyChannel("video", 1); | 538 DestroyChannel("video", 1); |
548 channel1->SetConnectionCount(1); | 539 channel1->SetConnectionCount(1); |
549 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 540 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
550 // 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 |
551 EXPECT_EQ(2, connection_state_signal_count_); | 542 EXPECT_EQ(2, connection_state_signal_count_); |
552 } | 543 } |
553 | 544 |
554 // 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 |
555 // "connecting". | 546 // "connecting". |
556 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) { | 547 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) { |
557 FakeTransportChannel* channel = CreateChannel("audio", 1); | 548 FakeTransportChannel* channel = CreateChannel("audio", 1); |
558 ASSERT_NE(nullptr, channel); | 549 ASSERT_NE(nullptr, channel); |
559 | 550 |
560 channel->SetCandidatesGatheringComplete(); | 551 channel->SetCandidatesGatheringComplete(); |
561 channel->SetConnectionCount(2); | 552 channel->SetConnectionCount(2); |
562 channel->SetWritable(true); | 553 channel->SetWritable(true); |
563 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 554 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
564 EXPECT_EQ(1, connection_state_signal_count_); | 555 EXPECT_EQ(1, connection_state_signal_count_); |
565 | 556 |
566 DestroyChannel("audio", 1); | 557 DestroyChannel("audio", 1); |
567 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 558 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
568 kTimeout); | |
569 // 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 |
570 EXPECT_EQ(2, connection_state_signal_count_); | 560 EXPECT_EQ(2, connection_state_signal_count_); |
571 } | 561 } |
572 | 562 |
573 TEST_F(TransportControllerTest, TestSignalReceiving) { | 563 TEST_F(TransportControllerTest, TestSignalReceiving) { |
574 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 564 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
575 ASSERT_NE(nullptr, channel1); | 565 ASSERT_NE(nullptr, channel1); |
576 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 566 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
577 ASSERT_NE(nullptr, channel2); | 567 ASSERT_NE(nullptr, channel2); |
578 | 568 |
579 // Should signal receiving as soon as any channel is receiving. | 569 // Should signal receiving as soon as any channel is receiving. |
580 channel1->SetReceiving(true); | 570 channel1->SetReceiving(true); |
581 EXPECT_TRUE_WAIT(receiving_, kTimeout); | 571 EXPECT_TRUE_WAIT(receiving_, kTimeout); |
582 EXPECT_EQ(1, receiving_signal_count_); | 572 EXPECT_EQ(1, receiving_signal_count_); |
583 | 573 |
584 channel2->SetReceiving(true); | 574 channel2->SetReceiving(true); |
585 channel1->SetReceiving(false); | 575 channel1->SetReceiving(false); |
586 channel2->SetReceiving(false); | 576 channel2->SetReceiving(false); |
587 EXPECT_TRUE_WAIT(!receiving_, kTimeout); | 577 EXPECT_TRUE_WAIT(!receiving_, kTimeout); |
588 EXPECT_EQ(2, receiving_signal_count_); | 578 EXPECT_EQ(2, receiving_signal_count_); |
589 } | 579 } |
590 | 580 |
591 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) { | 581 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) { |
592 FakeTransportChannel* channel = CreateChannel("audio", 1); | 582 FakeTransportChannel* channel = CreateChannel("audio", 1); |
593 ASSERT_NE(nullptr, channel); | 583 ASSERT_NE(nullptr, channel); |
594 channel->MaybeStartGathering(); | 584 channel->MaybeStartGathering(); |
595 // 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. |
596 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 586 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
597 EXPECT_EQ(1, gathering_state_signal_count_); | 587 EXPECT_EQ(1, gathering_state_signal_count_); |
598 } | 588 } |
599 | 589 |
600 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) { | 590 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) { |
601 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 591 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
602 ASSERT_NE(nullptr, channel1); | 592 ASSERT_NE(nullptr, channel1); |
603 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 593 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
604 ASSERT_NE(nullptr, channel2); | 594 ASSERT_NE(nullptr, channel2); |
605 FakeTransportChannel* channel3 = CreateChannel("data", 1); | 595 FakeTransportChannel* channel3 = CreateChannel("data", 1); |
606 ASSERT_NE(nullptr, channel3); | 596 ASSERT_NE(nullptr, channel3); |
607 | 597 |
608 channel3->MaybeStartGathering(); | 598 channel3->MaybeStartGathering(); |
609 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 599 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
610 EXPECT_EQ(1, gathering_state_signal_count_); | 600 EXPECT_EQ(1, gathering_state_signal_count_); |
611 | 601 |
612 // 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 |
613 // completion wasn't signalled if only one transport finished gathering. | 603 // completion wasn't signalled if only one transport finished gathering. |
614 channel3->SetCandidatesGatheringComplete(); | 604 channel3->SetCandidatesGatheringComplete(); |
615 DestroyChannel("data", 1); | 605 DestroyChannel("data", 1); |
616 EXPECT_EQ_WAIT(cricket::kIceGatheringNew, gathering_state_, kTimeout); | 606 EXPECT_EQ_WAIT(kIceGatheringNew, gathering_state_, kTimeout); |
617 EXPECT_EQ(2, gathering_state_signal_count_); | 607 EXPECT_EQ(2, gathering_state_signal_count_); |
618 | 608 |
619 // Make remaining channels start and then finish gathering. | 609 // Make remaining channels start and then finish gathering. |
620 channel1->MaybeStartGathering(); | 610 channel1->MaybeStartGathering(); |
621 channel2->MaybeStartGathering(); | 611 channel2->MaybeStartGathering(); |
622 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 612 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
623 EXPECT_EQ(3, gathering_state_signal_count_); | 613 EXPECT_EQ(3, gathering_state_signal_count_); |
624 | 614 |
625 channel1->SetCandidatesGatheringComplete(); | 615 channel1->SetCandidatesGatheringComplete(); |
626 channel2->SetCandidatesGatheringComplete(); | 616 channel2->SetCandidatesGatheringComplete(); |
627 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 617 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
628 EXPECT_EQ(4, gathering_state_signal_count_); | 618 EXPECT_EQ(4, gathering_state_signal_count_); |
629 } | 619 } |
630 | 620 |
631 // 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 |
632 // gathering is destroyed, the aggregate state jumps to "completed". This can | 622 // gathering is destroyed, the aggregate state jumps to "completed". This can |
633 // 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 |
634 // transport completes, then we start bundling video on the audio transport. | 624 // transport completes, then we start bundling video on the audio transport. |
635 TEST_F(TransportControllerTest, | 625 TEST_F(TransportControllerTest, |
636 TestSignalingWhenLastIncompleteTransportDestroyed) { | 626 TestSignalingWhenLastIncompleteTransportDestroyed) { |
637 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 627 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
638 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 628 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
639 ASSERT_NE(nullptr, channel1); | 629 ASSERT_NE(nullptr, channel1); |
640 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 630 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
641 ASSERT_NE(nullptr, channel2); | 631 ASSERT_NE(nullptr, channel2); |
642 | 632 |
643 channel1->SetCandidatesGatheringComplete(); | 633 channel1->SetCandidatesGatheringComplete(); |
644 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 634 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
645 EXPECT_EQ(1, gathering_state_signal_count_); | 635 EXPECT_EQ(1, gathering_state_signal_count_); |
646 | 636 |
647 channel1->SetConnectionCount(1); | 637 channel1->SetConnectionCount(1); |
648 channel1->SetWritable(true); | 638 channel1->SetWritable(true); |
649 DestroyChannel("video", 1); | 639 DestroyChannel("video", 1); |
650 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 640 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
651 EXPECT_EQ(1, connection_state_signal_count_); | 641 EXPECT_EQ(1, connection_state_signal_count_); |
652 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 642 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
653 EXPECT_EQ(2, gathering_state_signal_count_); | 643 EXPECT_EQ(2, gathering_state_signal_count_); |
654 } | 644 } |
655 | 645 |
656 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) { | 646 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) { |
657 FakeTransportChannel* channel = CreateChannel("audio", 1); | 647 FakeTransportChannel* channel = CreateChannel("audio", 1); |
658 ASSERT_NE(nullptr, channel); | 648 ASSERT_NE(nullptr, channel); |
659 | 649 |
660 // Transport won't signal candidates until it has a local description. | 650 // Transport won't signal candidates until it has a local description. |
661 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, | 651 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, |
662 kIcePwd1, cricket::ICEMODE_FULL, | 652 kIcePwd1, ICEMODE_FULL, |
663 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 653 CONNECTIONROLE_ACTPASS, nullptr); |
664 std::string err; | 654 std::string err; |
665 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 655 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
666 "audio", local_desc, cricket::CA_OFFER, &err)); | 656 "audio", local_desc, CA_OFFER, &err)); |
667 transport_controller_->MaybeStartGathering(); | 657 transport_controller_->MaybeStartGathering(); |
668 | 658 |
669 channel->SignalCandidateGathered(channel, CreateCandidate(1)); | 659 channel->SignalCandidateGathered(channel, CreateCandidate(1)); |
670 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout); | 660 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout); |
671 EXPECT_EQ(1U, candidates_["audio"].size()); | 661 EXPECT_EQ(1U, candidates_["audio"].size()); |
672 } | 662 } |
673 | 663 |
674 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) { | 664 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) { |
675 CreateTransportControllerWithWorkerThread(); | 665 CreateTransportControllerWithWorkerThread(); |
676 CreateChannelsAndCompleteConnectionOnWorkerThread(); | 666 CreateChannelsAndCompleteConnectionOnWorkerThread(); |
677 | 667 |
678 // connecting --> connected --> completed | 668 // connecting --> connected --> completed |
679 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 669 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
680 EXPECT_EQ(2, connection_state_signal_count_); | 670 EXPECT_EQ(2, connection_state_signal_count_); |
681 | 671 |
682 EXPECT_TRUE_WAIT(receiving_, kTimeout); | 672 EXPECT_TRUE_WAIT(receiving_, kTimeout); |
683 EXPECT_EQ(1, receiving_signal_count_); | 673 EXPECT_EQ(1, receiving_signal_count_); |
684 | 674 |
685 // new --> gathering --> complete | 675 // new --> gathering --> complete |
686 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 676 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
687 EXPECT_EQ(2, gathering_state_signal_count_); | 677 EXPECT_EQ(2, gathering_state_signal_count_); |
688 | 678 |
689 EXPECT_EQ_WAIT(1U, candidates_["audio"].size(), kTimeout); | 679 EXPECT_EQ_WAIT(1U, candidates_["audio"].size(), kTimeout); |
690 EXPECT_EQ_WAIT(1U, candidates_["video"].size(), kTimeout); | 680 EXPECT_EQ_WAIT(1U, candidates_["video"].size(), kTimeout); |
691 EXPECT_EQ(2, candidates_signal_count_); | 681 EXPECT_EQ(2, candidates_signal_count_); |
692 | 682 |
693 EXPECT_TRUE(!signaled_on_non_signaling_thread_); | 683 EXPECT_TRUE(!signaled_on_non_signaling_thread_); |
694 } | 684 } |
| 685 |
| 686 // 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, |
| 688 // so for now we can't safely stop doing this. |
| 689 // 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 |
| 691 // enough population. |
| 692 TEST_F(TransportControllerTest, IceRoleRedeterminedOnIceRestart) { |
| 693 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 694 ASSERT_NE(nullptr, channel); |
| 695 std::string err; |
| 696 // Do an initial offer answer, so that the next offer is an ICE restart. |
| 697 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); |
| 698 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
| 699 kIcePwd1, ICEMODE_FULL, |
| 700 CONNECTIONROLE_ACTPASS, nullptr); |
| 701 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
| 702 "audio", remote_desc, CA_OFFER, &err)); |
| 703 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, |
| 704 kIcePwd2, ICEMODE_FULL, |
| 705 CONNECTIONROLE_ACTPASS, nullptr); |
| 706 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 707 "audio", local_desc, CA_ANSWER, &err)); |
| 708 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole()); |
| 709 |
| 710 // The endpoint that initiated an ICE restart should take the controlling |
| 711 // role. |
| 712 TransportDescription ice_restart_desc(std::vector<std::string>(), kIceUfrag3, |
| 713 kIcePwd3, ICEMODE_FULL, |
| 714 CONNECTIONROLE_ACTPASS, nullptr); |
| 715 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 716 "audio", ice_restart_desc, CA_OFFER, &err)); |
| 717 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole()); |
| 718 } |
| 719 |
| 720 } // namespace cricket { |
OLD | NEW |