| 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(int receiving_timeout, | 133 IceConfig CreateIceConfig(int receiving_timeout, bool gather_continually) { |
| 141 bool gather_continually) { | 134 IceConfig config; |
| 142 cricket::IceConfig config; | |
| 143 config.receiving_timeout = receiving_timeout; | 135 config.receiving_timeout = receiving_timeout; |
| 144 config.gather_continually = gather_continually; | 136 config.gather_continually = gather_continually; |
| 145 return config; | 137 return config; |
| 146 } | 138 } |
| 147 | 139 |
| 148 protected: | 140 protected: |
| 149 void OnConnectionState(IceConnectionState state) { | 141 void OnConnectionState(IceConnectionState state) { |
| 150 if (!signaling_thread_->IsCurrent()) { | 142 if (!signaling_thread_->IsCurrent()) { |
| 151 signaled_on_non_signaling_thread_ = true; | 143 signaled_on_non_signaling_thread_ = true; |
| 152 } | 144 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 177 } | 169 } |
| 178 candidates_[transport_name].insert(candidates_[transport_name].end(), | 170 candidates_[transport_name].insert(candidates_[transport_name].end(), |
| 179 candidates.begin(), candidates.end()); | 171 candidates.begin(), candidates.end()); |
| 180 ++candidates_signal_count_; | 172 ++candidates_signal_count_; |
| 181 } | 173 } |
| 182 | 174 |
| 183 std::unique_ptr<rtc::Thread> worker_thread_; // Not used for most tests. | 175 std::unique_ptr<rtc::Thread> worker_thread_; // Not used for most tests. |
| 184 std::unique_ptr<TransportControllerForTest> transport_controller_; | 176 std::unique_ptr<TransportControllerForTest> transport_controller_; |
| 185 | 177 |
| 186 // Information received from signals from transport controller. | 178 // Information received from signals from transport controller. |
| 187 IceConnectionState connection_state_ = cricket::kIceConnectionConnecting; | 179 IceConnectionState connection_state_ = kIceConnectionConnecting; |
| 188 bool receiving_ = false; | 180 bool receiving_ = false; |
| 189 IceGatheringState gathering_state_ = cricket::kIceGatheringNew; | 181 IceGatheringState gathering_state_ = kIceGatheringNew; |
| 190 // transport_name => candidates | 182 // transport_name => candidates |
| 191 std::map<std::string, Candidates> candidates_; | 183 std::map<std::string, Candidates> candidates_; |
| 192 // Counts of each signal emitted. | 184 // Counts of each signal emitted. |
| 193 int connection_state_signal_count_ = 0; | 185 int connection_state_signal_count_ = 0; |
| 194 int receiving_signal_count_ = 0; | 186 int receiving_signal_count_ = 0; |
| 195 int gathering_state_signal_count_ = 0; | 187 int gathering_state_signal_count_ = 0; |
| 196 int candidates_signal_count_ = 0; | 188 int candidates_signal_count_ = 0; |
| 197 | 189 |
| 198 // Used to make sure signals only come on signaling thread. | 190 // Used to make sure signals only come on signaling thread. |
| 199 rtc::Thread* const signaling_thread_ = nullptr; | 191 rtc::Thread* const signaling_thread_ = nullptr; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 225 | 217 |
| 226 // Setting max version after transport is created should fail. | 218 // Setting max version after transport is created should fail. |
| 227 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion( | 219 EXPECT_FALSE(transport_controller_->SetSslMaxProtocolVersion( |
| 228 rtc::SSL_PROTOCOL_DTLS_10)); | 220 rtc::SSL_PROTOCOL_DTLS_10)); |
| 229 } | 221 } |
| 230 | 222 |
| 231 TEST_F(TransportControllerTest, TestSetIceRole) { | 223 TEST_F(TransportControllerTest, TestSetIceRole) { |
| 232 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 224 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 233 ASSERT_NE(nullptr, channel1); | 225 ASSERT_NE(nullptr, channel1); |
| 234 | 226 |
| 235 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 227 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 236 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 228 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
| 237 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 229 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); |
| 238 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); | 230 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); |
| 239 | 231 |
| 240 // Test that value stored in controller is applied to new channels. | 232 // Test that value stored in controller is applied to new channels. |
| 241 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 233 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 242 ASSERT_NE(nullptr, channel2); | 234 ASSERT_NE(nullptr, channel2); |
| 243 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 235 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); |
| 244 } | 236 } |
| 245 | 237 |
| 246 // Test that when one channel encounters a role conflict, the ICE role is | 238 // Test that when one channel encounters a role conflict, the ICE role is |
| 247 // swapped on every channel. | 239 // swapped on every channel. |
| 248 TEST_F(TransportControllerTest, TestIceRoleConflict) { | 240 TEST_F(TransportControllerTest, TestIceRoleConflict) { |
| 249 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 241 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 250 ASSERT_NE(nullptr, channel1); | 242 ASSERT_NE(nullptr, channel1); |
| 251 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 243 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 252 ASSERT_NE(nullptr, channel2); | 244 ASSERT_NE(nullptr, channel2); |
| 253 | 245 |
| 254 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 246 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 255 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 247 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
| 256 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); | 248 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); |
| 257 | 249 |
| 258 channel1->SignalRoleConflict(channel1); | 250 channel1->SignalRoleConflict(channel1); |
| 259 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); | 251 EXPECT_EQ(ICEROLE_CONTROLLED, channel1->GetIceRole()); |
| 260 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 252 EXPECT_EQ(ICEROLE_CONTROLLED, channel2->GetIceRole()); |
| 261 | 253 |
| 262 // Should be able to handle a second role conflict. The remote endpoint can | 254 // Should be able to handle a second role conflict. The remote endpoint can |
| 263 // change its role/tie-breaker when it does an ICE restart. | 255 // change its role/tie-breaker when it does an ICE restart. |
| 264 channel2->SignalRoleConflict(channel2); | 256 channel2->SignalRoleConflict(channel2); |
| 265 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 257 EXPECT_EQ(ICEROLE_CONTROLLING, channel1->GetIceRole()); |
| 266 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); | 258 EXPECT_EQ(ICEROLE_CONTROLLING, channel2->GetIceRole()); |
| 267 } | 259 } |
| 268 | 260 |
| 269 TEST_F(TransportControllerTest, TestGetSslRole) { | 261 TEST_F(TransportControllerTest, TestGetSslRole) { |
| 270 FakeTransportChannel* channel = CreateChannel("audio", 1); | 262 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 271 ASSERT_NE(nullptr, channel); | 263 ASSERT_NE(nullptr, channel); |
| 272 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT)); | 264 ASSERT_TRUE(channel->SetSslRole(rtc::SSL_CLIENT)); |
| 273 rtc::SSLRole role; | 265 rtc::SSLRole role; |
| 274 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role)); | 266 EXPECT_FALSE(transport_controller_->GetSslRole("video", &role)); |
| 275 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role)); | 267 EXPECT_TRUE(transport_controller_->GetSslRole("audio", &role)); |
| 276 EXPECT_EQ(rtc::SSL_CLIENT, role); | 268 EXPECT_EQ(rtc::SSL_CLIENT, role); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 returned_certificate->ToPEMString()); | 316 returned_certificate->ToPEMString()); |
| 325 | 317 |
| 326 // Should fail if called for a nonexistant transport. | 318 // Should fail if called for a nonexistant transport. |
| 327 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video")); | 319 EXPECT_FALSE(transport_controller_->GetRemoteSSLCertificate("video")); |
| 328 } | 320 } |
| 329 | 321 |
| 330 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) { | 322 TEST_F(TransportControllerTest, TestSetLocalTransportDescription) { |
| 331 FakeTransportChannel* channel = CreateChannel("audio", 1); | 323 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 332 ASSERT_NE(nullptr, channel); | 324 ASSERT_NE(nullptr, channel); |
| 333 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, | 325 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, |
| 334 kIcePwd1, cricket::ICEMODE_FULL, | 326 kIcePwd1, ICEMODE_FULL, |
| 335 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 327 CONNECTIONROLE_ACTPASS, nullptr); |
| 336 std::string err; | 328 std::string err; |
| 337 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 329 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 338 "audio", local_desc, cricket::CA_OFFER, &err)); | 330 "audio", local_desc, CA_OFFER, &err)); |
| 339 // Check that ICE ufrag and pwd were propagated to channel. | 331 // Check that ICE ufrag and pwd were propagated to channel. |
| 340 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag()); | 332 EXPECT_EQ(kIceUfrag1, channel->ice_ufrag()); |
| 341 EXPECT_EQ(kIcePwd1, channel->ice_pwd()); | 333 EXPECT_EQ(kIcePwd1, channel->ice_pwd()); |
| 342 // After setting local description, we should be able to start gathering | 334 // After setting local description, we should be able to start gathering |
| 343 // candidates. | 335 // candidates. |
| 344 transport_controller_->MaybeStartGathering(); | 336 transport_controller_->MaybeStartGathering(); |
| 345 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 337 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
| 346 EXPECT_EQ(1, gathering_state_signal_count_); | 338 EXPECT_EQ(1, gathering_state_signal_count_); |
| 347 } | 339 } |
| 348 | 340 |
| 349 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) { | 341 TEST_F(TransportControllerTest, TestSetRemoteTransportDescription) { |
| 350 FakeTransportChannel* channel = CreateChannel("audio", 1); | 342 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 351 ASSERT_NE(nullptr, channel); | 343 ASSERT_NE(nullptr, channel); |
| 352 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, | 344 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
| 353 kIcePwd1, cricket::ICEMODE_FULL, | 345 kIcePwd1, ICEMODE_FULL, |
| 354 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 346 CONNECTIONROLE_ACTPASS, nullptr); |
| 355 std::string err; | 347 std::string err; |
| 356 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( | 348 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
| 357 "audio", remote_desc, cricket::CA_OFFER, &err)); | 349 "audio", remote_desc, CA_OFFER, &err)); |
| 358 // Check that ICE ufrag and pwd were propagated to channel. | 350 // Check that ICE ufrag and pwd were propagated to channel. |
| 359 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag()); | 351 EXPECT_EQ(kIceUfrag1, channel->remote_ice_ufrag()); |
| 360 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd()); | 352 EXPECT_EQ(kIcePwd1, channel->remote_ice_pwd()); |
| 361 } | 353 } |
| 362 | 354 |
| 363 TEST_F(TransportControllerTest, TestAddRemoteCandidates) { | 355 TEST_F(TransportControllerTest, TestAddRemoteCandidates) { |
| 364 FakeTransportChannel* channel = CreateChannel("audio", 1); | 356 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 365 ASSERT_NE(nullptr, channel); | 357 ASSERT_NE(nullptr, channel); |
| 366 Candidates candidates; | 358 Candidates candidates; |
| 367 candidates.push_back(CreateCandidate(1)); | 359 candidates.push_back(CreateCandidate(1)); |
| 368 std::string err; | 360 std::string err; |
| 369 EXPECT_TRUE( | 361 EXPECT_TRUE( |
| 370 transport_controller_->AddRemoteCandidates("audio", candidates, &err)); | 362 transport_controller_->AddRemoteCandidates("audio", candidates, &err)); |
| 371 EXPECT_EQ(1U, channel->remote_candidates().size()); | 363 EXPECT_EQ(1U, channel->remote_candidates().size()); |
| 372 } | 364 } |
| 373 | 365 |
| 374 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) { | 366 TEST_F(TransportControllerTest, TestReadyForRemoteCandidates) { |
| 375 FakeTransportChannel* channel = CreateChannel("audio", 1); | 367 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 376 ASSERT_NE(nullptr, channel); | 368 ASSERT_NE(nullptr, channel); |
| 377 // We expect to be ready for remote candidates only after local and remote | 369 // We expect to be ready for remote candidates only after local and remote |
| 378 // descriptions are set. | 370 // descriptions are set. |
| 379 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); | 371 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); |
| 380 | 372 |
| 381 std::string err; | 373 std::string err; |
| 382 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, | 374 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
| 383 kIcePwd1, cricket::ICEMODE_FULL, | 375 kIcePwd1, ICEMODE_FULL, |
| 384 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 376 CONNECTIONROLE_ACTPASS, nullptr); |
| 385 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( | 377 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
| 386 "audio", remote_desc, cricket::CA_OFFER, &err)); | 378 "audio", remote_desc, CA_OFFER, &err)); |
| 387 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); | 379 EXPECT_FALSE(transport_controller_->ReadyForRemoteCandidates("audio")); |
| 388 | 380 |
| 389 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, | 381 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, |
| 390 kIcePwd2, cricket::ICEMODE_FULL, | 382 kIcePwd2, ICEMODE_FULL, |
| 391 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 383 CONNECTIONROLE_ACTPASS, nullptr); |
| 392 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 384 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 393 "audio", local_desc, cricket::CA_ANSWER, &err)); | 385 "audio", local_desc, CA_ANSWER, &err)); |
| 394 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio")); | 386 EXPECT_TRUE(transport_controller_->ReadyForRemoteCandidates("audio")); |
| 395 } | 387 } |
| 396 | 388 |
| 397 TEST_F(TransportControllerTest, TestGetStats) { | 389 TEST_F(TransportControllerTest, TestGetStats) { |
| 398 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 390 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 399 ASSERT_NE(nullptr, channel1); | 391 ASSERT_NE(nullptr, channel1); |
| 400 FakeTransportChannel* channel2 = CreateChannel("audio", 2); | 392 FakeTransportChannel* channel2 = CreateChannel("audio", 2); |
| 401 ASSERT_NE(nullptr, channel2); | 393 ASSERT_NE(nullptr, channel2); |
| 402 FakeTransportChannel* channel3 = CreateChannel("video", 1); | 394 FakeTransportChannel* channel3 = CreateChannel("video", 1); |
| 403 ASSERT_NE(nullptr, channel3); | 395 ASSERT_NE(nullptr, channel3); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 424 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); | 416 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); |
| 425 DestroyChannel("audio", 2); | 417 DestroyChannel("audio", 2); |
| 426 DestroyChannel("audio", 1); | 418 DestroyChannel("audio", 1); |
| 427 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); | 419 EXPECT_TRUE(transport_controller_->GetStats("audio", &stats)); |
| 428 DestroyChannel("audio", 1); | 420 DestroyChannel("audio", 1); |
| 429 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats)); | 421 EXPECT_FALSE(transport_controller_->GetStats("audio", &stats)); |
| 430 } | 422 } |
| 431 | 423 |
| 432 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) { | 424 TEST_F(TransportControllerTest, TestSignalConnectionStateFailed) { |
| 433 // Need controlling ICE role to get in failed state. | 425 // Need controlling ICE role to get in failed state. |
| 434 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 426 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 435 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 427 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 436 ASSERT_NE(nullptr, channel1); | 428 ASSERT_NE(nullptr, channel1); |
| 437 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 429 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 438 ASSERT_NE(nullptr, channel2); | 430 ASSERT_NE(nullptr, channel2); |
| 439 | 431 |
| 440 // Should signal "failed" if any channel failed; channel is considered failed | 432 // Should signal "failed" if any channel failed; channel is considered failed |
| 441 // if it previously had a connection but now has none, and gathering is | 433 // if it previously had a connection but now has none, and gathering is |
| 442 // complete. | 434 // complete. |
| 443 channel1->SetCandidatesGatheringComplete(); | 435 channel1->SetCandidatesGatheringComplete(); |
| 444 channel1->SetConnectionCount(1); | 436 channel1->SetConnectionCount(1); |
| 445 channel1->SetConnectionCount(0); | 437 channel1->SetConnectionCount(0); |
| 446 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 438 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
| 447 EXPECT_EQ(1, connection_state_signal_count_); | 439 EXPECT_EQ(1, connection_state_signal_count_); |
| 448 } | 440 } |
| 449 | 441 |
| 450 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) { | 442 TEST_F(TransportControllerTest, TestSignalConnectionStateConnected) { |
| 451 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 443 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 452 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 444 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 453 ASSERT_NE(nullptr, channel1); | 445 ASSERT_NE(nullptr, channel1); |
| 454 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 446 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 455 ASSERT_NE(nullptr, channel2); | 447 ASSERT_NE(nullptr, channel2); |
| 456 FakeTransportChannel* channel3 = CreateChannel("video", 2); | 448 FakeTransportChannel* channel3 = CreateChannel("video", 2); |
| 457 ASSERT_NE(nullptr, channel3); | 449 ASSERT_NE(nullptr, channel3); |
| 458 | 450 |
| 459 // First, have one channel connect, and another fail, to ensure that | 451 // First, have one channel connect, and another fail, to ensure that |
| 460 // the first channel connecting didn't trigger a "connected" state signal. | 452 // the first channel connecting didn't trigger a "connected" state signal. |
| 461 // We should only get a signal when all are connected. | 453 // We should only get a signal when all are connected. |
| 462 channel1->SetConnectionCount(2); | 454 channel1->SetConnectionCount(2); |
| 463 channel1->SetWritable(true); | 455 channel1->SetWritable(true); |
| 464 channel3->SetCandidatesGatheringComplete(); | 456 channel3->SetCandidatesGatheringComplete(); |
| 465 channel3->SetConnectionCount(1); | 457 channel3->SetConnectionCount(1); |
| 466 channel3->SetConnectionCount(0); | 458 channel3->SetConnectionCount(0); |
| 467 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 459 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
| 468 // Signal count of 1 means that the only signal emitted was "failed". | 460 // Signal count of 1 means that the only signal emitted was "failed". |
| 469 EXPECT_EQ(1, connection_state_signal_count_); | 461 EXPECT_EQ(1, connection_state_signal_count_); |
| 470 | 462 |
| 471 // Destroy the failed channel to return to "connecting" state. | 463 // Destroy the failed channel to return to "connecting" state. |
| 472 DestroyChannel("video", 2); | 464 DestroyChannel("video", 2); |
| 473 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 465 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
| 474 kTimeout); | |
| 475 EXPECT_EQ(2, connection_state_signal_count_); | 466 EXPECT_EQ(2, connection_state_signal_count_); |
| 476 | 467 |
| 477 // Make the remaining channel reach a connected state. | 468 // Make the remaining channel reach a connected state. |
| 478 channel2->SetConnectionCount(2); | 469 channel2->SetConnectionCount(2); |
| 479 channel2->SetWritable(true); | 470 channel2->SetWritable(true); |
| 480 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 471 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
| 481 EXPECT_EQ(3, connection_state_signal_count_); | 472 EXPECT_EQ(3, connection_state_signal_count_); |
| 482 } | 473 } |
| 483 | 474 |
| 484 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) { | 475 TEST_F(TransportControllerTest, TestSignalConnectionStateComplete) { |
| 485 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 476 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 486 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 477 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 487 ASSERT_NE(nullptr, channel1); | 478 ASSERT_NE(nullptr, channel1); |
| 488 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 479 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 489 ASSERT_NE(nullptr, channel2); | 480 ASSERT_NE(nullptr, channel2); |
| 490 FakeTransportChannel* channel3 = CreateChannel("video", 2); | 481 FakeTransportChannel* channel3 = CreateChannel("video", 2); |
| 491 ASSERT_NE(nullptr, channel3); | 482 ASSERT_NE(nullptr, channel3); |
| 492 | 483 |
| 493 // Similar to above test, but we're now reaching the completed state, which | 484 // Similar to above test, but we're now reaching the completed state, which |
| 494 // means only one connection per FakeTransportChannel. | 485 // means only one connection per FakeTransportChannel. |
| 495 channel1->SetCandidatesGatheringComplete(); | 486 channel1->SetCandidatesGatheringComplete(); |
| 496 channel1->SetConnectionCount(1); | 487 channel1->SetConnectionCount(1); |
| 497 channel1->SetWritable(true); | 488 channel1->SetWritable(true); |
| 498 channel3->SetCandidatesGatheringComplete(); | 489 channel3->SetCandidatesGatheringComplete(); |
| 499 channel3->SetConnectionCount(1); | 490 channel3->SetConnectionCount(1); |
| 500 channel3->SetConnectionCount(0); | 491 channel3->SetConnectionCount(0); |
| 501 EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout); | 492 EXPECT_EQ_WAIT(kIceConnectionFailed, connection_state_, kTimeout); |
| 502 // Signal count of 1 means that the only signal emitted was "failed". | 493 // Signal count of 1 means that the only signal emitted was "failed". |
| 503 EXPECT_EQ(1, connection_state_signal_count_); | 494 EXPECT_EQ(1, connection_state_signal_count_); |
| 504 | 495 |
| 505 // Destroy the failed channel to return to "connecting" state. | 496 // Destroy the failed channel to return to "connecting" state. |
| 506 DestroyChannel("video", 2); | 497 DestroyChannel("video", 2); |
| 507 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 498 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
| 508 kTimeout); | |
| 509 EXPECT_EQ(2, connection_state_signal_count_); | 499 EXPECT_EQ(2, connection_state_signal_count_); |
| 510 | 500 |
| 511 // Make the remaining channel reach a connected state. | 501 // Make the remaining channel reach a connected state. |
| 512 channel2->SetCandidatesGatheringComplete(); | 502 channel2->SetCandidatesGatheringComplete(); |
| 513 channel2->SetConnectionCount(2); | 503 channel2->SetConnectionCount(2); |
| 514 channel2->SetWritable(true); | 504 channel2->SetWritable(true); |
| 515 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 505 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
| 516 EXPECT_EQ(3, connection_state_signal_count_); | 506 EXPECT_EQ(3, connection_state_signal_count_); |
| 517 | 507 |
| 518 // Finally, transition to completed state. | 508 // Finally, transition to completed state. |
| 519 channel2->SetConnectionCount(1); | 509 channel2->SetConnectionCount(1); |
| 520 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 510 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
| 521 EXPECT_EQ(4, connection_state_signal_count_); | 511 EXPECT_EQ(4, connection_state_signal_count_); |
| 522 } | 512 } |
| 523 | 513 |
| 524 // Make sure that if we're "connected" and remove a transport, we stay in the | 514 // Make sure that if we're "connected" and remove a transport, we stay in the |
| 525 // "connected" state. | 515 // "connected" state. |
| 526 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) { | 516 TEST_F(TransportControllerTest, TestDestroyTransportAndStayConnected) { |
| 527 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 517 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 528 ASSERT_NE(nullptr, channel1); | 518 ASSERT_NE(nullptr, channel1); |
| 529 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 519 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 530 ASSERT_NE(nullptr, channel2); | 520 ASSERT_NE(nullptr, channel2); |
| 531 | 521 |
| 532 channel1->SetCandidatesGatheringComplete(); | 522 channel1->SetCandidatesGatheringComplete(); |
| 533 channel1->SetConnectionCount(2); | 523 channel1->SetConnectionCount(2); |
| 534 channel1->SetWritable(true); | 524 channel1->SetWritable(true); |
| 535 channel2->SetCandidatesGatheringComplete(); | 525 channel2->SetCandidatesGatheringComplete(); |
| 536 channel2->SetConnectionCount(2); | 526 channel2->SetConnectionCount(2); |
| 537 channel2->SetWritable(true); | 527 channel2->SetWritable(true); |
| 538 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 528 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
| 539 EXPECT_EQ(1, connection_state_signal_count_); | 529 EXPECT_EQ(1, connection_state_signal_count_); |
| 540 | 530 |
| 541 // Destroy one channel, then "complete" the other one, so we reach | 531 // Destroy one channel, then "complete" the other one, so we reach |
| 542 // a known state. | 532 // a known state. |
| 543 DestroyChannel("video", 1); | 533 DestroyChannel("video", 1); |
| 544 channel1->SetConnectionCount(1); | 534 channel1->SetConnectionCount(1); |
| 545 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 535 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
| 546 // Signal count of 2 means the deletion didn't cause any unexpected signals | 536 // Signal count of 2 means the deletion didn't cause any unexpected signals |
| 547 EXPECT_EQ(2, connection_state_signal_count_); | 537 EXPECT_EQ(2, connection_state_signal_count_); |
| 548 } | 538 } |
| 549 | 539 |
| 550 // If we destroy the last/only transport, we should simply transition to | 540 // If we destroy the last/only transport, we should simply transition to |
| 551 // "connecting". | 541 // "connecting". |
| 552 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) { | 542 TEST_F(TransportControllerTest, TestDestroyLastTransportWhileConnected) { |
| 553 FakeTransportChannel* channel = CreateChannel("audio", 1); | 543 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 554 ASSERT_NE(nullptr, channel); | 544 ASSERT_NE(nullptr, channel); |
| 555 | 545 |
| 556 channel->SetCandidatesGatheringComplete(); | 546 channel->SetCandidatesGatheringComplete(); |
| 557 channel->SetConnectionCount(2); | 547 channel->SetConnectionCount(2); |
| 558 channel->SetWritable(true); | 548 channel->SetWritable(true); |
| 559 EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout); | 549 EXPECT_EQ_WAIT(kIceConnectionConnected, connection_state_, kTimeout); |
| 560 EXPECT_EQ(1, connection_state_signal_count_); | 550 EXPECT_EQ(1, connection_state_signal_count_); |
| 561 | 551 |
| 562 DestroyChannel("audio", 1); | 552 DestroyChannel("audio", 1); |
| 563 EXPECT_EQ_WAIT(cricket::kIceConnectionConnecting, connection_state_, | 553 EXPECT_EQ_WAIT(kIceConnectionConnecting, connection_state_, kTimeout); |
| 564 kTimeout); | |
| 565 // Signal count of 2 means the deletion didn't cause any unexpected signals | 554 // Signal count of 2 means the deletion didn't cause any unexpected signals |
| 566 EXPECT_EQ(2, connection_state_signal_count_); | 555 EXPECT_EQ(2, connection_state_signal_count_); |
| 567 } | 556 } |
| 568 | 557 |
| 569 TEST_F(TransportControllerTest, TestSignalReceiving) { | 558 TEST_F(TransportControllerTest, TestSignalReceiving) { |
| 570 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 559 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 571 ASSERT_NE(nullptr, channel1); | 560 ASSERT_NE(nullptr, channel1); |
| 572 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 561 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 573 ASSERT_NE(nullptr, channel2); | 562 ASSERT_NE(nullptr, channel2); |
| 574 | 563 |
| 575 // Should signal receiving as soon as any channel is receiving. | 564 // Should signal receiving as soon as any channel is receiving. |
| 576 channel1->SetReceiving(true); | 565 channel1->SetReceiving(true); |
| 577 EXPECT_TRUE_WAIT(receiving_, kTimeout); | 566 EXPECT_TRUE_WAIT(receiving_, kTimeout); |
| 578 EXPECT_EQ(1, receiving_signal_count_); | 567 EXPECT_EQ(1, receiving_signal_count_); |
| 579 | 568 |
| 580 channel2->SetReceiving(true); | 569 channel2->SetReceiving(true); |
| 581 channel1->SetReceiving(false); | 570 channel1->SetReceiving(false); |
| 582 channel2->SetReceiving(false); | 571 channel2->SetReceiving(false); |
| 583 EXPECT_TRUE_WAIT(!receiving_, kTimeout); | 572 EXPECT_TRUE_WAIT(!receiving_, kTimeout); |
| 584 EXPECT_EQ(2, receiving_signal_count_); | 573 EXPECT_EQ(2, receiving_signal_count_); |
| 585 } | 574 } |
| 586 | 575 |
| 587 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) { | 576 TEST_F(TransportControllerTest, TestSignalGatheringStateGathering) { |
| 588 FakeTransportChannel* channel = CreateChannel("audio", 1); | 577 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 589 ASSERT_NE(nullptr, channel); | 578 ASSERT_NE(nullptr, channel); |
| 590 channel->Connect(); | 579 channel->Connect(); |
| 591 channel->MaybeStartGathering(); | 580 channel->MaybeStartGathering(); |
| 592 // Should be in the gathering state as soon as any transport starts gathering. | 581 // Should be in the gathering state as soon as any transport starts gathering. |
| 593 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 582 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
| 594 EXPECT_EQ(1, gathering_state_signal_count_); | 583 EXPECT_EQ(1, gathering_state_signal_count_); |
| 595 } | 584 } |
| 596 | 585 |
| 597 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) { | 586 TEST_F(TransportControllerTest, TestSignalGatheringStateComplete) { |
| 598 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 587 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 599 ASSERT_NE(nullptr, channel1); | 588 ASSERT_NE(nullptr, channel1); |
| 600 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 589 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 601 ASSERT_NE(nullptr, channel2); | 590 ASSERT_NE(nullptr, channel2); |
| 602 FakeTransportChannel* channel3 = CreateChannel("data", 1); | 591 FakeTransportChannel* channel3 = CreateChannel("data", 1); |
| 603 ASSERT_NE(nullptr, channel3); | 592 ASSERT_NE(nullptr, channel3); |
| 604 | 593 |
| 605 channel3->Connect(); | 594 channel3->Connect(); |
| 606 channel3->MaybeStartGathering(); | 595 channel3->MaybeStartGathering(); |
| 607 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 596 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
| 608 EXPECT_EQ(1, gathering_state_signal_count_); | 597 EXPECT_EQ(1, gathering_state_signal_count_); |
| 609 | 598 |
| 610 // Have one channel finish gathering, then destroy it, to make sure gathering | 599 // Have one channel finish gathering, then destroy it, to make sure gathering |
| 611 // completion wasn't signalled if only one transport finished gathering. | 600 // completion wasn't signalled if only one transport finished gathering. |
| 612 channel3->SetCandidatesGatheringComplete(); | 601 channel3->SetCandidatesGatheringComplete(); |
| 613 DestroyChannel("data", 1); | 602 DestroyChannel("data", 1); |
| 614 EXPECT_EQ_WAIT(cricket::kIceGatheringNew, gathering_state_, kTimeout); | 603 EXPECT_EQ_WAIT(kIceGatheringNew, gathering_state_, kTimeout); |
| 615 EXPECT_EQ(2, gathering_state_signal_count_); | 604 EXPECT_EQ(2, gathering_state_signal_count_); |
| 616 | 605 |
| 617 // Make remaining channels start and then finish gathering. | 606 // Make remaining channels start and then finish gathering. |
| 618 channel1->Connect(); | 607 channel1->Connect(); |
| 619 channel1->MaybeStartGathering(); | 608 channel1->MaybeStartGathering(); |
| 620 channel2->Connect(); | 609 channel2->Connect(); |
| 621 channel2->MaybeStartGathering(); | 610 channel2->MaybeStartGathering(); |
| 622 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 611 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
| 623 EXPECT_EQ(3, gathering_state_signal_count_); | 612 EXPECT_EQ(3, gathering_state_signal_count_); |
| 624 | 613 |
| 625 channel1->SetCandidatesGatheringComplete(); | 614 channel1->SetCandidatesGatheringComplete(); |
| 626 channel2->SetCandidatesGatheringComplete(); | 615 channel2->SetCandidatesGatheringComplete(); |
| 627 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 616 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
| 628 EXPECT_EQ(4, gathering_state_signal_count_); | 617 EXPECT_EQ(4, gathering_state_signal_count_); |
| 629 } | 618 } |
| 630 | 619 |
| 631 // Test that when the last transport that hasn't finished connecting and/or | 620 // 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 | 621 // 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 | 622 // 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. | 623 // transport completes, then we start bundling video on the audio transport. |
| 635 TEST_F(TransportControllerTest, | 624 TEST_F(TransportControllerTest, |
| 636 TestSignalingWhenLastIncompleteTransportDestroyed) { | 625 TestSignalingWhenLastIncompleteTransportDestroyed) { |
| 637 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 626 transport_controller_->SetIceRole(ICEROLE_CONTROLLING); |
| 638 FakeTransportChannel* channel1 = CreateChannel("audio", 1); | 627 FakeTransportChannel* channel1 = CreateChannel("audio", 1); |
| 639 ASSERT_NE(nullptr, channel1); | 628 ASSERT_NE(nullptr, channel1); |
| 640 FakeTransportChannel* channel2 = CreateChannel("video", 1); | 629 FakeTransportChannel* channel2 = CreateChannel("video", 1); |
| 641 ASSERT_NE(nullptr, channel2); | 630 ASSERT_NE(nullptr, channel2); |
| 642 | 631 |
| 643 channel1->SetCandidatesGatheringComplete(); | 632 channel1->SetCandidatesGatheringComplete(); |
| 644 EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout); | 633 EXPECT_EQ_WAIT(kIceGatheringGathering, gathering_state_, kTimeout); |
| 645 EXPECT_EQ(1, gathering_state_signal_count_); | 634 EXPECT_EQ(1, gathering_state_signal_count_); |
| 646 | 635 |
| 647 channel1->SetConnectionCount(1); | 636 channel1->SetConnectionCount(1); |
| 648 channel1->SetWritable(true); | 637 channel1->SetWritable(true); |
| 649 DestroyChannel("video", 1); | 638 DestroyChannel("video", 1); |
| 650 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 639 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
| 651 EXPECT_EQ(1, connection_state_signal_count_); | 640 EXPECT_EQ(1, connection_state_signal_count_); |
| 652 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 641 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
| 653 EXPECT_EQ(2, gathering_state_signal_count_); | 642 EXPECT_EQ(2, gathering_state_signal_count_); |
| 654 } | 643 } |
| 655 | 644 |
| 656 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) { | 645 TEST_F(TransportControllerTest, TestSignalCandidatesGathered) { |
| 657 FakeTransportChannel* channel = CreateChannel("audio", 1); | 646 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 658 ASSERT_NE(nullptr, channel); | 647 ASSERT_NE(nullptr, channel); |
| 659 | 648 |
| 660 // Transport won't signal candidates until it has a local description. | 649 // Transport won't signal candidates until it has a local description. |
| 661 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, | 650 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag1, |
| 662 kIcePwd1, cricket::ICEMODE_FULL, | 651 kIcePwd1, ICEMODE_FULL, |
| 663 cricket::CONNECTIONROLE_ACTPASS, nullptr); | 652 CONNECTIONROLE_ACTPASS, nullptr); |
| 664 std::string err; | 653 std::string err; |
| 665 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( | 654 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 666 "audio", local_desc, cricket::CA_OFFER, &err)); | 655 "audio", local_desc, CA_OFFER, &err)); |
| 667 transport_controller_->MaybeStartGathering(); | 656 transport_controller_->MaybeStartGathering(); |
| 668 | 657 |
| 669 channel->SignalCandidateGathered(channel, CreateCandidate(1)); | 658 channel->SignalCandidateGathered(channel, CreateCandidate(1)); |
| 670 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout); | 659 EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout); |
| 671 EXPECT_EQ(1U, candidates_["audio"].size()); | 660 EXPECT_EQ(1U, candidates_["audio"].size()); |
| 672 } | 661 } |
| 673 | 662 |
| 674 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) { | 663 TEST_F(TransportControllerTest, TestSignalingOccursOnSignalingThread) { |
| 675 CreateTransportControllerWithWorkerThread(); | 664 CreateTransportControllerWithWorkerThread(); |
| 676 CreateChannelsAndCompleteConnectionOnWorkerThread(); | 665 CreateChannelsAndCompleteConnectionOnWorkerThread(); |
| 677 | 666 |
| 678 // connecting --> connected --> completed | 667 // connecting --> connected --> completed |
| 679 EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout); | 668 EXPECT_EQ_WAIT(kIceConnectionCompleted, connection_state_, kTimeout); |
| 680 EXPECT_EQ(2, connection_state_signal_count_); | 669 EXPECT_EQ(2, connection_state_signal_count_); |
| 681 | 670 |
| 682 EXPECT_TRUE_WAIT(receiving_, kTimeout); | 671 EXPECT_TRUE_WAIT(receiving_, kTimeout); |
| 683 EXPECT_EQ(1, receiving_signal_count_); | 672 EXPECT_EQ(1, receiving_signal_count_); |
| 684 | 673 |
| 685 // new --> gathering --> complete | 674 // new --> gathering --> complete |
| 686 EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout); | 675 EXPECT_EQ_WAIT(kIceGatheringComplete, gathering_state_, kTimeout); |
| 687 EXPECT_EQ(2, gathering_state_signal_count_); | 676 EXPECT_EQ(2, gathering_state_signal_count_); |
| 688 | 677 |
| 689 EXPECT_EQ_WAIT(1U, candidates_["audio"].size(), kTimeout); | 678 EXPECT_EQ_WAIT(1U, candidates_["audio"].size(), kTimeout); |
| 690 EXPECT_EQ_WAIT(1U, candidates_["video"].size(), kTimeout); | 679 EXPECT_EQ_WAIT(1U, candidates_["video"].size(), kTimeout); |
| 691 EXPECT_EQ(2, candidates_signal_count_); | 680 EXPECT_EQ(2, candidates_signal_count_); |
| 692 | 681 |
| 693 EXPECT_TRUE(!signaled_on_non_signaling_thread_); | 682 EXPECT_TRUE(!signaled_on_non_signaling_thread_); |
| 694 } | 683 } |
| 684 |
| 685 // Older versions of Chrome expect the ICE role to be re-determined when an |
| 686 // ICE restart occurs, and also don't perform conflict resolution correctly, |
| 687 // so for now we can't safely stop doing this. |
| 688 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=628676 |
| 689 // TODO(deadbeef): Remove this when these old versions of Chrome reach a low |
| 690 // enough population. |
| 691 TEST_F(TransportControllerTest, IceRoleRedeterminedOnIceRestart) { |
| 692 FakeTransportChannel* channel = CreateChannel("audio", 1); |
| 693 ASSERT_NE(nullptr, channel); |
| 694 std::string err; |
| 695 // Do an initial offer answer, so that the next offer is an ICE restart. |
| 696 transport_controller_->SetIceRole(ICEROLE_CONTROLLED); |
| 697 TransportDescription remote_desc(std::vector<std::string>(), kIceUfrag1, |
| 698 kIcePwd1, ICEMODE_FULL, |
| 699 CONNECTIONROLE_ACTPASS, nullptr); |
| 700 EXPECT_TRUE(transport_controller_->SetRemoteTransportDescription( |
| 701 "audio", remote_desc, CA_OFFER, &err)); |
| 702 TransportDescription local_desc(std::vector<std::string>(), kIceUfrag2, |
| 703 kIcePwd2, ICEMODE_FULL, |
| 704 CONNECTIONROLE_ACTPASS, nullptr); |
| 705 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 706 "audio", local_desc, CA_ANSWER, &err)); |
| 707 EXPECT_EQ(ICEROLE_CONTROLLED, channel->GetIceRole()); |
| 708 |
| 709 // The endpoint that initiated an ICE restart should take the controlling |
| 710 // role. |
| 711 TransportDescription ice_restart_desc(std::vector<std::string>(), kIceUfrag3, |
| 712 kIcePwd3, ICEMODE_FULL, |
| 713 CONNECTIONROLE_ACTPASS, nullptr); |
| 714 EXPECT_TRUE(transport_controller_->SetLocalTransportDescription( |
| 715 "audio", ice_restart_desc, CA_OFFER, &err)); |
| 716 EXPECT_EQ(ICEROLE_CONTROLLING, channel->GetIceRole()); |
| 717 } |
| 718 |
| 719 } // namespace cricket { |
| OLD | NEW |