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

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

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 <stack> 5 #include <stack>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 28 matching lines...) Expand all
39 const char kHttpBasicBody[] = "Hello"; 39 const char kHttpBasicBody[] = "Hello";
40 40
41 const int kNumBlocks = 4; 41 const int kNumBlocks = 4;
42 const int kBlockSize = 1024; 42 const int kBlockSize = 1024;
43 43
44 class MockURLRequestJobFactory : public net::URLRequestJobFactory { 44 class MockURLRequestJobFactory : public net::URLRequestJobFactory {
45 public: 45 public:
46 MockURLRequestJobFactory() : job_(NULL) { 46 MockURLRequestJobFactory() : job_(NULL) {
47 } 47 }
48 48
49 virtual ~MockURLRequestJobFactory() { 49 ~MockURLRequestJobFactory() override { DCHECK(!job_); }
50 DCHECK(!job_);
51 }
52 50
53 void SetJob(net::URLRequestJob* job) { 51 void SetJob(net::URLRequestJob* job) {
54 job_ = job; 52 job_ = job;
55 } 53 }
56 54
57 bool has_job() const { 55 bool has_job() const {
58 return job_ != NULL; 56 return job_ != NULL;
59 } 57 }
60 58
61 // net::URLRequestJobFactory implementation. 59 // net::URLRequestJobFactory implementation.
62 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 60 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
63 const std::string& scheme, 61 const std::string& scheme,
64 net::URLRequest* request, 62 net::URLRequest* request,
65 net::NetworkDelegate* network_delegate) const override { 63 net::NetworkDelegate* network_delegate) const override {
66 if (job_) { 64 if (job_) {
67 net::URLRequestJob* temp = job_; 65 net::URLRequestJob* temp = job_;
68 job_ = NULL; 66 job_ = NULL;
69 return temp; 67 return temp;
70 } else { 68 } else {
71 return new net::URLRequestErrorJob(request, 69 return new net::URLRequestErrorJob(request,
72 network_delegate, 70 network_delegate,
73 net::ERR_INTERNET_DISCONNECTED); 71 net::ERR_INTERNET_DISCONNECTED);
74 } 72 }
75 } 73 }
76 74
77 virtual bool IsHandledProtocol(const std::string& scheme) const override { 75 bool IsHandledProtocol(const std::string& scheme) const override {
78 return scheme == "http"; 76 return scheme == "http";
79 }; 77 };
80 78
81 virtual bool IsHandledURL(const GURL& url) const override { 79 bool IsHandledURL(const GURL& url) const override {
82 return url.SchemeIs("http"); 80 return url.SchemeIs("http");
83 } 81 }
84 82
85 virtual bool IsSafeRedirectTarget(const GURL& location) const override { 83 bool IsSafeRedirectTarget(const GURL& location) const override {
86 return false; 84 return false;
87 } 85 }
88 86
89 private: 87 private:
90 mutable net::URLRequestJob* job_; 88 mutable net::URLRequestJob* job_;
91 }; 89 };
92 90
93 class AppCacheURLRequestJobTest : public testing::Test { 91 class AppCacheURLRequestJobTest : public testing::Test {
94 public: 92 public:
95 93
96 // Test Harness ------------------------------------------------------------- 94 // Test Harness -------------------------------------------------------------
97 // TODO(michaeln): share this test harness with AppCacheResponseTest 95 // TODO(michaeln): share this test harness with AppCacheResponseTest
98 96
99 class MockStorageDelegate : public AppCacheStorage::Delegate { 97 class MockStorageDelegate : public AppCacheStorage::Delegate {
100 public: 98 public:
101 explicit MockStorageDelegate(AppCacheURLRequestJobTest* test) 99 explicit MockStorageDelegate(AppCacheURLRequestJobTest* test)
102 : loaded_info_id_(0), test_(test) { 100 : loaded_info_id_(0), test_(test) {
103 } 101 }
104 102
105 virtual void OnResponseInfoLoaded(AppCacheResponseInfo* info, 103 void OnResponseInfoLoaded(AppCacheResponseInfo* info,
106 int64 response_id) override { 104 int64 response_id) override {
107 loaded_info_ = info; 105 loaded_info_ = info;
108 loaded_info_id_ = response_id; 106 loaded_info_id_ = response_id;
109 test_->ScheduleNextTask(); 107 test_->ScheduleNextTask();
110 } 108 }
111 109
112 scoped_refptr<AppCacheResponseInfo> loaded_info_; 110 scoped_refptr<AppCacheResponseInfo> loaded_info_;
113 int64 loaded_info_id_; 111 int64 loaded_info_id_;
114 AppCacheURLRequestJobTest* test_; 112 AppCacheURLRequestJobTest* test_;
115 }; 113 };
116 114
117 class MockURLRequestDelegate : public net::URLRequest::Delegate { 115 class MockURLRequestDelegate : public net::URLRequest::Delegate {
118 public: 116 public:
119 explicit MockURLRequestDelegate(AppCacheURLRequestJobTest* test) 117 explicit MockURLRequestDelegate(AppCacheURLRequestJobTest* test)
120 : test_(test), 118 : test_(test),
121 received_data_(new net::IOBuffer(kNumBlocks * kBlockSize)), 119 received_data_(new net::IOBuffer(kNumBlocks * kBlockSize)),
122 did_receive_headers_(false), amount_received_(0), 120 did_receive_headers_(false), amount_received_(0),
123 kill_after_amount_received_(0), kill_with_io_pending_(false) { 121 kill_after_amount_received_(0), kill_with_io_pending_(false) {
124 } 122 }
125 123
126 virtual void OnResponseStarted(net::URLRequest* request) override { 124 void OnResponseStarted(net::URLRequest* request) override {
127 amount_received_ = 0; 125 amount_received_ = 0;
128 did_receive_headers_ = false; 126 did_receive_headers_ = false;
129 if (request->status().is_success()) { 127 if (request->status().is_success()) {
130 EXPECT_TRUE(request->response_headers()); 128 EXPECT_TRUE(request->response_headers());
131 did_receive_headers_ = true; 129 did_receive_headers_ = true;
132 received_info_ = request->response_info(); 130 received_info_ = request->response_info();
133 ReadSome(request); 131 ReadSome(request);
134 } else { 132 } else {
135 RequestComplete(); 133 RequestComplete();
136 } 134 }
137 } 135 }
138 136
139 virtual void OnReadCompleted(net::URLRequest* request, 137 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {
140 int bytes_read) override {
141 if (bytes_read > 0) { 138 if (bytes_read > 0) {
142 amount_received_ += bytes_read; 139 amount_received_ += bytes_read;
143 140
144 if (kill_after_amount_received_ && !kill_with_io_pending_) { 141 if (kill_after_amount_received_ && !kill_with_io_pending_) {
145 if (amount_received_ >= kill_after_amount_received_) { 142 if (amount_received_ >= kill_after_amount_received_) {
146 request->Cancel(); 143 request->Cancel();
147 return; 144 return;
148 } 145 }
149 } 146 }
150 147
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); 851 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest);
855 } 852 }
856 853
857 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 854 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
858 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 855 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
859 } 856 }
860 857
861 } // namespace 858 } // namespace
862 859
863 } // namespace content 860 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.h ('k') | content/browser/appcache/chrome_appcache_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698