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