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