OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/fakesslidentity.h" | 11 #include "webrtc/base/fakesslidentity.h" |
12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
13 #include "webrtc/base/network.h" | 13 #include "webrtc/base/network.h" |
14 #include "webrtc/p2p/base/faketransportcontroller.h" | 14 #include "webrtc/p2p/base/faketransportcontroller.h" |
15 #include "webrtc/p2p/base/p2ptransport.h" | 15 #include "webrtc/p2p/base/p2ptransport.h" |
16 | 16 |
17 using cricket::Candidate; | |
18 using cricket::Candidates; | |
19 using cricket::Transport; | 17 using cricket::Transport; |
20 using cricket::FakeTransport; | 18 using cricket::FakeTransport; |
21 using cricket::TransportChannel; | 19 using cricket::TransportChannel; |
22 using cricket::FakeTransportChannel; | 20 using cricket::FakeTransportChannel; |
23 using cricket::IceRole; | 21 using cricket::IceRole; |
24 using cricket::TransportDescription; | 22 using cricket::TransportDescription; |
25 using rtc::SocketAddress; | 23 using rtc::SocketAddress; |
26 | 24 |
27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 25 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 26 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 TEST_F(TransportTest, TestIceControllingOnIceRestartIfRemoteIsIceLite) { | 146 TEST_F(TransportTest, TestIceControllingOnIceRestartIfRemoteIsIceLite) { |
149 EXPECT_TRUE(SetupChannel()); | 147 EXPECT_TRUE(SetupChannel()); |
150 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 148 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
151 | 149 |
152 cricket::TransportDescription desc(kIceUfrag1, kIcePwd1); | 150 cricket::TransportDescription desc(kIceUfrag1, kIcePwd1); |
153 ASSERT_TRUE(transport_->SetLocalTransportDescription(desc, | 151 ASSERT_TRUE(transport_->SetLocalTransportDescription(desc, |
154 cricket::CA_OFFER, | 152 cricket::CA_OFFER, |
155 NULL)); | 153 NULL)); |
156 | 154 |
157 cricket::TransportDescription remote_desc( | 155 cricket::TransportDescription remote_desc( |
158 std::vector<std::string>(), | 156 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, |
159 kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, | 157 cricket::CONNECTIONROLE_NONE, NULL); |
160 cricket::CONNECTIONROLE_NONE, NULL, cricket::Candidates()); | |
161 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | 158 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, |
162 cricket::CA_ANSWER, | 159 cricket::CA_ANSWER, |
163 NULL)); | 160 NULL)); |
164 | 161 |
165 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 162 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
166 | 163 |
167 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2); | 164 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2); |
168 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc, | 165 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc, |
169 cricket::CA_ANSWER, | 166 cricket::CA_ANSWER, |
170 NULL)); | 167 NULL)); |
171 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 168 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
172 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); | 169 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); |
173 } | 170 } |
174 | 171 |
175 // Tests channel role is reversed after receiving ice-lite from remote. | 172 // Tests channel role is reversed after receiving ice-lite from remote. |
176 TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { | 173 TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { |
177 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 174 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
178 cricket::TransportDescription remote_desc( | 175 cricket::TransportDescription remote_desc( |
179 std::vector<std::string>(), | 176 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, |
180 kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, | 177 cricket::CONNECTIONROLE_ACTPASS, NULL); |
181 cricket::CONNECTIONROLE_ACTPASS, NULL, cricket::Candidates()); | |
182 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | 178 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, |
183 cricket::CA_OFFER, | 179 cricket::CA_OFFER, |
184 NULL)); | 180 NULL)); |
185 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | 181 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); |
186 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, | 182 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, |
187 cricket::CA_ANSWER, | 183 cricket::CA_ANSWER, |
188 NULL)); | 184 NULL)); |
189 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 185 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
190 EXPECT_TRUE(SetupChannel()); | 186 EXPECT_TRUE(SetupChannel()); |
191 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); | 187 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); |
192 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); | 188 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); |
193 } | 189 } |
194 | 190 |
195 // Tests ice-lite in remote answer. | 191 // Tests ice-lite in remote answer. |
196 TEST_F(TransportTest, TestSetRemoteIceLiteInAnswer) { | 192 TEST_F(TransportTest, TestSetRemoteIceLiteInAnswer) { |
197 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); | 193 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
198 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | 194 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); |
199 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, | 195 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, |
200 cricket::CA_OFFER, | 196 cricket::CA_OFFER, |
201 NULL)); | 197 NULL)); |
202 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); | 198 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); |
203 EXPECT_TRUE(SetupChannel()); | 199 EXPECT_TRUE(SetupChannel()); |
204 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); | 200 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); |
205 // Channels will be created in ICEFULL_MODE. | 201 // Channels will be created in ICEFULL_MODE. |
206 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); | 202 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); |
207 cricket::TransportDescription remote_desc( | 203 cricket::TransportDescription remote_desc( |
208 std::vector<std::string>(), | 204 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, |
209 kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, | 205 cricket::CONNECTIONROLE_NONE, NULL); |
210 cricket::CONNECTIONROLE_NONE, NULL, cricket::Candidates()); | |
211 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, | 206 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, |
212 cricket::CA_ANSWER, | 207 cricket::CA_ANSWER, |
213 NULL)); | 208 NULL)); |
214 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); | 209 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); |
215 // After receiving remote description with ICEMODE_LITE, channel should | 210 // After receiving remote description with ICEMODE_LITE, channel should |
216 // have mode set to ICEMODE_LITE. | 211 // have mode set to ICEMODE_LITE. |
217 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); | 212 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); |
218 } | 213 } |
219 | 214 |
220 TEST_F(TransportTest, TestGetStats) { | 215 TEST_F(TransportTest, TestGetStats) { |
221 EXPECT_TRUE(SetupChannel()); | 216 EXPECT_TRUE(SetupChannel()); |
222 cricket::TransportStats stats; | 217 cricket::TransportStats stats; |
223 EXPECT_TRUE(transport_->GetStats(&stats)); | 218 EXPECT_TRUE(transport_->GetStats(&stats)); |
224 // Note that this tests the behavior of a FakeTransportChannel. | 219 // Note that this tests the behavior of a FakeTransportChannel. |
225 ASSERT_EQ(1U, stats.channel_stats.size()); | 220 ASSERT_EQ(1U, stats.channel_stats.size()); |
226 EXPECT_EQ(1, stats.channel_stats[0].component); | 221 EXPECT_EQ(1, stats.channel_stats[0].component); |
227 transport_->ConnectChannels(); | 222 transport_->ConnectChannels(); |
228 EXPECT_TRUE(transport_->GetStats(&stats)); | 223 EXPECT_TRUE(transport_->GetStats(&stats)); |
229 ASSERT_EQ(1U, stats.channel_stats.size()); | 224 ASSERT_EQ(1U, stats.channel_stats.size()); |
230 EXPECT_EQ(1, stats.channel_stats[0].component); | 225 EXPECT_EQ(1, stats.channel_stats[0].component); |
231 } | 226 } |
232 | 227 |
OLD | NEW |