| 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 <stack> | 5 #include <stack> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/location.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 15 #include "content/browser/appcache/appcache.h" | 17 #include "content/browser/appcache/appcache.h" |
| 16 #include "content/browser/appcache/appcache_backend_impl.h" | 18 #include "content/browser/appcache/appcache_backend_impl.h" |
| 17 #include "content/browser/appcache/appcache_request_handler.h" | 19 #include "content/browser/appcache/appcache_request_handler.h" |
| 18 #include "content/browser/appcache/appcache_url_request_job.h" | 20 #include "content/browser/appcache/appcache_url_request_job.h" |
| 19 #include "content/browser/appcache/mock_appcache_policy.h" | 21 #include "content/browser/appcache/mock_appcache_policy.h" |
| 20 #include "content/browser/appcache/mock_appcache_service.h" | 22 #include "content/browser/appcache/mock_appcache_service.h" |
| 21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 22 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 23 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 io_thread_.reset(NULL); | 175 io_thread_.reset(NULL); |
| 174 } | 176 } |
| 175 | 177 |
| 176 // Test harness -------------------------------------------------- | 178 // Test harness -------------------------------------------------- |
| 177 | 179 |
| 178 AppCacheRequestHandlerTest() : host_(NULL) {} | 180 AppCacheRequestHandlerTest() : host_(NULL) {} |
| 179 | 181 |
| 180 template <class Method> | 182 template <class Method> |
| 181 void RunTestOnIOThread(Method method) { | 183 void RunTestOnIOThread(Method method) { |
| 182 test_finished_event_ .reset(new base::WaitableEvent(false, false)); | 184 test_finished_event_ .reset(new base::WaitableEvent(false, false)); |
| 183 io_thread_->message_loop()->PostTask( | 185 io_thread_->task_runner()->PostTask( |
| 184 FROM_HERE, | 186 FROM_HERE, |
| 185 base::Bind(&AppCacheRequestHandlerTest::MethodWrapper<Method>, | 187 base::Bind(&AppCacheRequestHandlerTest::MethodWrapper<Method>, |
| 186 base::Unretained(this), method)); | 188 base::Unretained(this), method)); |
| 187 test_finished_event_->Wait(); | 189 test_finished_event_->Wait(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void SetUpTest() { | 192 void SetUpTest() { |
| 191 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 193 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); |
| 192 mock_service_.reset(new MockAppCacheService); | 194 mock_service_.reset(new MockAppCacheService); |
| 193 mock_service_->set_request_context(&empty_context_); | 195 mock_service_->set_request_context(&empty_context_); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 214 mock_service_.reset(); | 216 mock_service_.reset(); |
| 215 mock_policy_.reset(); | 217 mock_policy_.reset(); |
| 216 job_factory_.reset(); | 218 job_factory_.reset(); |
| 217 host_ = NULL; | 219 host_ = NULL; |
| 218 } | 220 } |
| 219 | 221 |
| 220 void TestFinished() { | 222 void TestFinished() { |
| 221 // We unwind the stack prior to finishing up to let stack | 223 // We unwind the stack prior to finishing up to let stack |
| 222 // based objects get deleted. | 224 // based objects get deleted. |
| 223 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 225 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); |
| 224 base::MessageLoop::current()->PostTask( | 226 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 225 FROM_HERE, | 227 FROM_HERE, base::Bind(&AppCacheRequestHandlerTest::TestFinishedUnwound, |
| 226 base::Bind(&AppCacheRequestHandlerTest::TestFinishedUnwound, | 228 base::Unretained(this))); |
| 227 base::Unretained(this))); | |
| 228 } | 229 } |
| 229 | 230 |
| 230 void TestFinishedUnwound() { | 231 void TestFinishedUnwound() { |
| 231 TearDownTest(); | 232 TearDownTest(); |
| 232 test_finished_event_->Signal(); | 233 test_finished_event_->Signal(); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void PushNextTask(const base::Closure& task) { | 236 void PushNextTask(const base::Closure& task) { |
| 236 task_stack_.push(task); | 237 task_stack_.push(task); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void ScheduleNextTask() { | 240 void ScheduleNextTask() { |
| 240 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 241 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); |
| 241 if (task_stack_.empty()) { | 242 if (task_stack_.empty()) { |
| 242 TestFinished(); | 243 TestFinished(); |
| 243 return; | 244 return; |
| 244 } | 245 } |
| 245 base::MessageLoop::current()->PostTask(FROM_HERE, task_stack_.top()); | 246 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task_stack_.top()); |
| 246 task_stack_.pop(); | 247 task_stack_.pop(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 // MainResource_Miss -------------------------------------------------- | 250 // MainResource_Miss -------------------------------------------------- |
| 250 | 251 |
| 251 void MainResource_Miss() { | 252 void MainResource_Miss() { |
| 252 PushNextTask( | 253 PushNextTask( |
| 253 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, | 254 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, |
| 254 base::Unretained(this))); | 255 base::Unretained(this))); |
| 255 | 256 |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 | 1018 |
| 1018 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1019 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 1019 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1020 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 1020 } | 1021 } |
| 1021 | 1022 |
| 1022 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1023 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
| 1023 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1024 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
| 1024 } | 1025 } |
| 1025 | 1026 |
| 1026 } // namespace content | 1027 } // namespace content |
| OLD | NEW |