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

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

Issue 2824583003: Remove URLRequestJob::GetResponseCode implementations from AppCache. (Closed)
Patch Set: Fix Created 3 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 | « no previous file | content/browser/appcache/appcache_update_job_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 // 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_request_handler.h" 5 #include "content/browser/appcache/appcache_request_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <stack> 9 #include <stack>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/stringprintf.h"
22 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
25 #include "content/browser/appcache/appcache.h" 26 #include "content/browser/appcache/appcache.h"
26 #include "content/browser/appcache/appcache_backend_impl.h" 27 #include "content/browser/appcache/appcache_backend_impl.h"
27 #include "content/browser/appcache/appcache_url_request_job.h" 28 #include "content/browser/appcache/appcache_url_request_job.h"
28 #include "content/browser/appcache/mock_appcache_policy.h" 29 #include "content/browser/appcache/mock_appcache_policy.h"
29 #include "content/browser/appcache/mock_appcache_service.h" 30 #include "content/browser/appcache/mock_appcache_service.h"
30 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
31 #include "net/base/request_priority.h" 32 #include "net/base/request_priority.h"
32 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
34 #include "net/http/http_util.h"
33 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
34 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
35 #include "net/url_request/url_request_error_job.h" 37 #include "net/url_request/url_request_error_job.h"
36 #include "net/url_request/url_request_job_factory.h" 38 #include "net/url_request/url_request_job_factory.h"
37 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
38 40
39 namespace content { 41 namespace content {
40 42
41 static const int kMockProcessId = 1; 43 static const int kMockProcessId = 1;
42 44
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int request_status() const { return request_status_; } 100 int request_status() const { return request_status_; }
99 101
100 private: 102 private:
101 int request_status_; 103 int request_status_;
102 }; 104 };
103 105
104 class MockURLRequestJob : public net::URLRequestJob { 106 class MockURLRequestJob : public net::URLRequestJob {
105 public: 107 public:
106 MockURLRequestJob(net::URLRequest* request, 108 MockURLRequestJob(net::URLRequest* request,
107 net::NetworkDelegate* network_delegate, 109 net::NetworkDelegate* network_delegate,
108 int response_code)
109 : net::URLRequestJob(request, network_delegate),
110 response_code_(response_code),
111 has_response_info_(false) {}
112 MockURLRequestJob(net::URLRequest* request,
113 net::NetworkDelegate* network_delegate,
114 const net::HttpResponseInfo& info) 110 const net::HttpResponseInfo& info)
115 : net::URLRequestJob(request, network_delegate), 111 : net::URLRequestJob(request, network_delegate),
116 response_code_(info.headers->response_code()),
117 has_response_info_(true), 112 has_response_info_(true),
118 response_info_(info) {} 113 response_info_(info) {}
119 114
120 ~MockURLRequestJob() override {} 115 ~MockURLRequestJob() override {}
121 116
122 protected: 117 protected:
123 void Start() override { NotifyHeadersComplete(); } 118 void Start() override { NotifyHeadersComplete(); }
124 int GetResponseCode() const override { return response_code_; }
125 void GetResponseInfo(net::HttpResponseInfo* info) override { 119 void GetResponseInfo(net::HttpResponseInfo* info) override {
126 if (!has_response_info_) 120 if (!has_response_info_)
127 return; 121 return;
128 *info = response_info_; 122 *info = response_info_;
129 } 123 }
130 124
131 private: 125 private:
132 int response_code_;
133 bool has_response_info_; 126 bool has_response_info_;
134 net::HttpResponseInfo response_info_; 127 net::HttpResponseInfo response_info_;
135 }; 128 };
136 129
137 class MockURLRequestJobFactory : public net::URLRequestJobFactory { 130 class MockURLRequestJobFactory : public net::URLRequestJobFactory {
138 public: 131 public:
139 MockURLRequestJobFactory() {} 132 MockURLRequestJobFactory() {}
140 133
141 ~MockURLRequestJobFactory() override { DCHECK(!job_); } 134 ~MockURLRequestJobFactory() override { DCHECK(!job_); }
142 135
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 job_.reset(handler_->MaybeLoadResource( 383 job_.reset(handler_->MaybeLoadResource(
391 request_.get(), request_->context()->network_delegate())); 384 request_.get(), request_->context()->network_delegate()));
392 EXPECT_TRUE(job_.get()); 385 EXPECT_TRUE(job_.get());
393 EXPECT_TRUE(job_->is_waiting()); 386 EXPECT_TRUE(job_->is_waiting());
394 387
395 // We have to wait for completion of storage->FindResponseForMainRequest. 388 // We have to wait for completion of storage->FindResponseForMainRequest.
396 ScheduleNextTask(); 389 ScheduleNextTask();
397 } 390 }
398 391
399 void SimulateResponseCode(int response_code) { 392 void SimulateResponseCode(int response_code) {
393 net::HttpResponseInfo info;
394 std::string headers =
395 base::StringPrintf("HTTP/1.1 %i Muffin\r\n\r\n", response_code);
396 info.headers = new net::HttpResponseHeaders(
397 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.length()));
398
400 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 399 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
401 request_.get(), request_->context()->network_delegate(), 400 request_.get(), request_->context()->network_delegate(), info));
402 response_code));
403 request_->Start(); 401 request_->Start();
404 // All our simulation needs to satisfy are the following two DCHECKs 402 // All our simulation needs to satisfy are the following two DCHECKs.
405 DCHECK_EQ(net::OK, delegate_.request_status()); 403 DCHECK_EQ(net::OK, delegate_.request_status());
406 DCHECK_EQ(response_code, request_->GetResponseCode()); 404 DCHECK_EQ(response_code, request_->GetResponseCode());
407 } 405 }
408 406
409 void SimulateResponseInfo(const net::HttpResponseInfo& info) { 407 void SimulateResponseInfo(const net::HttpResponseInfo& info) {
410 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 408 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
411 request_.get(), request_->context()->network_delegate(), info)); 409 request_.get(), request_->context()->network_delegate(), info));
412 request_->Start(); 410 request_->Start();
413 } 411 }
414 412
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 1120
1123 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { 1121 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) {
1124 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); 1122 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest);
1125 } 1123 }
1126 1124
1127 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { 1125 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
1128 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); 1126 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked);
1129 } 1127 }
1130 1128
1131 } // namespace content 1129 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/appcache/appcache_update_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698