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> |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 188 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
189 base::WaitableEvent::InitialState::NOT_SIGNALED)); | 189 base::WaitableEvent::InitialState::NOT_SIGNALED)); |
190 io_thread_->task_runner()->PostTask( | 190 io_thread_->task_runner()->PostTask( |
191 FROM_HERE, | 191 FROM_HERE, |
192 base::Bind(&AppCacheRequestHandlerTest::MethodWrapper<Method>, | 192 base::Bind(&AppCacheRequestHandlerTest::MethodWrapper<Method>, |
193 base::Unretained(this), method)); | 193 base::Unretained(this), method)); |
194 test_finished_event_->Wait(); | 194 test_finished_event_->Wait(); |
195 } | 195 } |
196 | 196 |
197 void SetUpTest() { | 197 void SetUpTest() { |
198 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 198 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
199 mock_service_.reset(new MockAppCacheService); | 199 mock_service_.reset(new MockAppCacheService); |
200 mock_service_->set_request_context(&empty_context_); | 200 mock_service_->set_request_context(&empty_context_); |
201 mock_policy_.reset(new MockAppCachePolicy); | 201 mock_policy_.reset(new MockAppCachePolicy); |
202 mock_service_->set_appcache_policy(mock_policy_.get()); | 202 mock_service_->set_appcache_policy(mock_policy_.get()); |
203 mock_frontend_.reset(new MockFrontend); | 203 mock_frontend_.reset(new MockFrontend); |
204 backend_impl_.reset(new AppCacheBackendImpl); | 204 backend_impl_.reset(new AppCacheBackendImpl); |
205 backend_impl_->Initialize(mock_service_.get(), mock_frontend_.get(), | 205 backend_impl_->Initialize(mock_service_.get(), mock_frontend_.get(), |
206 kMockProcessId); | 206 kMockProcessId); |
207 const int kHostId = 1; | 207 const int kHostId = 1; |
208 backend_impl_->RegisterHost(kHostId); | 208 backend_impl_->RegisterHost(kHostId); |
209 host_ = backend_impl_->GetHost(kHostId); | 209 host_ = backend_impl_->GetHost(kHostId); |
210 job_factory_.reset(new MockURLRequestJobFactory()); | 210 job_factory_.reset(new MockURLRequestJobFactory()); |
211 empty_context_.set_job_factory(job_factory_.get()); | 211 empty_context_.set_job_factory(job_factory_.get()); |
212 } | 212 } |
213 | 213 |
214 void TearDownTest() { | 214 void TearDownTest() { |
215 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 215 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
216 job_ = NULL; | 216 job_ = NULL; |
217 handler_.reset(); | 217 handler_.reset(); |
218 request_.reset(); | 218 request_.reset(); |
219 backend_impl_.reset(); | 219 backend_impl_.reset(); |
220 mock_frontend_.reset(); | 220 mock_frontend_.reset(); |
221 mock_service_.reset(); | 221 mock_service_.reset(); |
222 mock_policy_.reset(); | 222 mock_policy_.reset(); |
223 job_factory_.reset(); | 223 job_factory_.reset(); |
224 host_ = NULL; | 224 host_ = NULL; |
225 } | 225 } |
226 | 226 |
227 void TestFinished() { | 227 void TestFinished() { |
228 // We unwind the stack prior to finishing up to let stack | 228 // We unwind the stack prior to finishing up to let stack |
229 // based objects get deleted. | 229 // based objects get deleted. |
230 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 230 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
231 base::ThreadTaskRunnerHandle::Get()->PostTask( | 231 base::ThreadTaskRunnerHandle::Get()->PostTask( |
232 FROM_HERE, base::Bind(&AppCacheRequestHandlerTest::TestFinishedUnwound, | 232 FROM_HERE, base::Bind(&AppCacheRequestHandlerTest::TestFinishedUnwound, |
233 base::Unretained(this))); | 233 base::Unretained(this))); |
234 } | 234 } |
235 | 235 |
236 void TestFinishedUnwound() { | 236 void TestFinishedUnwound() { |
237 TearDownTest(); | 237 TearDownTest(); |
238 test_finished_event_->Signal(); | 238 test_finished_event_->Signal(); |
239 } | 239 } |
240 | 240 |
241 void PushNextTask(const base::Closure& task) { | 241 void PushNextTask(const base::Closure& task) { |
242 task_stack_.push(task); | 242 task_stack_.push(task); |
243 } | 243 } |
244 | 244 |
245 void ScheduleNextTask() { | 245 void ScheduleNextTask() { |
246 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 246 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
247 if (task_stack_.empty()) { | 247 if (task_stack_.empty()) { |
248 TestFinished(); | 248 TestFinished(); |
249 return; | 249 return; |
250 } | 250 } |
251 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task_stack_.top()); | 251 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task_stack_.top()); |
252 task_stack_.pop(); | 252 task_stack_.pop(); |
253 } | 253 } |
254 | 254 |
255 // MainResource_Miss -------------------------------------------------- | 255 // MainResource_Miss -------------------------------------------------- |
256 | 256 |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 | 1030 |
1031 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1031 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
1032 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1032 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
1033 } | 1033 } |
1034 | 1034 |
1035 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1035 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
1036 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1036 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
1037 } | 1037 } |
1038 | 1038 |
1039 } // namespace content | 1039 } // namespace content |
OLD | NEW |