| 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" | 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/message_loop/message_loop.h" | |
| 22 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 24 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
| 24 #include "base/test/scoped_task_environment.h" |
| 25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "content/browser/appcache/appcache.h" | 27 #include "content/browser/appcache/appcache.h" |
| 28 #include "content/browser/appcache/appcache_backend_impl.h" | 28 #include "content/browser/appcache/appcache_backend_impl.h" |
| 29 #include "content/browser/appcache/appcache_url_request.h" | 29 #include "content/browser/appcache/appcache_url_request.h" |
| 30 #include "content/browser/appcache/appcache_url_request_job.h" | 30 #include "content/browser/appcache/appcache_url_request_job.h" |
| 31 #include "content/browser/appcache/mock_appcache_policy.h" | 31 #include "content/browser/appcache/mock_appcache_policy.h" |
| 32 #include "content/browser/appcache/mock_appcache_service.h" | 32 #include "content/browser/appcache/mock_appcache_service.h" |
| 33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 34 #include "net/base/request_priority.h" | 34 #include "net/base/request_priority.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 bool IsSafeRedirectTarget(const GURL& location) const override { | 173 bool IsSafeRedirectTarget(const GURL& location) const override { |
| 174 return false; | 174 return false; |
| 175 } | 175 } |
| 176 | 176 |
| 177 private: | 177 private: |
| 178 mutable std::unique_ptr<net::URLRequestJob> job_; | 178 mutable std::unique_ptr<net::URLRequestJob> job_; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 static void SetUpTestCase() { | 181 static void SetUpTestCase() { |
| 182 scoped_task_environment_.reset(new base::test::ScopedTaskEnvironment); |
| 182 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); | 183 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); |
| 183 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 184 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 184 io_thread_->StartWithOptions(options); | 185 io_thread_->StartWithOptions(options); |
| 185 } | 186 } |
| 186 | 187 |
| 187 static void TearDownTestCase() { | 188 static void TearDownTestCase() { |
| 188 io_thread_.reset(NULL); | 189 io_thread_.reset(); |
| 190 scoped_task_environment_.reset(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 // Test harness -------------------------------------------------- | 193 // Test harness -------------------------------------------------- |
| 192 | 194 |
| 193 AppCacheRequestHandlerTest() : host_(NULL) {} | 195 AppCacheRequestHandlerTest() : host_(NULL) {} |
| 194 | 196 |
| 195 template <class Method> | 197 template <class Method> |
| 196 void RunTestOnIOThread(Method method) { | 198 void RunTestOnIOThread(Method method) { |
| 197 test_finished_event_.reset(new base::WaitableEvent( | 199 test_finished_event_.reset(new base::WaitableEvent( |
| 198 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 200 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 std::unique_ptr<MockAppCachePolicy> mock_policy_; | 1080 std::unique_ptr<MockAppCachePolicy> mock_policy_; |
| 1079 AppCacheHost* host_; | 1081 AppCacheHost* host_; |
| 1080 std::unique_ptr<net::URLRequestContext> empty_context_; | 1082 std::unique_ptr<net::URLRequestContext> empty_context_; |
| 1081 std::unique_ptr<MockURLRequestJobFactory> job_factory_; | 1083 std::unique_ptr<MockURLRequestJobFactory> job_factory_; |
| 1082 MockURLRequestDelegate delegate_; | 1084 MockURLRequestDelegate delegate_; |
| 1083 std::unique_ptr<net::URLRequest> request_; | 1085 std::unique_ptr<net::URLRequest> request_; |
| 1084 std::unique_ptr<AppCacheRequestHandler> handler_; | 1086 std::unique_ptr<AppCacheRequestHandler> handler_; |
| 1085 std::unique_ptr<AppCacheURLRequestJob> job_; | 1087 std::unique_ptr<AppCacheURLRequestJob> job_; |
| 1086 | 1088 |
| 1087 static std::unique_ptr<base::Thread> io_thread_; | 1089 static std::unique_ptr<base::Thread> io_thread_; |
| 1090 static std::unique_ptr<base::test::ScopedTaskEnvironment> |
| 1091 scoped_task_environment_; |
| 1088 }; | 1092 }; |
| 1089 | 1093 |
| 1090 // static | 1094 // static |
| 1091 std::unique_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; | 1095 std::unique_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; |
| 1096 std::unique_ptr<base::test::ScopedTaskEnvironment> |
| 1097 AppCacheRequestHandlerTest::scoped_task_environment_; |
| 1092 | 1098 |
| 1093 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { | 1099 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { |
| 1094 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Miss); | 1100 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Miss); |
| 1095 } | 1101 } |
| 1096 | 1102 |
| 1097 TEST_F(AppCacheRequestHandlerTest, MainResource_Hit) { | 1103 TEST_F(AppCacheRequestHandlerTest, MainResource_Hit) { |
| 1098 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Hit); | 1104 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Hit); |
| 1099 } | 1105 } |
| 1100 | 1106 |
| 1101 TEST_F(AppCacheRequestHandlerTest, MainResource_Fallback) { | 1107 TEST_F(AppCacheRequestHandlerTest, MainResource_Fallback) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 | 1173 |
| 1168 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1174 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 1169 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1175 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 1170 } | 1176 } |
| 1171 | 1177 |
| 1172 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1178 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
| 1173 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1179 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
| 1174 } | 1180 } |
| 1175 | 1181 |
| 1176 } // namespace content | 1182 } // namespace content |
| OLD | NEW |