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

Side by Side Diff: content/browser/appcache/appcache_response_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 <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
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/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/location.h"
13 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
16 #include "content/browser/appcache/appcache_response.h" 19 #include "content/browser/appcache/appcache_response.h"
17 #include "content/browser/appcache/mock_appcache_service.h" 20 #include "content/browser/appcache/mock_appcache_service.h"
18 #include "net/base/io_buffer.h" 21 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
20 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
21 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
22 25
23 using net::IOBuffer; 26 using net::IOBuffer;
24 using net::WrappedIOBuffer; 27 using net::WrappedIOBuffer;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 71
69 static void TearDownTestCase() { 72 static void TearDownTestCase() {
70 io_thread_.reset(NULL); 73 io_thread_.reset(NULL);
71 } 74 }
72 75
73 AppCacheResponseTest() {} 76 AppCacheResponseTest() {}
74 77
75 template <class Method> 78 template <class Method>
76 void RunTestOnIOThread(Method method) { 79 void RunTestOnIOThread(Method method) {
77 test_finished_event_ .reset(new base::WaitableEvent(false, false)); 80 test_finished_event_ .reset(new base::WaitableEvent(false, false));
78 io_thread_->message_loop()->PostTask( 81 io_thread_->task_runner()->PostTask(
79 FROM_HERE, base::Bind(&AppCacheResponseTest::MethodWrapper<Method>, 82 FROM_HERE, base::Bind(&AppCacheResponseTest::MethodWrapper<Method>,
80 base::Unretained(this), method)); 83 base::Unretained(this), method));
81 test_finished_event_->Wait(); 84 test_finished_event_->Wait();
82 } 85 }
83 86
84 void SetUpTest() { 87 void SetUpTest() {
85 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 88 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
86 DCHECK(task_stack_.empty()); 89 DCHECK(task_stack_.empty());
87 storage_delegate_.reset(new MockStorageDelegate(this)); 90 storage_delegate_.reset(new MockStorageDelegate(this));
88 service_.reset(new MockAppCacheService()); 91 service_.reset(new MockAppCacheService());
(...skipping 20 matching lines...) Expand all
109 write_buffer_ = NULL; 112 write_buffer_ = NULL;
110 write_info_buffer_ = NULL; 113 write_info_buffer_ = NULL;
111 storage_delegate_.reset(); 114 storage_delegate_.reset();
112 service_.reset(); 115 service_.reset();
113 } 116 }
114 117
115 void TestFinished() { 118 void TestFinished() {
116 // We unwind the stack prior to finishing up to let stack 119 // We unwind the stack prior to finishing up to let stack
117 // based objects get deleted. 120 // based objects get deleted.
118 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 121 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
119 base::MessageLoop::current()->PostTask( 122 base::ThreadTaskRunnerHandle::Get()->PostTask(
120 FROM_HERE, base::Bind(&AppCacheResponseTest::TestFinishedUnwound, 123 FROM_HERE, base::Bind(&AppCacheResponseTest::TestFinishedUnwound,
121 base::Unretained(this))); 124 base::Unretained(this)));
122 } 125 }
123 126
124 void TestFinishedUnwound() { 127 void TestFinishedUnwound() {
125 TearDownTest(); 128 TearDownTest();
126 test_finished_event_->Signal(); 129 test_finished_event_->Signal();
127 } 130 }
128 131
129 void PushNextTask(const base::Closure& task) { 132 void PushNextTask(const base::Closure& task) {
130 task_stack_.push(std::pair<base::Closure, bool>(task, false)); 133 task_stack_.push(std::pair<base::Closure, bool>(task, false));
131 } 134 }
132 135
133 void PushNextTaskAsImmediate(const base::Closure& task) { 136 void PushNextTaskAsImmediate(const base::Closure& task) {
134 task_stack_.push(std::pair<base::Closure, bool>(task, true)); 137 task_stack_.push(std::pair<base::Closure, bool>(task, true));
135 } 138 }
136 139
137 void ScheduleNextTask() { 140 void ScheduleNextTask() {
138 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); 141 DCHECK(base::MessageLoop::current() == io_thread_->message_loop());
139 if (task_stack_.empty()) { 142 if (task_stack_.empty()) {
140 TestFinished(); 143 TestFinished();
141 return; 144 return;
142 } 145 }
143 base::Closure task = task_stack_.top().first; 146 base::Closure task = task_stack_.top().first;
144 bool immediate = task_stack_.top().second; 147 bool immediate = task_stack_.top().second;
145 task_stack_.pop(); 148 task_stack_.pop();
146 if (immediate) 149 if (immediate)
147 task.Run(); 150 task.Run();
148 else 151 else
149 base::MessageLoop::current()->PostTask(FROM_HERE, task); 152 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
150 } 153 }
151 154
152 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods 155 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods
153 156
154 void WriteBasicResponse() { 157 void WriteBasicResponse() {
155 static const char kHttpHeaders[] = 158 static const char kHttpHeaders[] =
156 "HTTP/1.0 200 OK\0Content-Length: 5\0\0"; 159 "HTTP/1.0 200 OK\0Content-Length: 5\0\0";
157 static const char kHttpBody[] = "Hello"; 160 static const char kHttpBody[] = "Hello";
158 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBody)); 161 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBody));
159 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); 162 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders));
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 732
730 void ReadThenDelete() { 733 void ReadThenDelete() {
731 read_callback_was_called_ = false; 734 read_callback_was_called_ = false;
732 reader_.reset(service_->storage()->CreateResponseReader( 735 reader_.reset(service_->storage()->CreateResponseReader(
733 GURL(), 0, written_response_id_)); 736 GURL(), 0, written_response_id_));
734 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize); 737 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
735 EXPECT_TRUE(reader_->IsReadPending()); 738 EXPECT_TRUE(reader_->IsReadPending());
736 reader_.reset(); 739 reader_.reset();
737 740
738 // Wait a moment to verify no callbacks. 741 // Wait a moment to verify no callbacks.
739 base::MessageLoop::current()->PostDelayedTask( 742 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
740 FROM_HERE, base::Bind(&AppCacheResponseTest::VerifyNoCallbacks, 743 FROM_HERE, base::Bind(&AppCacheResponseTest::VerifyNoCallbacks,
741 base::Unretained(this)), 744 base::Unretained(this)),
742 base::TimeDelta::FromMilliseconds(10)); 745 base::TimeDelta::FromMilliseconds(10));
743 } 746 }
744 747
745 void VerifyNoCallbacks() { 748 void VerifyNoCallbacks() {
746 EXPECT_TRUE(!write_callback_was_called_); 749 EXPECT_TRUE(!write_callback_was_called_);
747 EXPECT_TRUE(!read_callback_was_called_); 750 EXPECT_TRUE(!read_callback_was_called_);
748 TestFinished(); 751 TestFinished();
749 } 752 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 812
810 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { 813 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) {
811 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); 814 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks);
812 } 815 }
813 816
814 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { 817 TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
815 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); 818 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending);
816 } 819 }
817 820
818 } // namespace content 821 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_response.cc ('k') | content/browser/appcache/appcache_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698