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

Side by Side Diff: net/socket/client_socket_pool_base_unittest.cc

Issue 1892323002: Change scoped_ptr to std::unique_ptr in //net/socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « net/socket/client_socket_pool_base.cc ('k') | net/socket/client_socket_pool_manager.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 198 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
199 }; 199 };
200 200
201 class TestConnectJob; 201 class TestConnectJob;
202 202
203 class MockClientSocketFactory : public ClientSocketFactory { 203 class MockClientSocketFactory : public ClientSocketFactory {
204 public: 204 public:
205 MockClientSocketFactory() : allocation_count_(0) {} 205 MockClientSocketFactory() : allocation_count_(0) {}
206 206
207 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 207 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
208 DatagramSocket::BindType bind_type, 208 DatagramSocket::BindType bind_type,
209 const RandIntCallback& rand_int_cb, 209 const RandIntCallback& rand_int_cb,
210 NetLog* net_log, 210 NetLog* net_log,
211 const NetLog::Source& source) override { 211 const NetLog::Source& source) override {
212 NOTREACHED(); 212 NOTREACHED();
213 return scoped_ptr<DatagramClientSocket>(); 213 return std::unique_ptr<DatagramClientSocket>();
214 } 214 }
215 215
216 scoped_ptr<StreamSocket> CreateTransportClientSocket( 216 std::unique_ptr<StreamSocket> CreateTransportClientSocket(
217 const AddressList& addresses, 217 const AddressList& addresses,
218 scoped_ptr<SocketPerformanceWatcher> /* socket_performance_watcher */, 218 std::unique_ptr<
219 SocketPerformanceWatcher> /* socket_performance_watcher */,
219 NetLog* /* net_log */, 220 NetLog* /* net_log */,
220 const NetLog::Source& /*source*/) override { 221 const NetLog::Source& /*source*/) override {
221 allocation_count_++; 222 allocation_count_++;
222 return scoped_ptr<StreamSocket>(); 223 return std::unique_ptr<StreamSocket>();
223 } 224 }
224 225
225 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 226 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
226 scoped_ptr<ClientSocketHandle> transport_socket, 227 std::unique_ptr<ClientSocketHandle> transport_socket,
227 const HostPortPair& host_and_port, 228 const HostPortPair& host_and_port,
228 const SSLConfig& ssl_config, 229 const SSLConfig& ssl_config,
229 const SSLClientSocketContext& context) override { 230 const SSLClientSocketContext& context) override {
230 NOTIMPLEMENTED(); 231 NOTIMPLEMENTED();
231 return scoped_ptr<SSLClientSocket>(); 232 return std::unique_ptr<SSLClientSocket>();
232 } 233 }
233 234
234 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); } 235 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); }
235 236
236 void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); } 237 void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); }
237 238
238 void SignalJobs(); 239 void SignalJobs();
239 240
240 void SignalJob(size_t job); 241 void SignalJob(size_t job);
241 242
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 307 }
307 } 308 }
308 309
309 private: 310 private:
310 // From ConnectJob: 311 // From ConnectJob:
311 312
312 int ConnectInternal() override { 313 int ConnectInternal() override {
313 AddressList ignored; 314 AddressList ignored;
314 client_socket_factory_->CreateTransportClientSocket(ignored, NULL, NULL, 315 client_socket_factory_->CreateTransportClientSocket(ignored, NULL, NULL,
315 NetLog::Source()); 316 NetLog::Source());
316 SetSocket( 317 SetSocket(std::unique_ptr<StreamSocket>(
317 scoped_ptr<StreamSocket>(new MockClientSocket(net_log().net_log()))); 318 new MockClientSocket(net_log().net_log())));
318 switch (job_type_) { 319 switch (job_type_) {
319 case kMockJob: 320 case kMockJob:
320 return DoConnect(true /* successful */, false /* sync */, 321 return DoConnect(true /* successful */, false /* sync */,
321 false /* recoverable */); 322 false /* recoverable */);
322 case kMockFailingJob: 323 case kMockFailingJob:
323 return DoConnect(false /* error */, false /* sync */, 324 return DoConnect(false /* error */, false /* sync */,
324 false /* recoverable */); 325 false /* recoverable */);
325 case kMockPendingJob: 326 case kMockPendingJob:
326 set_load_state(LOAD_STATE_CONNECTING); 327 set_load_state(LOAD_STATE_CONNECTING);
327 328
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 base::TimeDelta::FromMilliseconds(2)); 385 base::TimeDelta::FromMilliseconds(2));
385 return ERR_IO_PENDING; 386 return ERR_IO_PENDING;
386 case kMockUnreadDataJob: { 387 case kMockUnreadDataJob: {
387 int ret = DoConnect(true /* successful */, false /* sync */, 388 int ret = DoConnect(true /* successful */, false /* sync */,
388 false /* recoverable */); 389 false /* recoverable */);
389 static_cast<MockClientSocket*>(socket())->set_has_unread_data(true); 390 static_cast<MockClientSocket*>(socket())->set_has_unread_data(true);
390 return ret; 391 return ret;
391 } 392 }
392 default: 393 default:
393 NOTREACHED(); 394 NOTREACHED();
394 SetSocket(scoped_ptr<StreamSocket>()); 395 SetSocket(std::unique_ptr<StreamSocket>());
395 return ERR_FAILED; 396 return ERR_FAILED;
396 } 397 }
397 } 398 }
398 399
399 int DoConnect(bool succeed, bool was_async, bool recoverable) { 400 int DoConnect(bool succeed, bool was_async, bool recoverable) {
400 int result = OK; 401 int result = OK;
401 if (succeed) { 402 if (succeed) {
402 socket()->Connect(CompletionCallback()); 403 socket()->Connect(CompletionCallback());
403 } else if (recoverable) { 404 } else if (recoverable) {
404 result = ERR_PROXY_AUTH_REQUESTED; 405 result = ERR_PROXY_AUTH_REQUESTED;
405 } else { 406 } else {
406 result = ERR_CONNECTION_FAILED; 407 result = ERR_CONNECTION_FAILED;
407 SetSocket(scoped_ptr<StreamSocket>()); 408 SetSocket(std::unique_ptr<StreamSocket>());
408 } 409 }
409 410
410 if (was_async) 411 if (was_async)
411 NotifyDelegateOfCompletion(result); 412 NotifyDelegateOfCompletion(result);
412 return result; 413 return result;
413 } 414 }
414 415
415 bool waiting_success_; 416 bool waiting_success_;
416 const JobType job_type_; 417 const JobType job_type_;
417 MockClientSocketFactory* const client_socket_factory_; 418 MockClientSocketFactory* const client_socket_factory_;
(...skipping 24 matching lines...) Expand all
442 job_types_ = job_types; 443 job_types_ = job_types;
443 CHECK(!job_types_->empty()); 444 CHECK(!job_types_->empty());
444 } 445 }
445 446
446 void set_timeout_duration(base::TimeDelta timeout_duration) { 447 void set_timeout_duration(base::TimeDelta timeout_duration) {
447 timeout_duration_ = timeout_duration; 448 timeout_duration_ = timeout_duration;
448 } 449 }
449 450
450 // ConnectJobFactory implementation. 451 // ConnectJobFactory implementation.
451 452
452 scoped_ptr<ConnectJob> NewConnectJob( 453 std::unique_ptr<ConnectJob> NewConnectJob(
453 const std::string& group_name, 454 const std::string& group_name,
454 const TestClientSocketPoolBase::Request& request, 455 const TestClientSocketPoolBase::Request& request,
455 ConnectJob::Delegate* delegate) const override { 456 ConnectJob::Delegate* delegate) const override {
456 EXPECT_TRUE(!job_types_ || !job_types_->empty()); 457 EXPECT_TRUE(!job_types_ || !job_types_->empty());
457 TestConnectJob::JobType job_type = job_type_; 458 TestConnectJob::JobType job_type = job_type_;
458 if (job_types_ && !job_types_->empty()) { 459 if (job_types_ && !job_types_->empty()) {
459 job_type = job_types_->front(); 460 job_type = job_types_->front();
460 job_types_->pop_front(); 461 job_types_->pop_front();
461 } 462 }
462 return scoped_ptr<ConnectJob>(new TestConnectJob(job_type, 463 return std::unique_ptr<ConnectJob>(
463 group_name, 464 new TestConnectJob(job_type, group_name, request, timeout_duration_,
464 request, 465 delegate, client_socket_factory_, net_log_));
465 timeout_duration_,
466 delegate,
467 client_socket_factory_,
468 net_log_));
469 } 466 }
470 467
471 base::TimeDelta ConnectionTimeout() const override { 468 base::TimeDelta ConnectionTimeout() const override {
472 return timeout_duration_; 469 return timeout_duration_;
473 } 470 }
474 471
475 private: 472 private:
476 TestConnectJob::JobType job_type_; 473 TestConnectJob::JobType job_type_;
477 std::list<TestConnectJob::JobType>* job_types_; 474 std::list<TestConnectJob::JobType>* job_types_;
478 base::TimeDelta timeout_duration_; 475 base::TimeDelta timeout_duration_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 520
524 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); 521 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);
525 } 522 }
526 523
527 void CancelRequest(const std::string& group_name, 524 void CancelRequest(const std::string& group_name,
528 ClientSocketHandle* handle) override { 525 ClientSocketHandle* handle) override {
529 base_.CancelRequest(group_name, handle); 526 base_.CancelRequest(group_name, handle);
530 } 527 }
531 528
532 void ReleaseSocket(const std::string& group_name, 529 void ReleaseSocket(const std::string& group_name,
533 scoped_ptr<StreamSocket> socket, 530 std::unique_ptr<StreamSocket> socket,
534 int id) override { 531 int id) override {
535 base_.ReleaseSocket(group_name, std::move(socket), id); 532 base_.ReleaseSocket(group_name, std::move(socket), id);
536 } 533 }
537 534
538 void FlushWithError(int error) override { base_.FlushWithError(error); } 535 void FlushWithError(int error) override { base_.FlushWithError(error); }
539 536
540 bool IsStalled() const override { return base_.IsStalled(); } 537 bool IsStalled() const override { return base_.IsStalled(); }
541 538
542 void CloseIdleSockets() override { base_.CloseIdleSockets(); } 539 void CloseIdleSockets() override { base_.CloseIdleSockets(); }
543 540
544 int IdleSocketCount() const override { return base_.idle_socket_count(); } 541 int IdleSocketCount() const override { return base_.idle_socket_count(); }
545 542
546 int IdleSocketCountInGroup(const std::string& group_name) const override { 543 int IdleSocketCountInGroup(const std::string& group_name) const override {
547 return base_.IdleSocketCountInGroup(group_name); 544 return base_.IdleSocketCountInGroup(group_name);
548 } 545 }
549 546
550 LoadState GetLoadState(const std::string& group_name, 547 LoadState GetLoadState(const std::string& group_name,
551 const ClientSocketHandle* handle) const override { 548 const ClientSocketHandle* handle) const override {
552 return base_.GetLoadState(group_name, handle); 549 return base_.GetLoadState(group_name, handle);
553 } 550 }
554 551
555 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override { 552 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override {
556 base_.AddHigherLayeredPool(higher_pool); 553 base_.AddHigherLayeredPool(higher_pool);
557 } 554 }
558 555
559 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) override { 556 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) override {
560 base_.RemoveHigherLayeredPool(higher_pool); 557 base_.RemoveHigherLayeredPool(higher_pool);
561 } 558 }
562 559
563 scoped_ptr<base::DictionaryValue> GetInfoAsValue( 560 std::unique_ptr<base::DictionaryValue> GetInfoAsValue(
564 const std::string& name, 561 const std::string& name,
565 const std::string& type, 562 const std::string& type,
566 bool include_nested_pools) const override { 563 bool include_nested_pools) const override {
567 return base_.GetInfoAsValue(name, type); 564 return base_.GetInfoAsValue(name, type);
568 } 565 }
569 566
570 base::TimeDelta ConnectionTimeout() const override { 567 base::TimeDelta ConnectionTimeout() const override {
571 return base_.ConnectionTimeout(); 568 return base_.ConnectionTimeout();
572 } 569 }
573 570
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 625 }
629 626
630 class TestConnectJobDelegate : public ConnectJob::Delegate { 627 class TestConnectJobDelegate : public ConnectJob::Delegate {
631 public: 628 public:
632 TestConnectJobDelegate() 629 TestConnectJobDelegate()
633 : have_result_(false), waiting_for_result_(false), result_(OK) {} 630 : have_result_(false), waiting_for_result_(false), result_(OK) {}
634 ~TestConnectJobDelegate() override {} 631 ~TestConnectJobDelegate() override {}
635 632
636 void OnConnectJobComplete(int result, ConnectJob* job) override { 633 void OnConnectJobComplete(int result, ConnectJob* job) override {
637 result_ = result; 634 result_ = result;
638 scoped_ptr<ConnectJob> owned_job(job); 635 std::unique_ptr<ConnectJob> owned_job(job);
639 scoped_ptr<StreamSocket> socket = owned_job->PassSocket(); 636 std::unique_ptr<StreamSocket> socket = owned_job->PassSocket();
640 // socket.get() should be NULL iff result != OK 637 // socket.get() should be NULL iff result != OK
641 EXPECT_EQ(socket == NULL, result != OK); 638 EXPECT_EQ(socket == NULL, result != OK);
642 have_result_ = true; 639 have_result_ = true;
643 if (waiting_for_result_) 640 if (waiting_for_result_)
644 base::MessageLoop::current()->QuitWhenIdle(); 641 base::MessageLoop::current()->QuitWhenIdle();
645 } 642 }
646 643
647 int WaitForResult() { 644 int WaitForResult() {
648 DCHECK(!waiting_for_result_); 645 DCHECK(!waiting_for_result_);
649 while (!have_result_) { 646 while (!have_result_) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) { 717 bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) {
721 return test_base_.ReleaseOneConnection(keep_alive); 718 return test_base_.ReleaseOneConnection(keep_alive);
722 } 719 }
723 720
724 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { 721 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) {
725 test_base_.ReleaseAllConnections(keep_alive); 722 test_base_.ReleaseAllConnections(keep_alive);
726 } 723 }
727 724
728 TestSocketRequest* request(int i) { return test_base_.request(i); } 725 TestSocketRequest* request(int i) { return test_base_.request(i); }
729 size_t requests_size() const { return test_base_.requests_size(); } 726 size_t requests_size() const { return test_base_.requests_size(); }
730 std::vector<scoped_ptr<TestSocketRequest>>* requests() { 727 std::vector<std::unique_ptr<TestSocketRequest>>* requests() {
731 return test_base_.requests(); 728 return test_base_.requests();
732 } 729 }
733 size_t completion_count() const { return test_base_.completion_count(); } 730 size_t completion_count() const { return test_base_.completion_count(); }
734 731
735 TestNetLog net_log_; 732 TestNetLog net_log_;
736 bool connect_backup_jobs_enabled_; 733 bool connect_backup_jobs_enabled_;
737 bool cleanup_timer_enabled_; 734 bool cleanup_timer_enabled_;
738 MockClientSocketFactory client_socket_factory_; 735 MockClientSocketFactory client_socket_factory_;
739 TestConnectJobFactory* connect_job_factory_; 736 TestConnectJobFactory* connect_job_factory_;
740 scoped_refptr<TestSocketParams> params_; 737 scoped_refptr<TestSocketParams> params_;
741 scoped_ptr<TestClientSocketPool> pool_; 738 std::unique_ptr<TestClientSocketPool> pool_;
742 ClientSocketPoolTest test_base_; 739 ClientSocketPoolTest test_base_;
743 }; 740 };
744 741
745 // Even though a timeout is specified, it doesn't time out on a synchronous 742 // Even though a timeout is specified, it doesn't time out on a synchronous
746 // completion. 743 // completion.
747 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { 744 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) {
748 TestConnectJobDelegate delegate; 745 TestConnectJobDelegate delegate;
749 ClientSocketHandle ignored; 746 ClientSocketHandle ignored;
750 TestClientSocketPoolBase::Request request( 747 TestClientSocketPoolBase::Request request(
751 &ignored, CompletionCallback(), DEFAULT_PRIORITY, 748 &ignored, CompletionCallback(), DEFAULT_PRIORITY,
752 ClientSocketPool::RespectLimits::ENABLED, 749 ClientSocketPool::RespectLimits::ENABLED,
753 internal::ClientSocketPoolBaseHelper::NORMAL, params_, BoundNetLog()); 750 internal::ClientSocketPoolBaseHelper::NORMAL, params_, BoundNetLog());
754 scoped_ptr<TestConnectJob> job( 751 std::unique_ptr<TestConnectJob> job(
755 new TestConnectJob(TestConnectJob::kMockJob, 752 new TestConnectJob(TestConnectJob::kMockJob, "a", request,
756 "a", 753 base::TimeDelta::FromMicroseconds(1), &delegate,
757 request, 754 &client_socket_factory_, NULL));
758 base::TimeDelta::FromMicroseconds(1),
759 &delegate,
760 &client_socket_factory_,
761 NULL));
762 EXPECT_EQ(OK, job->Connect()); 755 EXPECT_EQ(OK, job->Connect());
763 } 756 }
764 757
765 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { 758 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) {
766 TestConnectJobDelegate delegate; 759 TestConnectJobDelegate delegate;
767 ClientSocketHandle ignored; 760 ClientSocketHandle ignored;
768 TestNetLog log; 761 TestNetLog log;
769 762
770 TestClientSocketPoolBase::Request request( 763 TestClientSocketPoolBase::Request request(
771 &ignored, CompletionCallback(), DEFAULT_PRIORITY, 764 &ignored, CompletionCallback(), DEFAULT_PRIORITY,
(...skipping 3068 matching lines...) Expand 10 before | Expand all | Expand 10 after
3840 request(1)->handle()->Reset(); 3833 request(1)->handle()->Reset();
3841 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3834 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3842 3835
3843 EXPECT_EQ(OK, request(2)->WaitForResult()); 3836 EXPECT_EQ(OK, request(2)->WaitForResult());
3844 EXPECT_FALSE(request(1)->have_result()); 3837 EXPECT_FALSE(request(1)->have_result());
3845 } 3838 }
3846 3839
3847 } // namespace 3840 } // namespace
3848 3841
3849 } // namespace net 3842 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/client_socket_pool_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698