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

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

Issue 1920043002: Replace scoped_ptr with unique_ptr in webrtc/base/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 8 months 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/transportcontroller_unittest.cc ('k') | webrtc/pc/channel_unittest.cc » ('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 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 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 <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "webrtc/p2p/base/p2pconstants.h" 15 #include "webrtc/p2p/base/p2pconstants.h"
15 #include "webrtc/p2p/base/transportdescription.h" 16 #include "webrtc/p2p/base/transportdescription.h"
16 #include "webrtc/p2p/base/transportdescriptionfactory.h" 17 #include "webrtc/p2p/base/transportdescriptionfactory.h"
17 #include "webrtc/base/fakesslidentity.h" 18 #include "webrtc/base/fakesslidentity.h"
18 #include "webrtc/base/gunit.h" 19 #include "webrtc/base/gunit.h"
19 #include "webrtc/base/ssladapter.h" 20 #include "webrtc/base/ssladapter.h"
20 21
21 using rtc::scoped_ptr;
22 using cricket::TransportDescriptionFactory; 22 using cricket::TransportDescriptionFactory;
23 using cricket::TransportDescription; 23 using cricket::TransportDescription;
24 using cricket::TransportOptions; 24 using cricket::TransportOptions;
25 25
26 class TransportDescriptionFactoryTest : public testing::Test { 26 class TransportDescriptionFactoryTest : public testing::Test {
27 public: 27 public:
28 TransportDescriptionFactoryTest() 28 TransportDescriptionFactoryTest()
29 : cert1_(rtc::RTCCertificate::Create( 29 : cert1_(rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
30 scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("User1")))), 30 new rtc::FakeSSLIdentity("User1")))),
31 cert2_(rtc::RTCCertificate::Create( 31 cert2_(rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
32 scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("User2")))) {} 32 new rtc::FakeSSLIdentity("User2")))) {}
33 33
34 void CheckDesc(const TransportDescription* desc, 34 void CheckDesc(const TransportDescription* desc,
35 const std::string& opt, const std::string& ice_ufrag, 35 const std::string& opt, const std::string& ice_ufrag,
36 const std::string& ice_pwd, const std::string& dtls_alg) { 36 const std::string& ice_pwd, const std::string& dtls_alg) {
37 ASSERT_TRUE(desc != NULL); 37 ASSERT_TRUE(desc != NULL);
38 EXPECT_EQ(!opt.empty(), desc->HasOption(opt)); 38 EXPECT_EQ(!opt.empty(), desc->HasOption(opt));
39 if (ice_ufrag.empty() && ice_pwd.empty()) { 39 if (ice_ufrag.empty() && ice_pwd.empty()) {
40 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), 40 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH),
41 desc->ice_ufrag.size()); 41 desc->ice_ufrag.size());
42 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), 42 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH),
(...skipping 21 matching lines...) Expand all
64 f2_.set_secure(cricket::SEC_ENABLED); 64 f2_.set_secure(cricket::SEC_ENABLED);
65 f1_.set_certificate(cert1_); 65 f1_.set_certificate(cert1_);
66 f2_.set_certificate(cert2_); 66 f2_.set_certificate(cert2_);
67 } else { 67 } else {
68 f1_.set_secure(cricket::SEC_DISABLED); 68 f1_.set_secure(cricket::SEC_DISABLED);
69 f2_.set_secure(cricket::SEC_DISABLED); 69 f2_.set_secure(cricket::SEC_DISABLED);
70 } 70 }
71 71
72 cricket::TransportOptions options; 72 cricket::TransportOptions options;
73 // The initial offer / answer exchange. 73 // The initial offer / answer exchange.
74 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( 74 std::unique_ptr<TransportDescription> offer(f1_.CreateOffer(options, NULL));
75 options, NULL)); 75 std::unique_ptr<TransportDescription> answer(
76 rtc::scoped_ptr<TransportDescription> answer( 76 f2_.CreateAnswer(offer.get(), options, NULL));
77 f2_.CreateAnswer(offer.get(),
78 options, NULL));
79 77
80 // Create an updated offer where we restart ice. 78 // Create an updated offer where we restart ice.
81 options.ice_restart = true; 79 options.ice_restart = true;
82 rtc::scoped_ptr<TransportDescription> restart_offer(f1_.CreateOffer( 80 std::unique_ptr<TransportDescription> restart_offer(
83 options, offer.get())); 81 f1_.CreateOffer(options, offer.get()));
84 82
85 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get()); 83 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get());
86 84
87 // Create a new answer. The transport ufrag and password is changed since 85 // Create a new answer. The transport ufrag and password is changed since
88 // |options.ice_restart == true| 86 // |options.ice_restart == true|
89 rtc::scoped_ptr<TransportDescription> restart_answer( 87 std::unique_ptr<TransportDescription> restart_answer(
90 f2_.CreateAnswer(restart_offer.get(), options, answer.get())); 88 f2_.CreateAnswer(restart_offer.get(), options, answer.get()));
91 ASSERT_TRUE(restart_answer.get() != NULL); 89 ASSERT_TRUE(restart_answer.get() != NULL);
92 90
93 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get()); 91 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get());
94 } 92 }
95 93
96 void VerifyUfragAndPasswordChanged(bool dtls, 94 void VerifyUfragAndPasswordChanged(bool dtls,
97 const TransportDescription* org_desc, 95 const TransportDescription* org_desc,
98 const TransportDescription* restart_desc) { 96 const TransportDescription* restart_desc) {
99 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); 97 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd);
(...skipping 13 matching lines...) Expand all
113 111
114 protected: 112 protected:
115 TransportDescriptionFactory f1_; 113 TransportDescriptionFactory f1_;
116 TransportDescriptionFactory f2_; 114 TransportDescriptionFactory f2_;
117 115
118 rtc::scoped_refptr<rtc::RTCCertificate> cert1_; 116 rtc::scoped_refptr<rtc::RTCCertificate> cert1_;
119 rtc::scoped_refptr<rtc::RTCCertificate> cert2_; 117 rtc::scoped_refptr<rtc::RTCCertificate> cert2_;
120 }; 118 };
121 119
122 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { 120 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) {
123 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( 121 std::unique_ptr<TransportDescription> desc(
124 TransportOptions(), NULL)); 122 f1_.CreateOffer(TransportOptions(), NULL));
125 CheckDesc(desc.get(), "", "", "", ""); 123 CheckDesc(desc.get(), "", "", "", "");
126 } 124 }
127 125
128 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { 126 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) {
129 f1_.set_secure(cricket::SEC_ENABLED); 127 f1_.set_secure(cricket::SEC_ENABLED);
130 f1_.set_certificate(cert1_); 128 f1_.set_certificate(cert1_);
131 std::string digest_alg; 129 std::string digest_alg;
132 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( 130 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm(
133 &digest_alg)); 131 &digest_alg));
134 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( 132 std::unique_ptr<TransportDescription> desc(
135 TransportOptions(), NULL)); 133 f1_.CreateOffer(TransportOptions(), NULL));
136 CheckDesc(desc.get(), "", "", "", digest_alg); 134 CheckDesc(desc.get(), "", "", "", digest_alg);
137 // Ensure it also works with SEC_REQUIRED. 135 // Ensure it also works with SEC_REQUIRED.
138 f1_.set_secure(cricket::SEC_REQUIRED); 136 f1_.set_secure(cricket::SEC_REQUIRED);
139 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); 137 desc.reset(f1_.CreateOffer(TransportOptions(), NULL));
140 CheckDesc(desc.get(), "", "", "", digest_alg); 138 CheckDesc(desc.get(), "", "", "", digest_alg);
141 } 139 }
142 140
143 // Test generating an offer with DTLS fails with no identity. 141 // Test generating an offer with DTLS fails with no identity.
144 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { 142 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) {
145 f1_.set_secure(cricket::SEC_ENABLED); 143 f1_.set_secure(cricket::SEC_ENABLED);
146 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( 144 std::unique_ptr<TransportDescription> desc(
147 TransportOptions(), NULL)); 145 f1_.CreateOffer(TransportOptions(), NULL));
148 ASSERT_TRUE(desc.get() == NULL); 146 ASSERT_TRUE(desc.get() == NULL);
149 } 147 }
150 148
151 // Test updating an offer with DTLS to pick ICE. 149 // Test updating an offer with DTLS to pick ICE.
152 // The ICE credentials should stay the same in the new offer. 150 // The ICE credentials should stay the same in the new offer.
153 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { 151 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) {
154 f1_.set_secure(cricket::SEC_ENABLED); 152 f1_.set_secure(cricket::SEC_ENABLED);
155 f1_.set_certificate(cert1_); 153 f1_.set_certificate(cert1_);
156 std::string digest_alg; 154 std::string digest_alg;
157 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( 155 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm(
158 &digest_alg)); 156 &digest_alg));
159 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( 157 std::unique_ptr<TransportDescription> old_desc(
160 TransportOptions(), NULL)); 158 f1_.CreateOffer(TransportOptions(), NULL));
161 ASSERT_TRUE(old_desc.get() != NULL); 159 ASSERT_TRUE(old_desc.get() != NULL);
162 scoped_ptr<TransportDescription> desc( 160 std::unique_ptr<TransportDescription> desc(
163 f1_.CreateOffer(TransportOptions(), old_desc.get())); 161 f1_.CreateOffer(TransportOptions(), old_desc.get()));
164 CheckDesc(desc.get(), "", 162 CheckDesc(desc.get(), "",
165 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); 163 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg);
166 } 164 }
167 165
168 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { 166 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) {
169 scoped_ptr<TransportDescription> offer(f1_.CreateOffer( 167 std::unique_ptr<TransportDescription> offer(
170 TransportOptions(), NULL)); 168 f1_.CreateOffer(TransportOptions(), NULL));
171 ASSERT_TRUE(offer.get() != NULL); 169 ASSERT_TRUE(offer.get() != NULL);
172 scoped_ptr<TransportDescription> desc(f2_.CreateAnswer( 170 std::unique_ptr<TransportDescription> desc(
173 offer.get(), TransportOptions(), NULL)); 171 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL));
174 CheckDesc(desc.get(), "", "", "", ""); 172 CheckDesc(desc.get(), "", "", "", "");
175 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), 173 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(),
176 NULL)); 174 NULL));
177 CheckDesc(desc.get(), "", "", "", ""); 175 CheckDesc(desc.get(), "", "", "", "");
178 } 176 }
179 177
180 // Test that we can update an answer properly; ICE credentials shouldn't change. 178 // Test that we can update an answer properly; ICE credentials shouldn't change.
181 TEST_F(TransportDescriptionFactoryTest, TestReanswer) { 179 TEST_F(TransportDescriptionFactoryTest, TestReanswer) {
182 scoped_ptr<TransportDescription> offer( 180 std::unique_ptr<TransportDescription> offer(
183 f1_.CreateOffer(TransportOptions(), NULL)); 181 f1_.CreateOffer(TransportOptions(), NULL));
184 ASSERT_TRUE(offer.get() != NULL); 182 ASSERT_TRUE(offer.get() != NULL);
185 scoped_ptr<TransportDescription> old_desc( 183 std::unique_ptr<TransportDescription> old_desc(
186 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); 184 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL));
187 ASSERT_TRUE(old_desc.get() != NULL); 185 ASSERT_TRUE(old_desc.get() != NULL);
188 scoped_ptr<TransportDescription> desc( 186 std::unique_ptr<TransportDescription> desc(
189 f2_.CreateAnswer(offer.get(), TransportOptions(), 187 f2_.CreateAnswer(offer.get(), TransportOptions(), old_desc.get()));
190 old_desc.get()));
191 ASSERT_TRUE(desc.get() != NULL); 188 ASSERT_TRUE(desc.get() != NULL);
192 CheckDesc(desc.get(), "", 189 CheckDesc(desc.get(), "",
193 old_desc->ice_ufrag, old_desc->ice_pwd, ""); 190 old_desc->ice_ufrag, old_desc->ice_pwd, "");
194 } 191 }
195 192
196 // Test that we handle answering an offer with DTLS with no DTLS. 193 // Test that we handle answering an offer with DTLS with no DTLS.
197 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { 194 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) {
198 f1_.set_secure(cricket::SEC_ENABLED); 195 f1_.set_secure(cricket::SEC_ENABLED);
199 f1_.set_certificate(cert1_); 196 f1_.set_certificate(cert1_);
200 scoped_ptr<TransportDescription> offer( 197 std::unique_ptr<TransportDescription> offer(
201 f1_.CreateOffer(TransportOptions(), NULL)); 198 f1_.CreateOffer(TransportOptions(), NULL));
202 ASSERT_TRUE(offer.get() != NULL); 199 ASSERT_TRUE(offer.get() != NULL);
203 scoped_ptr<TransportDescription> desc( 200 std::unique_ptr<TransportDescription> desc(
204 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); 201 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL));
205 CheckDesc(desc.get(), "", "", "", ""); 202 CheckDesc(desc.get(), "", "", "", "");
206 } 203 }
207 204
208 // Test that we handle answering an offer without DTLS if we have DTLS enabled, 205 // Test that we handle answering an offer without DTLS if we have DTLS enabled,
209 // but fail if we require DTLS. 206 // but fail if we require DTLS.
210 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { 207 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) {
211 f2_.set_secure(cricket::SEC_ENABLED); 208 f2_.set_secure(cricket::SEC_ENABLED);
212 f2_.set_certificate(cert2_); 209 f2_.set_certificate(cert2_);
213 scoped_ptr<TransportDescription> offer( 210 std::unique_ptr<TransportDescription> offer(
214 f1_.CreateOffer(TransportOptions(), NULL)); 211 f1_.CreateOffer(TransportOptions(), NULL));
215 ASSERT_TRUE(offer.get() != NULL); 212 ASSERT_TRUE(offer.get() != NULL);
216 scoped_ptr<TransportDescription> desc( 213 std::unique_ptr<TransportDescription> desc(
217 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); 214 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL));
218 CheckDesc(desc.get(), "", "", "", ""); 215 CheckDesc(desc.get(), "", "", "", "");
219 f2_.set_secure(cricket::SEC_REQUIRED); 216 f2_.set_secure(cricket::SEC_REQUIRED);
220 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), 217 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(),
221 NULL)); 218 NULL));
222 ASSERT_TRUE(desc.get() == NULL); 219 ASSERT_TRUE(desc.get() == NULL);
223 } 220 }
224 221
225 // Test that we handle answering an DTLS offer with DTLS, both if we have 222 // Test that we handle answering an DTLS offer with DTLS, both if we have
226 // DTLS enabled and required. 223 // DTLS enabled and required.
227 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { 224 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) {
228 f1_.set_secure(cricket::SEC_ENABLED); 225 f1_.set_secure(cricket::SEC_ENABLED);
229 f1_.set_certificate(cert1_); 226 f1_.set_certificate(cert1_);
230 227
231 f2_.set_secure(cricket::SEC_ENABLED); 228 f2_.set_secure(cricket::SEC_ENABLED);
232 f2_.set_certificate(cert2_); 229 f2_.set_certificate(cert2_);
233 // f2_ produces the answer that is being checked in this test, so the 230 // f2_ produces the answer that is being checked in this test, so the
234 // answer must contain fingerprint lines with cert2_'s digest algorithm. 231 // answer must contain fingerprint lines with cert2_'s digest algorithm.
235 std::string digest_alg2; 232 std::string digest_alg2;
236 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( 233 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm(
237 &digest_alg2)); 234 &digest_alg2));
238 235
239 scoped_ptr<TransportDescription> offer( 236 std::unique_ptr<TransportDescription> offer(
240 f1_.CreateOffer(TransportOptions(), NULL)); 237 f1_.CreateOffer(TransportOptions(), NULL));
241 ASSERT_TRUE(offer.get() != NULL); 238 ASSERT_TRUE(offer.get() != NULL);
242 scoped_ptr<TransportDescription> desc( 239 std::unique_ptr<TransportDescription> desc(
243 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); 240 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL));
244 CheckDesc(desc.get(), "", "", "", digest_alg2); 241 CheckDesc(desc.get(), "", "", "", digest_alg2);
245 f2_.set_secure(cricket::SEC_REQUIRED); 242 f2_.set_secure(cricket::SEC_REQUIRED);
246 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), 243 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(),
247 NULL)); 244 NULL));
248 CheckDesc(desc.get(), "", "", "", digest_alg2); 245 CheckDesc(desc.get(), "", "", "", digest_alg2);
249 } 246 }
250 247
251 // Test that ice ufrag and password is changed in an updated offer and answer 248 // Test that ice ufrag and password is changed in an updated offer and answer
252 // if |TransportDescriptionOptions::ice_restart| is true. 249 // if |TransportDescriptionOptions::ice_restart| is true.
253 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { 250 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) {
254 TestIceRestart(false); 251 TestIceRestart(false);
255 } 252 }
256 253
257 // Test that ice ufrag and password is changed in an updated offer and answer 254 // Test that ice ufrag and password is changed in an updated offer and answer
258 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. 255 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled.
259 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { 256 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) {
260 TestIceRestart(true); 257 TestIceRestart(true);
261 } 258 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transportcontroller_unittest.cc ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698