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

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

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