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

Side by Side Diff: content/browser/appcache/appcache_update_job_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
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_update_job.h" 5 #include "content/browser/appcache/appcache_update_job.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/stringprintf.h"
19 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
20 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "content/browser/appcache/appcache_group.h" 23 #include "content/browser/appcache/appcache_group.h"
23 #include "content/browser/appcache/appcache_host.h" 24 #include "content/browser/appcache/appcache_host.h"
24 #include "content/browser/appcache/appcache_response.h" 25 #include "content/browser/appcache/appcache_response.h"
25 #include "content/browser/appcache/mock_appcache_service.h" 26 #include "content/browser/appcache/mock_appcache_service.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
29 #include "net/http/http_util.h"
28 #include "net/url_request/url_request_error_job.h" 30 #include "net/url_request/url_request_error_job.h"
29 #include "net/url_request/url_request_job_factory_impl.h" 31 #include "net/url_request/url_request_job_factory_impl.h"
30 #include "net/url_request/url_request_test_job.h" 32 #include "net/url_request/url_request_test_job.h"
31 #include "net/url_request/url_request_test_util.h" 33 #include "net/url_request/url_request_test_util.h"
32 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
33 35
34 namespace content { 36 namespace content {
35 class AppCacheUpdateJobTest; 37 class AppCacheUpdateJobTest;
36 38
37 namespace { 39 namespace {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 EXPECT_EQ(expected_requests_, num_requests_); 396 EXPECT_EQ(expected_requests_, num_requests_);
395 num_requests_ = 0; 397 num_requests_ = 0;
396 expected_requests_ = 0; 398 expected_requests_ = 0;
397 } 399 }
398 400
399 static net::URLRequestJob* RetryFactory( 401 static net::URLRequestJob* RetryFactory(
400 net::URLRequest* request, net::NetworkDelegate* network_delegate) { 402 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
401 ++num_requests_; 403 ++num_requests_;
402 if (num_retries_ > 0 && request->original_url() == kRetryUrl) { 404 if (num_retries_ > 0 && request->original_url() == kRetryUrl) {
403 --num_retries_; 405 --num_retries_;
404 return new RetryRequestTestJob( 406 return new RetryRequestTestJob(request, network_delegate,
405 request, network_delegate, RetryRequestTestJob::retry_headers(), 503); 407 RetryRequestTestJob::retry_headers());
406 } else { 408 } else {
407 return new RetryRequestTestJob( 409 return new RetryRequestTestJob(request, network_delegate,
408 request, 410 RetryRequestTestJob::manifest_headers());
409 network_delegate,
410 RetryRequestTestJob::manifest_headers(), 200);
411 } 411 }
412 } 412 }
413 413
414 int GetResponseCode() const override { return response_code_; }
415
416 private: 414 private:
417 ~RetryRequestTestJob() override {} 415 ~RetryRequestTestJob() override {}
418 416
419 static std::string retry_headers() { 417 static std::string retry_headers() {
420 const char no_retry_after[] = 418 const char no_retry_after[] =
421 "HTTP/1.1 503 BOO HOO\n" 419 "HTTP/1.1 503 BOO HOO\n"
422 "\n"; 420 "\n";
423 const char nonzero[] = 421 const char nonzero[] =
424 "HTTP/1.1 503 BOO HOO\n" 422 "HTTP/1.1 503 BOO HOO\n"
425 "Retry-After: 60\n" 423 "Retry-After: 60\n"
(...skipping 22 matching lines...) Expand all
448 return std::string(headers, arraysize(headers)); 446 return std::string(headers, arraysize(headers));
449 } 447 }
450 448
451 static std::string data() { 449 static std::string data() {
452 return std::string("CACHE MANIFEST\r" 450 return std::string("CACHE MANIFEST\r"
453 "http://retry\r"); // must be same as kRetryUrl 451 "http://retry\r"); // must be same as kRetryUrl
454 } 452 }
455 453
456 RetryRequestTestJob(net::URLRequest* request, 454 RetryRequestTestJob(net::URLRequest* request,
457 net::NetworkDelegate* network_delegate, 455 net::NetworkDelegate* network_delegate,
458 const std::string& headers, 456 const std::string& headers)
459 int response_code) 457 : net::URLRequestTestJob(request,
460 : net::URLRequestTestJob( 458 network_delegate,
461 request, network_delegate, headers, data(), true), 459 headers,
462 response_code_(response_code) { 460 data(),
463 } 461 true) {}
464
465 int response_code_;
466 462
467 static int num_requests_; 463 static int num_requests_;
468 static int num_retries_; 464 static int num_retries_;
469 static RetryHeader retry_after_; 465 static RetryHeader retry_after_;
470 static int expected_requests_; 466 static int expected_requests_;
471 }; 467 };
472 468
473 class RetryRequestTestJobFactory 469 class RetryRequestTestJobFactory
474 : public net::URLRequestJobFactory::ProtocolHandler { 470 : public net::URLRequestJobFactory::ProtocolHandler {
475 public: 471 public:
(...skipping 3249 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 3721
3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { 3722 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); 3723 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3728 } 3724 }
3729 3725
3730 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { 3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3731 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); 3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3732 } 3728 }
3733 3729
3734 } // namespace content 3730 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_request_handler_unittest.cc ('k') | content/browser/appcache/appcache_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698