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