Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: content/browser/appcache/appcache_url_request_job_unittest.cc

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/location.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/pickle.h" 15 #include "base/pickle.h"
16 #include "base/single_thread_task_runner.h"
15 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
17 #include "content/browser/appcache/appcache_response.h" 20 #include "content/browser/appcache/appcache_response.h"
18 #include "content/browser/appcache/appcache_url_request_job.h" 21 #include "content/browser/appcache/appcache_url_request_job.h"
19 #include "content/browser/appcache/mock_appcache_service.h" 22 #include "content/browser/appcache/mock_appcache_service.h"
20 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
21 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
22 #include "net/base/request_priority.h" 25 #include "net/base/request_priority.h"
23 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
24 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_context.h" 28 #include "net/url_request/url_request_context.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 213
211 static void TearDownTestCase() { 214 static void TearDownTestCase() {
212 io_thread_.reset(NULL); 215 io_thread_.reset(NULL);
213 } 216 }
214 217
215 AppCacheURLRequestJobTest() {} 218 AppCacheURLRequestJobTest() {}
216 219
217 template <class Method> 220 template <class Method>
218 void RunTestOnIOThread(Method method) { 221 void RunTestOnIOThread(Method method) {
219 test_finished_event_ .reset(new base::WaitableEvent(false, false)); 222 test_finished_event_ .reset(new base::WaitableEvent(false, false));
220 io_thread_->message_loop()->PostTask( 223 io_thread_->task_runner()->PostTask(
221 FROM_HERE, base::Bind(&AppCacheURLRequestJobTest::MethodWrapper<Method>, 224 FROM_HERE, base::Bind(&AppCacheURLRequestJobTest::MethodWrapper<Method>,
222 base::Unretained(this), method)); 225 base::Unretained(this), method));
223 test_finished_event_->Wait(); 226 test_finished_event_->Wait();
224 } 227 }
225 228
226 void SetUpTest() { 229 void SetUpTest() {
227 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 230 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
228 DCHECK(task_stack_.empty()); 231 DCHECK(task_stack_.empty());
229 232
230 storage_delegate_.reset(new MockStorageDelegate(this)); 233 storage_delegate_.reset(new MockStorageDelegate(this));
(...skipping 29 matching lines...) Expand all
260 DCHECK(!job_factory_->has_job()); 263 DCHECK(!job_factory_->has_job());
261 empty_context_.reset(); 264 empty_context_.reset();
262 job_factory_.reset(); 265 job_factory_.reset();
263 url_request_delegate_.reset(); 266 url_request_delegate_.reset();
264 } 267 }
265 268
266 void TestFinished() { 269 void TestFinished() {
267 // We unwind the stack prior to finishing up to let stack 270 // We unwind the stack prior to finishing up to let stack
268 // based objects get deleted. 271 // based objects get deleted.
269 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 272 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
270 base::MessageLoop::current()->PostTask( 273 base::ThreadTaskRunnerHandle::Get()->PostTask(
271 FROM_HERE, 274 FROM_HERE, base::Bind(&AppCacheURLRequestJobTest::TestFinishedUnwound,
272 base::Bind(&AppCacheURLRequestJobTest::TestFinishedUnwound, 275 base::Unretained(this)));
273 base::Unretained(this)));
274 } 276 }
275 277
276 void TestFinishedUnwound() { 278 void TestFinishedUnwound() {
277 TearDownTest(); 279 TearDownTest();
278 test_finished_event_->Signal(); 280 test_finished_event_->Signal();
279 } 281 }
280 282
281 void PushNextTask(const base::Closure& task) { 283 void PushNextTask(const base::Closure& task) {
282 task_stack_.push(std::pair<base::Closure, bool>(task, false)); 284 task_stack_.push(std::pair<base::Closure, bool>(task, false));
283 } 285 }
284 286
285 void PushNextTaskAsImmediate(const base::Closure& task) { 287 void PushNextTaskAsImmediate(const base::Closure& task) {
286 task_stack_.push(std::pair<base::Closure, bool>(task, true)); 288 task_stack_.push(std::pair<base::Closure, bool>(task, true));
287 } 289 }
288 290
289 void ScheduleNextTask() { 291 void ScheduleNextTask() {
290 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 292 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
291 if (task_stack_.empty()) { 293 if (task_stack_.empty()) {
292 TestFinished(); 294 TestFinished();
293 return; 295 return;
294 } 296 }
295 base::Closure task =task_stack_.top().first; 297 base::Closure task =task_stack_.top().first;
296 bool immediate = task_stack_.top().second; 298 bool immediate = task_stack_.top().second;
297 task_stack_.pop(); 299 task_stack_.pop();
298 if (immediate) 300 if (immediate)
299 task.Run(); 301 task.Run();
300 else 302 else
301 base::MessageLoop::current()->PostTask(FROM_HERE, task); 303 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
302 } 304 }
303 305
304 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods 306 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods
305 307
306 void WriteBasicResponse() { 308 void WriteBasicResponse() {
307 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBasicBody)); 309 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBasicBody));
308 std::string raw_headers(kHttpBasicHeaders, arraysize(kHttpBasicHeaders)); 310 std::string raw_headers(kHttpBasicHeaders, arraysize(kHttpBasicHeaders));
309 WriteResponse( 311 WriteResponse(
310 MakeHttpResponseInfo(raw_headers), body.get(), strlen(kHttpBasicBody)); 312 MakeHttpResponseInfo(raw_headers), body.get(), strlen(kHttpBasicBody));
311 } 313 }
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); 863 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest);
862 } 864 }
863 865
864 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 866 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
865 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 867 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
866 } 868 }
867 869
868 } // namespace 870 } // namespace
869 871
870 } // namespace content 872 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.cc ('k') | content/browser/appcache/chrome_appcache_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698