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

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: use net::ERR_IO_PENDING as initial value 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
michaeln 2016/09/07 20:49:39 nit: you can delete the blank line and after the d
maksims (do not use this acc) 2016/09/12 12:45:58 Done.
88 request_status_ = net_error;
89 }
90 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {
91 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
92
93 if (bytes_read >= 0)
94 request_status_ = net::OK;
95 else
96 request_status_ = bytes_read;
97 }
98
99 int request_status() { return request_status_; }
michaeln 2016/09/07 20:49:39 could be const
maksims (do not use this acc) 2016/09/12 12:45:58 Done.
100
101 private:
102 int request_status_;
84 }; 103 };
85 104
86 class MockURLRequestJob : public net::URLRequestJob { 105 class MockURLRequestJob : public net::URLRequestJob {
87 public: 106 public:
88 MockURLRequestJob(net::URLRequest* request, 107 MockURLRequestJob(net::URLRequest* request,
89 net::NetworkDelegate* network_delegate, 108 net::NetworkDelegate* network_delegate,
90 int response_code) 109 int response_code)
91 : net::URLRequestJob(request, network_delegate), 110 : net::URLRequestJob(request, network_delegate),
92 response_code_(response_code), 111 response_code_(response_code),
93 has_response_info_(false) {} 112 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. 397 // We have to wait for completion of storage->FindResponseForMainRequest.
379 ScheduleNextTask(); 398 ScheduleNextTask();
380 } 399 }
381 400
382 void SimulateResponseCode(int response_code) { 401 void SimulateResponseCode(int response_code) {
383 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 402 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
384 request_.get(), request_->context()->network_delegate(), 403 request_.get(), request_->context()->network_delegate(),
385 response_code)); 404 response_code));
386 request_->Start(); 405 request_->Start();
387 // All our simulation needs to satisfy are the following two DCHECKs 406 // All our simulation needs to satisfy are the following two DCHECKs
388 DCHECK(request_->status().is_success()); 407 DCHECK_EQ(net::OK, delegate_.request_status());
389 DCHECK_EQ(response_code, request_->GetResponseCode()); 408 DCHECK_EQ(response_code, request_->GetResponseCode());
390 } 409 }
391 410
392 void SimulateResponseInfo(const net::HttpResponseInfo& info) { 411 void SimulateResponseInfo(const net::HttpResponseInfo& info) {
393 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>( 412 job_factory_->SetJob(base::MakeUnique<MockURLRequestJob>(
394 request_.get(), request_->context()->network_delegate(), info)); 413 request_.get(), request_->context()->network_delegate(), info));
395 request_->Start(); 414 request_->Start();
396 } 415 }
397 416
398 void Verify_MainResource_Fallback() { 417 void Verify_MainResource_Fallback() {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 1124
1106 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { 1125 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) {
1107 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); 1126 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest);
1108 } 1127 }
1109 1128
1110 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { 1129 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
1111 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); 1130 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked);
1112 } 1131 }
1113 1132
1114 } // namespace content 1133 } // 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