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