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

Side by Side Diff: extensions/browser/api/cast_channel/cast_socket_unittest.cc

Issue 2042493002: Fix use-before-new issue in TestCastSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/cast_channel/cast_socket.h" 5 #include "extensions/browser/api/cast_channel/cast_socket.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 static std::unique_ptr<TestCastSocket> CreateSecure( 180 static std::unique_ptr<TestCastSocket> CreateSecure(
181 Logger* logger, 181 Logger* logger,
182 uint64_t device_capabilities = cast_channel::CastDeviceCapability::NONE) { 182 uint64_t device_capabilities = cast_channel::CastDeviceCapability::NONE) {
183 return std::unique_ptr<TestCastSocket>(new TestCastSocket( 183 return std::unique_ptr<TestCastSocket>(new TestCastSocket(
184 CreateIPEndPointForTest(), CHANNEL_AUTH_TYPE_SSL_VERIFIED, 184 CreateIPEndPointForTest(), CHANNEL_AUTH_TYPE_SSL_VERIFIED,
185 kDistantTimeoutMillis, logger, device_capabilities)); 185 kDistantTimeoutMillis, logger, device_capabilities));
186 } 186 }
187 187
188 explicit TestCastSocket(const net::IPEndPoint& ip_endpoint, 188 explicit TestCastSocket(const net::IPEndPoint& ip_endpoint,
Wez 2016/06/03 22:12:18 nit: This doesn't need to be explicit, nor does th
krasin 2016/06/03 22:20:58 Done.
189 ChannelAuthType channel_auth, 189 ChannelAuthType channel_auth,
190 int64_t timeout_ms, 190 int64_t timeout_ms,
191 Logger* logger, 191 Logger* logger,
192 uint64_t device_capabilities) 192 uint64_t device_capabilities)
193 : TestCastSocket(ip_endpoint,
194 channel_auth,
195 timeout_ms,
196 logger,
197 new net::TestNetLog(),
198 device_capabilities) {}
199
200 explicit TestCastSocket(const net::IPEndPoint& ip_endpoint,
201 ChannelAuthType channel_auth,
202 int64_t timeout_ms,
203 Logger* logger,
204 net::TestNetLog* capturing_net_log,
205 uint64_t device_capabilities)
193 : CastSocketImpl("some_extension_id", 206 : CastSocketImpl("some_extension_id",
194 ip_endpoint, 207 ip_endpoint,
195 channel_auth, 208 channel_auth,
196 &capturing_net_log_, 209 capturing_net_log,
197 base::TimeDelta::FromMilliseconds(timeout_ms), 210 base::TimeDelta::FromMilliseconds(timeout_ms),
198 false, 211 false,
199 logger, 212 logger,
200 device_capabilities), 213 device_capabilities),
214 capturing_net_log_(capturing_net_log),
201 ip_(ip_endpoint), 215 ip_(ip_endpoint),
202 extract_cert_result_(true), 216 extract_cert_result_(true),
203 verify_challenge_result_(true), 217 verify_challenge_result_(true),
204 verify_challenge_disallow_(false), 218 verify_challenge_disallow_(false),
205 tcp_unresponsive_(false), 219 tcp_unresponsive_(false),
206 mock_timer_(new base::MockTimer(false, false)), 220 mock_timer_(new base::MockTimer(false, false)),
207 mock_transport_(nullptr) {} 221 mock_transport_(nullptr) {}
208 222
209 ~TestCastSocket() override {} 223 ~TestCastSocket() override {}
210 224
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 std::unique_ptr<net::SSLClientSocket> CreateSslSocket( 303 std::unique_ptr<net::SSLClientSocket> CreateSslSocket(
290 std::unique_ptr<net::StreamSocket> socket) override { 304 std::unique_ptr<net::StreamSocket> socket) override {
291 net::MockConnect* connect_data = ssl_connect_data_.get(); 305 net::MockConnect* connect_data = ssl_connect_data_.get();
292 connect_data->peer_addr = ip_; 306 connect_data->peer_addr = ip_;
293 307
294 ssl_data_.reset(new net::StaticSocketDataProvider( 308 ssl_data_.reset(new net::StaticSocketDataProvider(
295 reads_.data(), reads_.size(), writes_.data(), writes_.size())); 309 reads_.data(), reads_.size(), writes_.data(), writes_.size()));
296 ssl_data_->set_connect_data(*connect_data); 310 ssl_data_->set_connect_data(*connect_data);
297 // NOTE: net::MockTCPClientSocket inherits from net::SSLClientSocket !! 311 // NOTE: net::MockTCPClientSocket inherits from net::SSLClientSocket !!
298 return std::unique_ptr<net::SSLClientSocket>(new net::MockTCPClientSocket( 312 return std::unique_ptr<net::SSLClientSocket>(new net::MockTCPClientSocket(
299 net::AddressList(), &capturing_net_log_, ssl_data_.get())); 313 net::AddressList(), capturing_net_log_.get(), ssl_data_.get()));
300 } 314 }
301 315
302 scoped_refptr<net::X509Certificate> ExtractPeerCert() override { 316 scoped_refptr<net::X509Certificate> ExtractPeerCert() override {
303 return extract_cert_result_ ? make_scoped_refptr<net::X509Certificate>( 317 return extract_cert_result_ ? make_scoped_refptr<net::X509Certificate>(
304 new net::X509Certificate( 318 new net::X509Certificate(
305 "", "", base::Time(), base::Time())) 319 "", "", base::Time(), base::Time()))
306 : nullptr; 320 : nullptr;
307 } 321 }
308 322
309 bool VerifyChallengeReply() override { 323 bool VerifyChallengeReply() override {
310 EXPECT_FALSE(verify_challenge_disallow_); 324 EXPECT_FALSE(verify_challenge_disallow_);
311 return verify_challenge_result_; 325 return verify_challenge_result_;
312 } 326 }
313 327
314 base::Timer* GetTimer() override { return mock_timer_.get(); } 328 base::Timer* GetTimer() override { return mock_timer_.get(); }
315 329
316 net::TestNetLog capturing_net_log_; 330 std::unique_ptr<net::TestNetLog> capturing_net_log_;
317 net::IPEndPoint ip_; 331 net::IPEndPoint ip_;
318 // Simulated connect data 332 // Simulated connect data
319 std::unique_ptr<net::MockConnect> tcp_connect_data_; 333 std::unique_ptr<net::MockConnect> tcp_connect_data_;
320 std::unique_ptr<net::MockConnect> ssl_connect_data_; 334 std::unique_ptr<net::MockConnect> ssl_connect_data_;
321 // Simulated read / write data 335 // Simulated read / write data
322 std::vector<net::MockWrite> writes_; 336 std::vector<net::MockWrite> writes_;
323 std::vector<net::MockRead> reads_; 337 std::vector<net::MockRead> reads_;
324 std::unique_ptr<net::SocketDataProvider> ssl_data_; 338 std::unique_ptr<net::SocketDataProvider> ssl_data_;
325 // Simulated result of peer cert extraction. 339 // Simulated result of peer cert extraction.
326 bool extract_cert_result_; 340 bool extract_cert_result_;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 logger_, cast_channel::CastDeviceCapability::VIDEO_OUT); 900 logger_, cast_channel::CastDeviceCapability::VIDEO_OUT);
887 EXPECT_FALSE(socket_->audio_only()); 901 EXPECT_FALSE(socket_->audio_only());
888 EXPECT_TRUE(socket_->TestVerifyChannelPolicyNone()); 902 EXPECT_TRUE(socket_->TestVerifyChannelPolicyNone());
889 EXPECT_FALSE(socket_->audio_only()); 903 EXPECT_FALSE(socket_->audio_only());
890 EXPECT_FALSE(socket_->TestVerifyChannelPolicyAudioOnly()); 904 EXPECT_FALSE(socket_->TestVerifyChannelPolicyAudioOnly());
891 EXPECT_TRUE(socket_->audio_only()); 905 EXPECT_TRUE(socket_->audio_only());
892 } 906 }
893 } // namespace cast_channel 907 } // namespace cast_channel
894 } // namespace api 908 } // namespace api
895 } // namespace extensions 909 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698