| 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_url_request_job.h" | 5 #include "content/browser/appcache/appcache_url_request_job.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <stack> | 11 #include <stack> |
| 12 #include <utility> | 12 #include <utility> |
| 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/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/message_loop/message_loop.h" | |
| 23 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 24 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 25 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/test/scoped_task_environment.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "content/browser/appcache/appcache_response.h" | 28 #include "content/browser/appcache/appcache_response.h" |
| 29 #include "content/browser/appcache/mock_appcache_service.h" | 29 #include "content/browser/appcache/mock_appcache_service.h" |
| 30 #include "net/base/io_buffer.h" | 30 #include "net/base/io_buffer.h" |
| 31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 32 #include "net/base/request_priority.h" | 32 #include "net/base/request_priority.h" |
| 33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 34 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 35 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 // Helper callback to run a test on our io_thread. The io_thread is spun up | 224 // Helper callback to run a test on our io_thread. The io_thread is spun up |
| 225 // once and reused for all tests. | 225 // once and reused for all tests. |
| 226 template <class Method> | 226 template <class Method> |
| 227 void MethodWrapper(Method method) { | 227 void MethodWrapper(Method method) { |
| 228 SetUpTest(); | 228 SetUpTest(); |
| 229 (this->*method)(); | 229 (this->*method)(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 static void SetUpTestCase() { | 232 static void SetUpTestCase() { |
| 233 scoped_task_environment_.reset(new base::test::ScopedTaskEnvironment()); |
| 233 io_thread_.reset(new base::Thread("AppCacheURLRequestJobTest Thread")); | 234 io_thread_.reset(new base::Thread("AppCacheURLRequestJobTest Thread")); |
| 234 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 235 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 235 io_thread_->StartWithOptions(options); | 236 io_thread_->StartWithOptions(options); |
| 236 } | 237 } |
| 237 | 238 |
| 238 static void TearDownTestCase() { | 239 static void TearDownTestCase() { |
| 239 io_thread_.reset(NULL); | 240 io_thread_.reset(); |
| 241 scoped_task_environment_.reset(); |
| 240 } | 242 } |
| 241 | 243 |
| 242 AppCacheURLRequestJobTest() {} | 244 AppCacheURLRequestJobTest() {} |
| 243 | 245 |
| 244 template <class Method> | 246 template <class Method> |
| 245 void RunTestOnIOThread(Method method) { | 247 void RunTestOnIOThread(Method method) { |
| 246 test_finished_event_.reset(new base::WaitableEvent( | 248 test_finished_event_.reset(new base::WaitableEvent( |
| 247 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 249 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 248 base::WaitableEvent::InitialState::NOT_SIGNALED)); | 250 base::WaitableEvent::InitialState::NOT_SIGNALED)); |
| 249 io_thread_->task_runner()->PostTask( | 251 io_thread_->task_runner()->PostTask( |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 int writer_deletion_count_down_; | 859 int writer_deletion_count_down_; |
| 858 | 860 |
| 859 bool restart_callback_invoked_; | 861 bool restart_callback_invoked_; |
| 860 | 862 |
| 861 std::unique_ptr<MockURLRequestJobFactory> job_factory_; | 863 std::unique_ptr<MockURLRequestJobFactory> job_factory_; |
| 862 std::unique_ptr<net::URLRequestContext> empty_context_; | 864 std::unique_ptr<net::URLRequestContext> empty_context_; |
| 863 std::unique_ptr<net::URLRequest> request_; | 865 std::unique_ptr<net::URLRequest> request_; |
| 864 std::unique_ptr<MockURLRequestDelegate> url_request_delegate_; | 866 std::unique_ptr<MockURLRequestDelegate> url_request_delegate_; |
| 865 | 867 |
| 866 static std::unique_ptr<base::Thread> io_thread_; | 868 static std::unique_ptr<base::Thread> io_thread_; |
| 869 static std::unique_ptr<base::test::ScopedTaskEnvironment> |
| 870 scoped_task_environment_; |
| 867 }; | 871 }; |
| 868 | 872 |
| 869 // static | 873 // static |
| 870 std::unique_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_; | 874 std::unique_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_; |
| 875 std::unique_ptr<base::test::ScopedTaskEnvironment> |
| 876 AppCacheURLRequestJobTest::scoped_task_environment_; |
| 871 | 877 |
| 872 TEST_F(AppCacheURLRequestJobTest, Basic) { | 878 TEST_F(AppCacheURLRequestJobTest, Basic) { |
| 873 RunTestOnIOThread(&AppCacheURLRequestJobTest::Basic); | 879 RunTestOnIOThread(&AppCacheURLRequestJobTest::Basic); |
| 874 } | 880 } |
| 875 | 881 |
| 876 TEST_F(AppCacheURLRequestJobTest, DeliveryOrders) { | 882 TEST_F(AppCacheURLRequestJobTest, DeliveryOrders) { |
| 877 RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliveryOrders); | 883 RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliveryOrders); |
| 878 } | 884 } |
| 879 | 885 |
| 880 TEST_F(AppCacheURLRequestJobTest, DeliverNetworkResponse) { | 886 TEST_F(AppCacheURLRequestJobTest, DeliverNetworkResponse) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 899 | 905 |
| 900 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 906 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
| 901 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 907 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
| 902 } | 908 } |
| 903 | 909 |
| 904 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 910 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 905 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 911 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 906 } | 912 } |
| 907 | 913 |
| 908 } // namespace content | 914 } // namespace content |
| OLD | NEW |