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

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

Issue 2313693002: Use modified URLRequest::Read() and delegate methods in /appcache/ (Closed)
Patch Set: michaeln's comments Created 4 years, 3 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_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>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 template <class Method> 72 template <class Method>
73 void MethodWrapper(Method method) { 73 void MethodWrapper(Method method) {
74 SetUpTest(); 74 SetUpTest();
75 (this->*method)(); 75 (this->*method)();
76 } 76 }
77 77
78 // Subclasses to simulate particular responses so test cases can 78 // Subclasses to simulate particular responses so test cases can
79 // exercise fallback code paths. 79 // exercise fallback code paths.
80 80
81 class MockURLRequestDelegate : public net::URLRequest::Delegate { 81 class MockURLRequestDelegate : public net::URLRequest::Delegate {
82 void OnResponseStarted(net::URLRequest* request) override {} 82 public:
83 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} 83 MockURLRequestDelegate() : request_status_(1) {}
84
85 void OnResponseStarted(net::URLRequest* request, int net_error) override {
86 DCHECK_NE(net::ERR_IO_PENDING, net_error);
87 request_status_ = net_error;
88 }
89
90 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {
91 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
92 if (bytes_read >= 0)
93 request_status_ = net::OK;
94 else
95 request_status_ = bytes_read;
96 }
97
98 int request_status() const { return request_status_; }
99
100 private:
101 int request_status_;
84 }; 102 };
85 103
86 class MockURLRequestJob : public net::URLRequestJob { 104 class MockURLRequestJob : public net::URLRequestJob {
87 public: 105 public:
88 MockURLRequestJob(net::URLRequest* request, 106 MockURLRequestJob(net::URLRequest* request,
89 net::NetworkDelegate* network_delegate, 107 net::NetworkDelegate* network_delegate,
90 int response_code) 108 int response_code)
91 : net::URLRequestJob(request, network_delegate), 109 : net::URLRequestJob(request, network_delegate),
92 response_code_(response_code), 110 response_code_(response_code),
93 has_response_info_(false) {} 111 has_response_info_(false) {}
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // We have to wait for completion of storage->FindResponseForMainRequest. 396 // We have to wait for completion of storage->FindResponseForMainRequest.
379 ScheduleNextTask(); 397 ScheduleNextTask();
380 } 398 }
381 399
382 void SimulateResponseCode(int response_code) { 400 void SimulateResponseCode(int response_code) {
383 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 401 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
384 request_.get(), request_->context()->network_delegate(), 402 request_.get(), request_->context()->network_delegate(),
385 response_code)); 403 response_code));
386 request_->Start(); 404 request_->Start();
387 // All our simulation needs to satisfy are the following two DCHECKs 405 // All our simulation needs to satisfy are the following two DCHECKs
388 DCHECK(request_->status().is_success()); 406 DCHECK_EQ(net::OK, delegate_.request_status());
389 DCHECK_EQ(response_code, request_->GetResponseCode()); 407 DCHECK_EQ(response_code, request_->GetResponseCode());
390 } 408 }
391 409
392 void SimulateResponseInfo(const net::HttpResponseInfo& info) { 410 void SimulateResponseInfo(const net::HttpResponseInfo& info) {
393 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 411 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
394 request_.get(), request_->context()->network_delegate(), info)); 412 request_.get(), request_->context()->network_delegate(), info));
395 request_->Start(); 413 request_->Start();
396 } 414 }
397 415
398 void Verify_MainResource_Fallback() { 416 void Verify_MainResource_Fallback() {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 1123
1106 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { 1124 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) {
1107 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); 1125 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest);
1108 } 1126 }
1109 1127
1110 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { 1128 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
1111 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); 1129 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked);
1112 } 1130 }
1113 1131
1114 } // namespace content 1132 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/appcache/appcache_update_job.h » ('j') | content/browser/appcache/appcache_update_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698