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

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

Issue 2517883002: Refactoring that removes P2PTransport and DtlsTransport classes. (Closed)
Patch Set: Leaving comments about what we'd need to do to support QUIC again. Created 4 years, 1 month 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
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::Transport;
20 using cricket::FakeTransport; 19 using cricket::FakeTransport;
21 using cricket::TransportChannel; 20 using cricket::TransportChannel;
22 using cricket::FakeTransportChannel; 21 using cricket::FakeTransportChannel;
23 using cricket::IceRole; 22 using cricket::IceRole;
24 using cricket::TransportDescription; 23 using cricket::TransportDescription;
25 using rtc::SocketAddress; 24 using rtc::SocketAddress;
26 25
27 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; 26 static const char kIceUfrag1[] = "TESTICEUFRAG0001";
28 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; 27 static const char kIcePwd1[] = "TESTICEPWD00000000000001";
29 28
30 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; 29 static const char kIceUfrag2[] = "TESTICEUFRAG0002";
31 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; 30 static const char kIcePwd2[] = "TESTICEPWD00000000000002";
32 31
33 class TransportTest : public testing::Test, 32 class TransportTest : public testing::Test,
34 public sigslot::has_slots<> { 33 public sigslot::has_slots<> {
35 public: 34 public:
36 TransportTest() 35 TransportTest() : transport_(new Transport("test content name", nullptr)) {}
37 : transport_(new FakeTransport("test content name")), channel_(NULL) {} 36 bool SetupChannel() {
38 ~TransportTest() { 37 fake_ice_channel_.reset(new FakeTransportChannel(transport_->name(), 1));
39 transport_->DestroyAllChannels(); 38 fake_dtls_channel_.reset(new FakeTransportChannel(transport_->name(), 1));
39 return transport_->AddChannel(fake_dtls_channel_.get(),
40 fake_ice_channel_.get(), 1);
40 } 41 }
41 bool SetupChannel() { 42 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 43
54 protected: 44 protected:
55 std::unique_ptr<FakeTransport> transport_; 45 std::unique_ptr<FakeTransportChannel> fake_dtls_channel_;
56 FakeTransportChannel* channel_; 46 std::unique_ptr<FakeTransportChannel> fake_ice_channel_;
47 std::unique_ptr<Transport> transport_;
57 }; 48 };
58 49
59 // This test verifies channels are created with proper ICE 50 // This test verifies channels are created with proper ICE
60 // role, tiebreaker and remote ice mode and credentials after offer and 51 // ufrag/password after a transport description is applied.
61 // answer negotiations.
62 TEST_F(TransportTest, TestChannelIceParameters) { 52 TEST_F(TransportTest, TestChannelIceParameters) {
63 transport_->SetIceRole(cricket::ICEROLE_CONTROLLING);
64 transport_->SetIceTiebreaker(99U);
65 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); 53 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1);
66 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, 54 ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc,
67 cricket::CA_OFFER, 55 cricket::CA_OFFER,
68 NULL)); 56 NULL));
69 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role());
70 EXPECT_TRUE(SetupChannel()); 57 EXPECT_TRUE(SetupChannel());
71 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); 58 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode());
72 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); 59 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->ice_ufrag());
73 EXPECT_EQ(kIceUfrag1, channel_->ice_ufrag()); 60 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->ice_pwd());
74 EXPECT_EQ(kIcePwd1, channel_->ice_pwd());
75 61
76 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); 62 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1);
77 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, 63 ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc,
78 cricket::CA_ANSWER, 64 cricket::CA_ANSWER,
79 NULL)); 65 NULL));
80 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); 66 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode());
81 EXPECT_EQ(99U, channel_->IceTiebreaker()); 67 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->remote_ice_ufrag());
82 EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); 68 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->remote_ice_pwd());
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 } 69 }
90 70
91 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd 71 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd
92 // changed, and false in other cases. 72 // changed, and false in other cases.
93 TEST_F(TransportTest, TestIceCredentialsChanged) { 73 TEST_F(TransportTest, TestIceCredentialsChanged) {
94 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2")); 74 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2"));
95 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1")); 75 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1"));
96 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2")); 76 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2"));
97 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1")); 77 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1"));
98 } 78 }
99 79
100 // This test verifies that the callee's ICE role remains the same when the
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) { 80 TEST_F(TransportTest, TestGetStats) {
228 EXPECT_TRUE(SetupChannel()); 81 EXPECT_TRUE(SetupChannel());
229 cricket::TransportStats stats; 82 cricket::TransportStats stats;
230 EXPECT_TRUE(transport_->GetStats(&stats)); 83 EXPECT_TRUE(transport_->GetStats(&stats));
231 // Note that this tests the behavior of a FakeTransportChannel. 84 // Note that this tests the behavior of a FakeTransportChannel.
232 ASSERT_EQ(1U, stats.channel_stats.size()); 85 ASSERT_EQ(1U, stats.channel_stats.size());
233 EXPECT_EQ(1, stats.channel_stats[0].component); 86 EXPECT_EQ(1, stats.channel_stats[0].component);
234 // Set local transport description for FakeTransport before connecting. 87 // Set local transport description for FakeTransport before connecting.
235 TransportDescription faketransport_desc( 88 TransportDescription faketransport_desc(
236 std::vector<std::string>(), 89 std::vector<std::string>(),
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 remote_desc.connection_role = param.remote_role; 267 remote_desc.connection_role = param.remote_role;
415 268
416 ASSERT_TRUE(transport_->SetRemoteTransportDescription( 269 ASSERT_TRUE(transport_->SetRemoteTransportDescription(
417 remote_desc, param.remote_action, nullptr)); 270 remote_desc, param.remote_action, nullptr));
418 ASSERT_TRUE(transport_->SetLocalTransportDescription( 271 ASSERT_TRUE(transport_->SetLocalTransportDescription(
419 local_desc, param.local_action, nullptr)); 272 local_desc, param.local_action, nullptr));
420 EXPECT_FALSE( 273 EXPECT_FALSE(
421 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc)); 274 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc));
422 } 275 }
423 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698