Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: webrtc/p2p/base/jseptransport_unittest.cc

Issue 2517883002: Refactoring that removes P2PTransport and DtlsTransport classes. (Closed)
Patch Set: Adding stub transport.h file for backwards compat. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/jseptransport.cc ('k') | webrtc/p2p/base/p2ptransport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 11 #include <memory>
12 12
13 #include "webrtc/base/fakesslidentity.h" 13 #include "webrtc/base/fakesslidentity.h"
14 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/network.h" 15 #include "webrtc/base/network.h"
16 #include "webrtc/p2p/base/faketransportcontroller.h" 16 #include "webrtc/p2p/base/faketransportcontroller.h"
17 #include "webrtc/p2p/base/p2ptransport.h"
18 17
19 using cricket::Transport; 18 using cricket::JsepTransport;
20 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";
29 27
30 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; 28 static const char kIceUfrag2[] = "TESTICEUFRAG0002";
31 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; 29 static const char kIcePwd2[] = "TESTICEPWD00000000000002";
32 30
33 class TransportTest : public testing::Test, 31 class JsepTransportTest : public testing::Test, public sigslot::has_slots<> {
34 public sigslot::has_slots<> {
35 public: 32 public:
36 TransportTest() 33 JsepTransportTest()
37 : transport_(new FakeTransport("test content name")), channel_(NULL) {} 34 : transport_(new JsepTransport("test content name", nullptr)) {}
38 ~TransportTest() { 35 bool SetupChannel() {
39 transport_->DestroyAllChannels(); 36 fake_ice_channel_.reset(new FakeTransportChannel(transport_->mid(), 1));
37 fake_dtls_channel_.reset(new FakeTransportChannel(transport_->mid(), 1));
38 return transport_->AddChannel(fake_dtls_channel_.get(), 1);
40 } 39 }
41 bool SetupChannel() { 40 void DestroyChannel() { transport_->RemoveChannel(1); }
42 channel_ = CreateChannel(1);
43 return (channel_ != NULL);
44 }
45 FakeTransportChannel* CreateChannel(int component) {
46 return static_cast<FakeTransportChannel*>(
47 transport_->CreateChannel(component));
48 }
49 void DestroyChannel() {
50 transport_->DestroyChannel(1);
51 channel_ = NULL;
52 }
53 41
54 protected: 42 protected:
55 std::unique_ptr<FakeTransport> transport_; 43 std::unique_ptr<FakeTransportChannel> fake_dtls_channel_;
56 FakeTransportChannel* channel_; 44 std::unique_ptr<FakeTransportChannel> fake_ice_channel_;
45 std::unique_ptr<JsepTransport> transport_;
57 }; 46 };
58 47
59 // This test verifies channels are created with proper ICE 48 // This test verifies channels are created with proper ICE
60 // role, tiebreaker and remote ice mode and credentials after offer and 49 // ufrag/password after a transport description is applied.
61 // answer negotiations. 50 TEST_F(JsepTransportTest, TestChannelIceParameters) {
62 TEST_F(TransportTest, TestChannelIceParameters) {
63 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
64 transport_->SetIceTiebreaker(99U);
65 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); 51 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1);
66 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, 52 ASSERT_TRUE(transport_->SetLocalTransportDescription(
67 cricket::CA_OFFER, 53 local_desc, cricket::CA_OFFER, NULL));
68 NULL));
69 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
70 EXPECT_TRUE(SetupChannel()); 54 EXPECT_TRUE(SetupChannel());
71 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); 55 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode());
72 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); 56 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->ice_ufrag());
73 EXPECT_EQ(kIceUfrag1, channel_->ice_ufrag()); 57 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->ice_pwd());
74 EXPECT_EQ(kIcePwd1, channel_->ice_pwd());
75 58
76 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); 59 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1);
77 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, 60 ASSERT_TRUE(transport_->SetRemoteTransportDescription(
78 cricket::CA_ANSWER, 61 remote_desc, cricket::CA_ANSWER, NULL));
79 NULL)); 62 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode());
80 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); 63 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->remote_ice_ufrag());
81 EXPECT_EQ(99U, channel_->IceTiebreaker()); 64 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->remote_ice_pwd());
82 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode());
83 // Changing the transport role from CONTROLLING to CONTROLLED.
84 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED);
85 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel_->GetIceRole());
86 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode());
87 EXPECT_EQ(kIceUfrag1, channel_->remote_ice_ufrag());
88 EXPECT_EQ(kIcePwd1, channel_->remote_ice_pwd());
89 } 65 }
90 66
91 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd 67 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd
92 // changed, and false in other cases. 68 // changed, and false in other cases.
93 TEST_F(TransportTest, TestIceCredentialsChanged) { 69 TEST_F(JsepTransportTest, TestIceCredentialsChanged) {
94 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2")); 70 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2"));
95 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1")); 71 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1"));
96 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2")); 72 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2"));
97 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1")); 73 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1"));
98 } 74 }
99 75
100 // This test verifies that the callee's ICE role remains the same when the 76 TEST_F(JsepTransportTest, TestGetStats) {
101 // callee triggers an ICE restart.
102 //
103 // RFC5245 currently says that the role *should* change on an ICE restart,
104 // but this rule was intended for an ICE restart that occurs when an endpoint
105 // is changing to ICE lite (which we already handle). See discussion here:
106 // https://mailarchive.ietf.org/arch/msg/ice/C0_QRCTNcwtvUF12y28jQicPR10
107 TEST_F(TransportTest, TestIceControlledToControllingOnIceRestart) {
108 EXPECT_TRUE(SetupChannel());
109 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED);
110
111 cricket::TransportDescription desc(kIceUfrag1, kIcePwd1);
112 ASSERT_TRUE(transport_->SetRemoteTransportDescription(desc,
113 cricket::CA_OFFER,
114 NULL));
115 ASSERT_TRUE(transport_->SetLocalTransportDescription(desc,
116 cricket::CA_ANSWER,
117 NULL));
118 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, transport_->ice_role());
119
120 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2);
121 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc,
122 cricket::CA_OFFER,
123 NULL));
124 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, transport_->ice_role());
125 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel_->GetIceRole());
126 }
127
128 // This test verifies that the caller's ICE role remains the same when the
129 // callee triggers an ICE restart.
130 //
131 // RFC5245 currently says that the role *should* change on an ICE restart,
132 // but this rule was intended for an ICE restart that occurs when an endpoint
133 // is changing to ICE lite (which we already handle). See discussion here:
134 // https://mailarchive.ietf.org/arch/msg/ice/C0_QRCTNcwtvUF12y28jQicPR10
135 TEST_F(TransportTest, TestIceControllingToControlledOnIceRestart) {
136 EXPECT_TRUE(SetupChannel());
137 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
138
139 cricket::TransportDescription desc(kIceUfrag1, kIcePwd1);
140 ASSERT_TRUE(transport_->SetLocalTransportDescription(desc,
141 cricket::CA_OFFER,
142 NULL));
143 ASSERT_TRUE(transport_->SetRemoteTransportDescription(desc,
144 cricket::CA_ANSWER,
145 NULL));
146 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
147
148 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2);
149 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc,
150 cricket::CA_ANSWER,
151 NULL));
152 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
153 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole());
154 }
155
156 // This test verifies that the caller's ICE role is still controlling after the
157 // callee triggers ICE restart if the callee's ICE mode is LITE.
158 TEST_F(TransportTest, TestIceControllingOnIceRestartIfRemoteIsIceLite) {
159 EXPECT_TRUE(SetupChannel());
160 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
161
162 cricket::TransportDescription desc(kIceUfrag1, kIcePwd1);
163 ASSERT_TRUE(transport_->SetLocalTransportDescription(desc,
164 cricket::CA_OFFER,
165 NULL));
166
167 cricket::TransportDescription remote_desc(
168 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE,
169 cricket::CONNECTIONROLE_NONE, NULL);
170 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
171 cricket::CA_ANSWER,
172 NULL));
173
174 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
175
176 cricket::TransportDescription new_local_desc(kIceUfrag2, kIcePwd2);
177 ASSERT_TRUE(transport_->SetLocalTransportDescription(new_local_desc,
178 cricket::CA_ANSWER,
179 NULL));
180 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
181 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole());
182 }
183
184 // Tests channel role is reversed after receiving ice-lite from remote.
185 TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) {
186 transport_->SetIceRole(cricket::ICEROLE_CONTROLLED);
187 cricket::TransportDescription remote_desc(
188 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE,
189 cricket::CONNECTIONROLE_ACTPASS, NULL);
190 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
191 cricket::CA_OFFER,
192 NULL));
193 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1);
194 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc,
195 cricket::CA_ANSWER,
196 NULL));
197 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
198 EXPECT_TRUE(SetupChannel());
199 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole());
200 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode());
201 }
202
203 // Tests ice-lite in remote answer.
204 TEST_F(TransportTest, TestSetRemoteIceLiteInAnswer) {
205 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
206 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1);
207 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc,
208 cricket::CA_OFFER,
209 NULL));
210 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
211 EXPECT_TRUE(SetupChannel());
212 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole());
213 // Channels will be created in ICEFULL_MODE.
214 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode());
215 cricket::TransportDescription remote_desc(
216 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE,
217 cricket::CONNECTIONROLE_NONE, NULL);
218 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
219 cricket::CA_ANSWER,
220 NULL));
221 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole());
222 // After receiving remote description with ICEMODE_LITE, channel should
223 // have mode set to ICEMODE_LITE.
224 EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode());
225 }
226
227 TEST_F(TransportTest, TestGetStats) {
228 EXPECT_TRUE(SetupChannel()); 77 EXPECT_TRUE(SetupChannel());
229 cricket::TransportStats stats; 78 cricket::TransportStats stats;
230 EXPECT_TRUE(transport_->GetStats(&stats)); 79 EXPECT_TRUE(transport_->GetStats(&stats));
231 // Note that this tests the behavior of a FakeTransportChannel. 80 // Note that this tests the behavior of a FakeTransportChannel.
232 ASSERT_EQ(1U, stats.channel_stats.size()); 81 ASSERT_EQ(1U, stats.channel_stats.size());
233 EXPECT_EQ(1, stats.channel_stats[0].component); 82 EXPECT_EQ(1, stats.channel_stats[0].component);
234 // Set local transport description for FakeTransport before connecting. 83 // Set local transport description for FakeTransport before connecting.
235 TransportDescription faketransport_desc( 84 TransportDescription faketransport_desc(
236 std::vector<std::string>(), 85 std::vector<std::string>(),
237 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), 86 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH),
238 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH), cricket::ICEMODE_FULL, 87 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH), cricket::ICEMODE_FULL,
239 cricket::CONNECTIONROLE_NONE, nullptr); 88 cricket::CONNECTIONROLE_NONE, nullptr);
240 transport_->SetLocalTransportDescription(faketransport_desc, 89 transport_->SetLocalTransportDescription(faketransport_desc,
241 cricket::CA_OFFER, nullptr); 90 cricket::CA_OFFER, nullptr);
242 EXPECT_TRUE(transport_->GetStats(&stats)); 91 EXPECT_TRUE(transport_->GetStats(&stats));
243 ASSERT_EQ(1U, stats.channel_stats.size()); 92 ASSERT_EQ(1U, stats.channel_stats.size());
244 EXPECT_EQ(1, stats.channel_stats[0].component); 93 EXPECT_EQ(1, stats.channel_stats[0].component);
245 } 94 }
246 95
247 // Tests that VerifyCertificateFingerprint only returns true when the 96 // Tests that VerifyCertificateFingerprint only returns true when the
248 // certificate matches the fingerprint. 97 // certificate matches the fingerprint.
249 TEST_F(TransportTest, TestVerifyCertificateFingerprint) { 98 TEST_F(JsepTransportTest, TestVerifyCertificateFingerprint) {
250 std::string error_desc; 99 std::string error_desc;
251 EXPECT_FALSE( 100 EXPECT_FALSE(
252 transport_->VerifyCertificateFingerprint(nullptr, nullptr, &error_desc)); 101 transport_->VerifyCertificateFingerprint(nullptr, nullptr, &error_desc));
253 rtc::KeyType key_types[] = {rtc::KT_RSA, rtc::KT_ECDSA}; 102 rtc::KeyType key_types[] = {rtc::KT_RSA, rtc::KT_ECDSA};
254 103
255 for (auto& key_type : key_types) { 104 for (auto& key_type : key_types) {
256 rtc::scoped_refptr<rtc::RTCCertificate> certificate = 105 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
257 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( 106 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
258 rtc::SSLIdentity::Generate("testing", key_type))); 107 rtc::SSLIdentity::Generate("testing", key_type)));
259 ASSERT_NE(nullptr, certificate); 108 ASSERT_NE(nullptr, certificate);
(...skipping 14 matching lines...) Expand all
274 nullptr, good_fingerprint.get(), &error_desc)); 123 nullptr, good_fingerprint.get(), &error_desc));
275 124
276 rtc::SSLFingerprint bad_fingerprint = *good_fingerprint; 125 rtc::SSLFingerprint bad_fingerprint = *good_fingerprint;
277 bad_fingerprint.digest.AppendData("0", 1); 126 bad_fingerprint.digest.AppendData("0", 1);
278 EXPECT_FALSE(transport_->VerifyCertificateFingerprint( 127 EXPECT_FALSE(transport_->VerifyCertificateFingerprint(
279 certificate.get(), &bad_fingerprint, &error_desc)); 128 certificate.get(), &bad_fingerprint, &error_desc));
280 } 129 }
281 } 130 }
282 131
283 // Tests that NegotiateRole sets the SSL role correctly. 132 // Tests that NegotiateRole sets the SSL role correctly.
284 TEST_F(TransportTest, TestNegotiateRole) { 133 TEST_F(JsepTransportTest, TestNegotiateRole) {
285 TransportDescription local_desc(kIceUfrag1, kIcePwd1); 134 TransportDescription local_desc(kIceUfrag1, kIcePwd1);
286 TransportDescription remote_desc(kIceUfrag2, kIcePwd2); 135 TransportDescription remote_desc(kIceUfrag2, kIcePwd2);
287 136
288 struct NegotiateRoleParams { 137 struct NegotiateRoleParams {
289 cricket::ConnectionRole local_role; 138 cricket::ConnectionRole local_role;
290 cricket::ConnectionRole remote_role; 139 cricket::ConnectionRole remote_role;
291 cricket::ContentAction local_action; 140 cricket::ContentAction local_action;
292 cricket::ContentAction remote_action; 141 cricket::ContentAction remote_action;
293 }; 142 };
294 143
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 remote_desc.connection_role = param.remote_role; 263 remote_desc.connection_role = param.remote_role;
415 264
416 ASSERT_TRUE(transport_->SetRemoteTransportDescription( 265 ASSERT_TRUE(transport_->SetRemoteTransportDescription(
417 remote_desc, param.remote_action, nullptr)); 266 remote_desc, param.remote_action, nullptr));
418 ASSERT_TRUE(transport_->SetLocalTransportDescription( 267 ASSERT_TRUE(transport_->SetLocalTransportDescription(
419 local_desc, param.local_action, nullptr)); 268 local_desc, param.local_action, nullptr));
420 EXPECT_FALSE( 269 EXPECT_FALSE(
421 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc)); 270 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc));
422 } 271 }
423 } 272 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/jseptransport.cc ('k') | webrtc/p2p/base/p2ptransport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698