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

Side by Side Diff: content/browser/appcache/appcache_url_request_job_unittest.cc

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (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
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 "content/browser/appcache/appcache_url_request_job.h"
6
5 #include <stdint.h> 7 #include <stdint.h>
6 #include <string.h> 8 #include <string.h>
7 9
10 #include <memory>
8 #include <stack> 11 #include <stack>
9 #include <utility> 12 #include <utility>
10 13
11 #include "base/bind.h" 14 #include "base/bind.h"
12 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
13 #include "base/callback.h" 16 #include "base/callback.h"
14 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
15 #include "base/location.h" 18 #include "base/location.h"
16 #include "base/logging.h" 19 #include "base/logging.h"
17 #include "base/macros.h" 20 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
20 #include "base/pickle.h" 22 #include "base/pickle.h"
21 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
22 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
23 #include "base/thread_task_runner_handle.h" 25 #include "base/thread_task_runner_handle.h"
24 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
25 #include "content/browser/appcache/appcache_response.h" 27 #include "content/browser/appcache/appcache_response.h"
26 #include "content/browser/appcache/appcache_url_request_job.h"
27 #include "content/browser/appcache/mock_appcache_service.h" 28 #include "content/browser/appcache/mock_appcache_service.h"
28 #include "net/base/io_buffer.h" 29 #include "net/base/io_buffer.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/base/request_priority.h" 31 #include "net/base/request_priority.h"
31 #include "net/http/http_response_headers.h" 32 #include "net/http/http_response_headers.h"
32 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
33 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
34 #include "net/url_request/url_request_error_job.h" 35 #include "net/url_request/url_request_error_job.h"
35 #include "net/url_request/url_request_job_factory.h" 36 #include "net/url_request/url_request_job_factory.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 26 matching lines...) Expand all
63 EXPECT_FALSE(*value); 64 EXPECT_FALSE(*value);
64 *value = true; 65 *value = true;
65 } 66 }
66 67
67 class MockURLRequestJobFactory : public net::URLRequestJobFactory { 68 class MockURLRequestJobFactory : public net::URLRequestJobFactory {
68 public: 69 public:
69 MockURLRequestJobFactory() {} 70 MockURLRequestJobFactory() {}
70 71
71 ~MockURLRequestJobFactory() override { DCHECK(!job_); } 72 ~MockURLRequestJobFactory() override { DCHECK(!job_); }
72 73
73 void SetJob(scoped_ptr<net::URLRequestJob> job) { job_ = std::move(job); } 74 void SetJob(std::unique_ptr<net::URLRequestJob> job) {
75 job_ = std::move(job);
76 }
74 77
75 bool has_job() const { return job_.get() != nullptr; } 78 bool has_job() const { return job_.get() != nullptr; }
76 79
77 // net::URLRequestJobFactory implementation. 80 // net::URLRequestJobFactory implementation.
78 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 81 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
79 const std::string& scheme, 82 const std::string& scheme,
80 net::URLRequest* request, 83 net::URLRequest* request,
81 net::NetworkDelegate* network_delegate) const override { 84 net::NetworkDelegate* network_delegate) const override {
82 if (job_) { 85 if (job_) {
83 return job_.release(); 86 return job_.release();
(...skipping 24 matching lines...) Expand all
108 bool IsHandledURL(const GURL& url) const override { 111 bool IsHandledURL(const GURL& url) const override {
109 return url.SchemeIs("http"); 112 return url.SchemeIs("http");
110 } 113 }
111 114
112 bool IsSafeRedirectTarget(const GURL& location) const override { 115 bool IsSafeRedirectTarget(const GURL& location) const override {
113 return false; 116 return false;
114 } 117 }
115 118
116 private: 119 private:
117 // This is mutable because MaybeCreateJobWithProtocolHandler is const. 120 // This is mutable because MaybeCreateJobWithProtocolHandler is const.
118 mutable scoped_ptr<net::URLRequestJob> job_; 121 mutable std::unique_ptr<net::URLRequestJob> job_;
119 }; 122 };
120 123
121 } // namespace 124 } // namespace
122 125
123 class AppCacheURLRequestJobTest : public testing::Test { 126 class AppCacheURLRequestJobTest : public testing::Test {
124 public: 127 public:
125 128
126 // Test Harness ------------------------------------------------------------- 129 // Test Harness -------------------------------------------------------------
127 // TODO(michaeln): share this test harness with AppCacheResponseTest 130 // TODO(michaeln): share this test harness with AppCacheResponseTest
128 131
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // is delineated with a section header. 451 // is delineated with a section header.
449 452
450 // Basic ------------------------------------------------------------------- 453 // Basic -------------------------------------------------------------------
451 void Basic() { 454 void Basic() {
452 AppCacheStorage* storage = service_->storage(); 455 AppCacheStorage* storage = service_->storage();
453 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 456 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
454 net::DEFAULT_PRIORITY, nullptr); 457 net::DEFAULT_PRIORITY, nullptr);
455 458
456 // Create an instance and see that it looks as expected. 459 // Create an instance and see that it looks as expected.
457 460
458 scoped_ptr<AppCacheURLRequestJob> job( 461 std::unique_ptr<AppCacheURLRequestJob> job(
459 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr, 462 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr,
460 false, base::Bind(&ExpectNotRestarted))); 463 false, base::Bind(&ExpectNotRestarted)));
461 EXPECT_TRUE(job->is_waiting()); 464 EXPECT_TRUE(job->is_waiting());
462 EXPECT_FALSE(job->is_delivering_appcache_response()); 465 EXPECT_FALSE(job->is_delivering_appcache_response());
463 EXPECT_FALSE(job->is_delivering_network_response()); 466 EXPECT_FALSE(job->is_delivering_network_response());
464 EXPECT_FALSE(job->is_delivering_error_response()); 467 EXPECT_FALSE(job->is_delivering_error_response());
465 EXPECT_FALSE(job->has_been_started()); 468 EXPECT_FALSE(job->has_been_started());
466 EXPECT_FALSE(job->has_been_killed()); 469 EXPECT_FALSE(job->has_been_killed());
467 EXPECT_EQ(GURL(), job->manifest_url()); 470 EXPECT_EQ(GURL(), job->manifest_url());
468 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id()); 471 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id());
469 EXPECT_FALSE(job->entry().has_response_id()); 472 EXPECT_FALSE(job->entry().has_response_id());
470 473
471 TestFinished(); 474 TestFinished();
472 } 475 }
473 476
474 // DeliveryOrders ----------------------------------------------------- 477 // DeliveryOrders -----------------------------------------------------
475 void DeliveryOrders() { 478 void DeliveryOrders() {
476 AppCacheStorage* storage = service_->storage(); 479 AppCacheStorage* storage = service_->storage();
477 scoped_ptr<net::URLRequest> request(empty_context_->CreateRequest( 480 std::unique_ptr<net::URLRequest> request(empty_context_->CreateRequest(
478 GURL("http://blah/"), net::DEFAULT_PRIORITY, nullptr)); 481 GURL("http://blah/"), net::DEFAULT_PRIORITY, nullptr));
479 482
480 // Create an instance, give it a delivery order and see that 483 // Create an instance, give it a delivery order and see that
481 // it looks as expected. 484 // it looks as expected.
482 485
483 scoped_ptr<AppCacheURLRequestJob> job( 486 std::unique_ptr<AppCacheURLRequestJob> job(
484 new AppCacheURLRequestJob(request.get(), nullptr, storage, nullptr, 487 new AppCacheURLRequestJob(request.get(), nullptr, storage, nullptr,
485 false, base::Bind(&ExpectNotRestarted))); 488 false, base::Bind(&ExpectNotRestarted)));
486 job->DeliverErrorResponse(); 489 job->DeliverErrorResponse();
487 EXPECT_TRUE(job->is_delivering_error_response()); 490 EXPECT_TRUE(job->is_delivering_error_response());
488 EXPECT_FALSE(job->has_been_started()); 491 EXPECT_FALSE(job->has_been_started());
489 492
490 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage, 493 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage,
491 nullptr, false, 494 nullptr, false,
492 base::Bind(&ExpectNotRestarted))); 495 base::Bind(&ExpectNotRestarted)));
493 job->DeliverNetworkResponse(); 496 job->DeliverNetworkResponse();
(...skipping 29 matching lines...) Expand all
523 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, 526 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse,
524 base::Unretained(this))); 527 base::Unretained(this)));
525 528
526 AppCacheStorage* storage = service_->storage(); 529 AppCacheStorage* storage = service_->storage();
527 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 530 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
528 net::DEFAULT_PRIORITY, 531 net::DEFAULT_PRIORITY,
529 url_request_delegate_.get()); 532 url_request_delegate_.get());
530 533
531 // Set up to create an AppCacheURLRequestJob with orders to deliver 534 // Set up to create an AppCacheURLRequestJob with orders to deliver
532 // a network response. 535 // a network response.
533 scoped_ptr<AppCacheURLRequestJob> mock_job(new AppCacheURLRequestJob( 536 std::unique_ptr<AppCacheURLRequestJob> mock_job(new AppCacheURLRequestJob(
534 request_.get(), nullptr, storage, nullptr, false, 537 request_.get(), nullptr, storage, nullptr, false,
535 base::Bind(&SetIfCalled, &restart_callback_invoked_))); 538 base::Bind(&SetIfCalled, &restart_callback_invoked_)));
536 mock_job->DeliverNetworkResponse(); 539 mock_job->DeliverNetworkResponse();
537 EXPECT_TRUE(mock_job->is_delivering_network_response()); 540 EXPECT_TRUE(mock_job->is_delivering_network_response());
538 EXPECT_FALSE(mock_job->has_been_started()); 541 EXPECT_FALSE(mock_job->has_been_started());
539 job_factory_->SetJob(std::move(mock_job)); 542 job_factory_->SetJob(std::move(mock_job));
540 543
541 // Start the request. 544 // Start the request.
542 request_->Start(); 545 request_->Start();
543 546
(...skipping 17 matching lines...) Expand all
561 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, 564 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse,
562 base::Unretained(this))); 565 base::Unretained(this)));
563 566
564 AppCacheStorage* storage = service_->storage(); 567 AppCacheStorage* storage = service_->storage();
565 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 568 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
566 net::DEFAULT_PRIORITY, 569 net::DEFAULT_PRIORITY,
567 url_request_delegate_.get()); 570 url_request_delegate_.get());
568 571
569 // Setup to create an AppCacheURLRequestJob with orders to deliver 572 // Setup to create an AppCacheURLRequestJob with orders to deliver
570 // a network response. 573 // a network response.
571 scoped_ptr<AppCacheURLRequestJob> mock_job( 574 std::unique_ptr<AppCacheURLRequestJob> mock_job(
572 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr, 575 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr,
573 false, base::Bind(&ExpectNotRestarted))); 576 false, base::Bind(&ExpectNotRestarted)));
574 mock_job->DeliverErrorResponse(); 577 mock_job->DeliverErrorResponse();
575 EXPECT_TRUE(mock_job->is_delivering_error_response()); 578 EXPECT_TRUE(mock_job->is_delivering_error_response());
576 EXPECT_FALSE(mock_job->has_been_started()); 579 EXPECT_FALSE(mock_job->has_been_started());
577 job_factory_->SetJob(std::move(mock_job)); 580 job_factory_->SetJob(std::move(mock_job));
578 581
579 // Start the request. 582 // Start the request.
580 request_->Start(); 583 request_->Start();
581 584
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 616 }
614 617
615 void RequestAppCachedResource(bool start_after_delivery_orders) { 618 void RequestAppCachedResource(bool start_after_delivery_orders) {
616 AppCacheStorage* storage = service_->storage(); 619 AppCacheStorage* storage = service_->storage();
617 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 620 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
618 net::DEFAULT_PRIORITY, 621 net::DEFAULT_PRIORITY,
619 url_request_delegate_.get()); 622 url_request_delegate_.get());
620 623
621 // Setup to create an AppCacheURLRequestJob with orders to deliver 624 // Setup to create an AppCacheURLRequestJob with orders to deliver
622 // a network response. 625 // a network response.
623 scoped_ptr<AppCacheURLRequestJob> job( 626 std::unique_ptr<AppCacheURLRequestJob> job(
624 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false, 627 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false,
625 base::Bind(&ExpectNotRestarted))); 628 base::Bind(&ExpectNotRestarted)));
626 629
627 if (start_after_delivery_orders) { 630 if (start_after_delivery_orders) {
628 job->DeliverAppCachedResponse( 631 job->DeliverAppCachedResponse(
629 GURL(), 0, 111, 632 GURL(), 0, 111,
630 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 633 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
631 false); 634 false);
632 EXPECT_TRUE(job->is_delivering_appcache_response()); 635 EXPECT_TRUE(job->is_delivering_appcache_response());
633 } 636 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 737 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
735 net::DEFAULT_PRIORITY, 738 net::DEFAULT_PRIORITY,
736 url_request_delegate_.get()); 739 url_request_delegate_.get());
737 740
738 // Request a range, the 3 middle chars out of 'Hello' 741 // Request a range, the 3 middle chars out of 'Hello'
739 net::HttpRequestHeaders extra_headers; 742 net::HttpRequestHeaders extra_headers;
740 extra_headers.SetHeader("Range", "bytes= 1-3"); 743 extra_headers.SetHeader("Range", "bytes= 1-3");
741 request_->SetExtraRequestHeaders(extra_headers); 744 request_->SetExtraRequestHeaders(extra_headers);
742 745
743 // Create job with orders to deliver an appcached entry. 746 // Create job with orders to deliver an appcached entry.
744 scoped_ptr<AppCacheURLRequestJob> job( 747 std::unique_ptr<AppCacheURLRequestJob> job(
745 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false, 748 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false,
746 base::Bind(&ExpectNotRestarted))); 749 base::Bind(&ExpectNotRestarted)));
747 job->DeliverAppCachedResponse( 750 job->DeliverAppCachedResponse(
748 GURL(), 0, 111, 751 GURL(), 0, 111,
749 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 752 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
750 false); 753 false);
751 EXPECT_TRUE(job->is_delivering_appcache_response()); 754 EXPECT_TRUE(job->is_delivering_appcache_response());
752 755
753 // Start the request. 756 // Start the request.
754 EXPECT_FALSE(job->has_been_started()); 757 EXPECT_FALSE(job->has_been_started());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 WriteLargeResponse(); 828 WriteLargeResponse();
826 829
827 url_request_delegate_->kill_after_amount_received_ = kBlockSize; 830 url_request_delegate_->kill_after_amount_received_ = kBlockSize;
828 url_request_delegate_->kill_with_io_pending_ = true; 831 url_request_delegate_->kill_with_io_pending_ = true;
829 // Continues async 832 // Continues async
830 } 833 }
831 834
832 835
833 // Data members -------------------------------------------------------- 836 // Data members --------------------------------------------------------
834 837
835 scoped_ptr<base::WaitableEvent> test_finished_event_; 838 std::unique_ptr<base::WaitableEvent> test_finished_event_;
836 scoped_ptr<MockStorageDelegate> storage_delegate_; 839 std::unique_ptr<MockStorageDelegate> storage_delegate_;
837 scoped_ptr<MockAppCacheService> service_; 840 std::unique_ptr<MockAppCacheService> service_;
838 std::stack<std::pair<base::Closure, bool> > task_stack_; 841 std::stack<std::pair<base::Closure, bool> > task_stack_;
839 842
840 scoped_ptr<AppCacheResponseReader> reader_; 843 std::unique_ptr<AppCacheResponseReader> reader_;
841 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_; 844 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
842 scoped_refptr<IOBuffer> read_buffer_; 845 scoped_refptr<IOBuffer> read_buffer_;
843 int expected_read_result_; 846 int expected_read_result_;
844 int reader_deletion_count_down_; 847 int reader_deletion_count_down_;
845 848
846 int64_t written_response_id_; 849 int64_t written_response_id_;
847 scoped_ptr<AppCacheResponseWriter> writer_; 850 std::unique_ptr<AppCacheResponseWriter> writer_;
848 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; 851 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_;
849 scoped_refptr<IOBuffer> write_buffer_; 852 scoped_refptr<IOBuffer> write_buffer_;
850 int expected_write_result_; 853 int expected_write_result_;
851 int writer_deletion_count_down_; 854 int writer_deletion_count_down_;
852 855
853 bool restart_callback_invoked_; 856 bool restart_callback_invoked_;
854 857
855 scoped_ptr<MockURLRequestJobFactory> job_factory_; 858 std::unique_ptr<MockURLRequestJobFactory> job_factory_;
856 scoped_ptr<net::URLRequestContext> empty_context_; 859 std::unique_ptr<net::URLRequestContext> empty_context_;
857 scoped_ptr<net::URLRequest> request_; 860 std::unique_ptr<net::URLRequest> request_;
858 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; 861 std::unique_ptr<MockURLRequestDelegate> url_request_delegate_;
859 862
860 static scoped_ptr<base::Thread> io_thread_; 863 static std::unique_ptr<base::Thread> io_thread_;
861 }; 864 };
862 865
863 // static 866 // static
864 scoped_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_; 867 std::unique_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_;
865 868
866 TEST_F(AppCacheURLRequestJobTest, Basic) { 869 TEST_F(AppCacheURLRequestJobTest, Basic) {
867 RunTestOnIOThread(&AppCacheURLRequestJobTest::Basic); 870 RunTestOnIOThread(&AppCacheURLRequestJobTest::Basic);
868 } 871 }
869 872
870 TEST_F(AppCacheURLRequestJobTest, DeliveryOrders) { 873 TEST_F(AppCacheURLRequestJobTest, DeliveryOrders) {
871 RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliveryOrders); 874 RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliveryOrders);
872 } 875 }
873 876
874 TEST_F(AppCacheURLRequestJobTest, DeliverNetworkResponse) { 877 TEST_F(AppCacheURLRequestJobTest, DeliverNetworkResponse) {
(...skipping 18 matching lines...) Expand all
893 896
894 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { 897 TEST_F(AppCacheURLRequestJobTest, CancelRequest) {
895 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); 898 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest);
896 } 899 }
897 900
898 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 901 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
899 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 902 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
900 } 903 }
901 904
902 } // namespace content 905 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.h ('k') | content/browser/appcache/mock_appcache_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698