| OLD | NEW |
| 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" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 6 | |
| 7 #include <stack> | 8 #include <stack> |
| 8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 15 #include "base/callback.h" |
| 14 #include "base/location.h" | 16 #include "base/location.h" |
| 15 #include "base/macros.h" | 17 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 18 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 21 #include "content/browser/appcache/appcache.h" | 23 #include "content/browser/appcache/appcache.h" |
| 22 #include "content/browser/appcache/appcache_backend_impl.h" | 24 #include "content/browser/appcache/appcache_backend_impl.h" |
| 23 #include "content/browser/appcache/appcache_request_handler.h" | |
| 24 #include "content/browser/appcache/appcache_url_request_job.h" | 25 #include "content/browser/appcache/appcache_url_request_job.h" |
| 25 #include "content/browser/appcache/mock_appcache_policy.h" | 26 #include "content/browser/appcache/mock_appcache_policy.h" |
| 26 #include "content/browser/appcache/mock_appcache_service.h" | 27 #include "content/browser/appcache/mock_appcache_service.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
| 29 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
| 30 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 31 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
| 32 #include "net/url_request/url_request_error_job.h" | 33 #include "net/url_request/url_request_error_job.h" |
| 33 #include "net/url_request/url_request_job_factory.h" | 34 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 bool has_response_info_; | 113 bool has_response_info_; |
| 113 net::HttpResponseInfo response_info_; | 114 net::HttpResponseInfo response_info_; |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | 117 class MockURLRequestJobFactory : public net::URLRequestJobFactory { |
| 117 public: | 118 public: |
| 118 MockURLRequestJobFactory() {} | 119 MockURLRequestJobFactory() {} |
| 119 | 120 |
| 120 ~MockURLRequestJobFactory() override { DCHECK(!job_); } | 121 ~MockURLRequestJobFactory() override { DCHECK(!job_); } |
| 121 | 122 |
| 122 void SetJob(scoped_ptr<net::URLRequestJob> job) { job_ = job.Pass(); } | 123 void SetJob(scoped_ptr<net::URLRequestJob> job) { job_ = std::move(job); } |
| 123 | 124 |
| 124 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | 125 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 125 const std::string& scheme, | 126 const std::string& scheme, |
| 126 net::URLRequest* request, | 127 net::URLRequest* request, |
| 127 net::NetworkDelegate* network_delegate) const override { | 128 net::NetworkDelegate* network_delegate) const override { |
| 128 if (job_) | 129 if (job_) |
| 129 return job_.release(); | 130 return job_.release(); |
| 130 | 131 |
| 131 // Some of these tests trigger UpdateJobs which start URLRequests. | 132 // Some of these tests trigger UpdateJobs which start URLRequests. |
| 132 // We short circuit those be returning error jobs. | 133 // We short circuit those be returning error jobs. |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 EXPECT_TRUE(handler_.get()); | 810 EXPECT_TRUE(handler_.get()); |
| 810 | 811 |
| 811 job_.reset(handler_->MaybeLoadResource( | 812 job_.reset(handler_->MaybeLoadResource( |
| 812 request_.get(), request_->context()->network_delegate())); | 813 request_.get(), request_->context()->network_delegate())); |
| 813 EXPECT_TRUE(job_.get()); | 814 EXPECT_TRUE(job_.get()); |
| 814 EXPECT_TRUE(job_->is_waiting()); | 815 EXPECT_TRUE(job_->is_waiting()); |
| 815 EXPECT_FALSE(job_->has_been_started()); | 816 EXPECT_FALSE(job_->has_been_started()); |
| 816 | 817 |
| 817 base::WeakPtr<AppCacheURLRequestJob> weak_job = job_->GetWeakPtr(); | 818 base::WeakPtr<AppCacheURLRequestJob> weak_job = job_->GetWeakPtr(); |
| 818 | 819 |
| 819 job_factory_->SetJob(job_.Pass()); | 820 job_factory_->SetJob(std::move(job_)); |
| 820 request_->Start(); | 821 request_->Start(); |
| 821 ASSERT_TRUE(weak_job); | 822 ASSERT_TRUE(weak_job); |
| 822 EXPECT_TRUE(weak_job->has_been_started()); | 823 EXPECT_TRUE(weak_job->has_been_started()); |
| 823 | 824 |
| 824 request_->Cancel(); | 825 request_->Cancel(); |
| 825 ASSERT_FALSE(weak_job); | 826 ASSERT_FALSE(weak_job); |
| 826 | 827 |
| 827 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 828 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
| 828 request_.get(), request_->context()->network_delegate())); | 829 request_.get(), request_->context()->network_delegate())); |
| 829 | 830 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1024 |
| 1024 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1025 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 1025 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1026 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 1026 } | 1027 } |
| 1027 | 1028 |
| 1028 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1029 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
| 1029 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1030 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
| 1030 } | 1031 } |
| 1031 | 1032 |
| 1032 } // namespace content | 1033 } // namespace content |
| OLD | NEW |