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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandleTest.cpp

Issue 1713143002: Remove most of the blink::Task wrapping of WTF::Function outside WebTaskRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/fetch/CompositeDataConsumerHandle.h" 5 #include "modules/fetch/CompositeDataConsumerHandle.h"
6 6
7 #include "modules/fetch/DataConsumerHandleTestUtil.h" 7 #include "modules/fetch/DataConsumerHandleTestUtil.h"
8 #include "platform/Task.h"
9 #include "platform/ThreadSafeFunctional.h" 8 #include "platform/ThreadSafeFunctional.h"
10 #include "platform/WaitableEvent.h" 9 #include "platform/WaitableEvent.h"
11 #include "platform/heap/Handle.h" 10 #include "platform/heap/Handle.h"
12 #include "public/platform/Platform.h" 11 #include "public/platform/Platform.h"
13 #include "public/platform/WebThread.h" 12 #include "public/platform/WebThread.h"
14 #include "public/platform/WebTraceLocation.h" 13 #include "public/platform/WebTraceLocation.h"
15 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "wtf/Locker.h" 16 #include "wtf/Locker.h"
18 17
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 class ThreadingRegistrationTest : public DataConsumerHandleTestUtil::ThreadingTe stBase { 52 class ThreadingRegistrationTest : public DataConsumerHandleTestUtil::ThreadingTe stBase {
54 public: 53 public:
55 using Self = ThreadingRegistrationTest; 54 using Self = ThreadingRegistrationTest;
56 static PassRefPtr<Self> create() { return adoptRef(new Self); } 55 static PassRefPtr<Self> create() { return adoptRef(new Self); }
57 56
58 void run() 57 void run()
59 { 58 {
60 ThreadHolder holder(this); 59 ThreadHolder holder(this);
61 m_waitableEvent = adoptPtr(new WaitableEvent()); 60 m_waitableEvent = adoptPtr(new WaitableEvent());
62 61
63 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind (&Self::createHandle, this))); 62 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::c reateHandle, this));
64 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind( &Self::obtainReader, this))); 63 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::ob tainReader, this));
65 } 64 }
66 65
67 private: 66 private:
68 ThreadingRegistrationTest() = default; 67 ThreadingRegistrationTest() = default;
69 68
70 void createHandle() 69 void createHandle()
71 { 70 {
72 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater); 71 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater);
73 m_waitableEvent->signal(); 72 m_waitableEvent->signal();
74 } 73 }
75 void obtainReader() 74 void obtainReader()
76 { 75 {
77 m_reader = m_handle->obtainReader(&m_client); 76 m_reader = m_handle->obtainReader(&m_client);
78 postTaskToUpdatingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self: :update, this))); 77 postTaskToUpdatingThread(BLINK_FROM_HERE, threadSafeBind(&Self::update, this));
79 } 78 }
80 void update() 79 void update()
81 { 80 {
82 m_updater->update(DataConsumerHandle::create("handle2", m_context)); 81 m_updater->update(DataConsumerHandle::create("handle2", m_context));
83 m_updater.clear(); 82 m_updater.clear();
84 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 83 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
85 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 84 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signalDon e, this));
86 } 85 }
87 86
88 OwnPtr<WebDataConsumerHandle> m_handle; 87 OwnPtr<WebDataConsumerHandle> m_handle;
89 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; 88 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater;
90 }; 89 };
91 90
92 class ThreadingRegistrationDeleteHandleTest : public DataConsumerHandleTestUtil: :ThreadingTestBase { 91 class ThreadingRegistrationDeleteHandleTest : public DataConsumerHandleTestUtil: :ThreadingTestBase {
93 public: 92 public:
94 using Self = ThreadingRegistrationDeleteHandleTest; 93 using Self = ThreadingRegistrationDeleteHandleTest;
95 static PassRefPtr<Self> create() { return adoptRef(new Self); } 94 static PassRefPtr<Self> create() { return adoptRef(new Self); }
96 95
97 void run() 96 void run()
98 { 97 {
99 ThreadHolder holder(this); 98 ThreadHolder holder(this);
100 m_waitableEvent = adoptPtr(new WaitableEvent()); 99 m_waitableEvent = adoptPtr(new WaitableEvent());
101 100
102 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind (&Self::createHandle, this))); 101 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::c reateHandle, this));
103 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind( &Self::obtainReader, this))); 102 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::ob tainReader, this));
104 } 103 }
105 104
106 private: 105 private:
107 ThreadingRegistrationDeleteHandleTest() = default; 106 ThreadingRegistrationDeleteHandleTest() = default;
108 107
109 void createHandle() 108 void createHandle()
110 { 109 {
111 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater); 110 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater);
112 m_waitableEvent->signal(); 111 m_waitableEvent->signal();
113 } 112 }
114 113
115 void obtainReader() 114 void obtainReader()
116 { 115 {
117 m_reader = m_handle->obtainReader(&m_client); 116 m_reader = m_handle->obtainReader(&m_client);
118 postTaskToUpdatingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self: :update, this))); 117 postTaskToUpdatingThread(BLINK_FROM_HERE, threadSafeBind(&Self::update, this));
119 } 118 }
120 void update() 119 void update()
121 { 120 {
122 m_updater->update(DataConsumerHandle::create("handle2", m_context)); 121 m_updater->update(DataConsumerHandle::create("handle2", m_context));
123 m_updater.clear(); 122 m_updater.clear();
124 m_handle = nullptr; 123 m_handle = nullptr;
125 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 124 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
126 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 125 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signalDon e, this));
127 } 126 }
128 127
129 OwnPtr<WebDataConsumerHandle> m_handle; 128 OwnPtr<WebDataConsumerHandle> m_handle;
130 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; 129 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater;
131 }; 130 };
132 131
133 class ThreadingRegistrationDeleteReaderTest : public DataConsumerHandleTestUtil: :ThreadingTestBase { 132 class ThreadingRegistrationDeleteReaderTest : public DataConsumerHandleTestUtil: :ThreadingTestBase {
134 public: 133 public:
135 using Self = ThreadingRegistrationDeleteReaderTest; 134 using Self = ThreadingRegistrationDeleteReaderTest;
136 static PassRefPtr<Self> create() { return adoptRef(new Self); } 135 static PassRefPtr<Self> create() { return adoptRef(new Self); }
137 136
138 void run() 137 void run()
139 { 138 {
140 ThreadHolder holder(this); 139 ThreadHolder holder(this);
141 m_waitableEvent = adoptPtr(new WaitableEvent()); 140 m_waitableEvent = adoptPtr(new WaitableEvent());
142 141
143 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind (&Self::createHandle, this))); 142 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::c reateHandle, this));
144 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind( &Self::obtainReader, this))); 143 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::ob tainReader, this));
145 } 144 }
146 145
147 private: 146 private:
148 ThreadingRegistrationDeleteReaderTest() = default; 147 ThreadingRegistrationDeleteReaderTest() = default;
149 148
150 void createHandle() 149 void createHandle()
151 { 150 {
152 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater); 151 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater);
153 m_waitableEvent->signal(); 152 m_waitableEvent->signal();
154 } 153 }
155 154
156 void obtainReader() 155 void obtainReader()
157 { 156 {
158 m_reader = m_handle->obtainReader(&m_client); 157 m_reader = m_handle->obtainReader(&m_client);
159 postTaskToUpdatingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self: :update, this))); 158 postTaskToUpdatingThread(BLINK_FROM_HERE, threadSafeBind(&Self::update, this));
160 } 159 }
161 void update() 160 void update()
162 { 161 {
163 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 162 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
164 m_updater->update(DataConsumerHandle::create("handle2", m_context)); 163 m_updater->update(DataConsumerHandle::create("handle2", m_context));
165 m_updater.clear(); 164 m_updater.clear();
166 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 165 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
167 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 166 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signalDon e, this));
168 } 167 }
169 168
170 OwnPtr<WebDataConsumerHandle> m_handle; 169 OwnPtr<WebDataConsumerHandle> m_handle;
171 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; 170 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater;
172 }; 171 };
173 172
174 class ThreadingUpdatingReaderWhileUpdatingTest : public DataConsumerHandleTestUt il::ThreadingTestBase { 173 class ThreadingUpdatingReaderWhileUpdatingTest : public DataConsumerHandleTestUt il::ThreadingTestBase {
175 public: 174 public:
176 using Self = ThreadingUpdatingReaderWhileUpdatingTest; 175 using Self = ThreadingUpdatingReaderWhileUpdatingTest;
177 static PassRefPtr<Self> create() { return adoptRef(new Self); } 176 static PassRefPtr<Self> create() { return adoptRef(new Self); }
178 177
179 void run() 178 void run()
180 { 179 {
181 ThreadHolder holder(this); 180 ThreadHolder holder(this);
182 m_waitableEvent = adoptPtr(new WaitableEvent()); 181 m_waitableEvent = adoptPtr(new WaitableEvent());
183 m_updateEvent = adoptPtr(new WaitableEvent()); 182 m_updateEvent = adoptPtr(new WaitableEvent());
184 183
185 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind (&Self::createHandle, this))); 184 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::c reateHandle, this));
186 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind( &Self::obtainReader, this))); 185 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::ob tainReader, this));
187 } 186 }
188 187
189 private: 188 private:
190 ThreadingUpdatingReaderWhileUpdatingTest() = default; 189 ThreadingUpdatingReaderWhileUpdatingTest() = default;
191 190
192 void createHandle() 191 void createHandle()
193 { 192 {
194 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater); 193 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater);
195 m_waitableEvent->signal(); 194 m_waitableEvent->signal();
196 } 195 }
197 196
198 void obtainReader() 197 void obtainReader()
199 { 198 {
200 m_reader = m_handle->obtainReader(&m_client); 199 m_reader = m_handle->obtainReader(&m_client);
201 postTaskToUpdatingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self: :update, this))); 200 postTaskToUpdatingThread(BLINK_FROM_HERE, threadSafeBind(&Self::update, this));
202 m_updateEvent->wait(); 201 m_updateEvent->wait();
203 } 202 }
204 203
205 void update() 204 void update()
206 { 205 {
207 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: reobtainReader, this))); 206 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::reobtainR eader, this));
208 m_updater->update(DataConsumerHandle::create("handle2", m_context)); 207 m_updater->update(DataConsumerHandle::create("handle2", m_context));
209 m_updater.clear(); 208 m_updater.clear();
210 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 209 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
211 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 210 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signalDon e, this));
212 m_updateEvent->signal(); 211 m_updateEvent->signal();
213 } 212 }
214 213
215 void reobtainReader() 214 void reobtainReader()
216 { 215 {
217 m_reader = nullptr; 216 m_reader = nullptr;
218 m_reader = m_handle->obtainReader(&m_client); 217 m_reader = m_handle->obtainReader(&m_client);
219 } 218 }
220 219
221 OwnPtr<WebDataConsumerHandle> m_handle; 220 OwnPtr<WebDataConsumerHandle> m_handle;
222 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; 221 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater;
223 OwnPtr<WaitableEvent> m_updateEvent; 222 OwnPtr<WaitableEvent> m_updateEvent;
224 }; 223 };
225 224
226 class ThreadingRegistrationUpdateTwiceAtOneTimeTest : public DataConsumerHandleT estUtil::ThreadingTestBase { 225 class ThreadingRegistrationUpdateTwiceAtOneTimeTest : public DataConsumerHandleT estUtil::ThreadingTestBase {
227 public: 226 public:
228 using Self = ThreadingRegistrationUpdateTwiceAtOneTimeTest; 227 using Self = ThreadingRegistrationUpdateTwiceAtOneTimeTest;
229 static PassRefPtr<Self> create() { return adoptRef(new Self); } 228 static PassRefPtr<Self> create() { return adoptRef(new Self); }
230 229
231 void run() 230 void run()
232 { 231 {
233 ThreadHolder holder(this); 232 ThreadHolder holder(this);
234 m_waitableEvent = adoptPtr(new WaitableEvent()); 233 m_waitableEvent = adoptPtr(new WaitableEvent());
235 m_updateEvent = adoptPtr(new WaitableEvent()); 234 m_updateEvent = adoptPtr(new WaitableEvent());
236 235
237 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind (&Self::createHandle, this))); 236 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::c reateHandle, this));
238 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind( &Self::obtainReader, this))); 237 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self::ob tainReader, this));
239 } 238 }
240 239
241 private: 240 private:
242 ThreadingRegistrationUpdateTwiceAtOneTimeTest() = default; 241 ThreadingRegistrationUpdateTwiceAtOneTimeTest() = default;
243 242
244 void createHandle() 243 void createHandle()
245 { 244 {
246 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater); 245 m_handle = CompositeDataConsumerHandle::create(DataConsumerHandle::creat e("handle1", m_context), &m_updater);
247 m_waitableEvent->signal(); 246 m_waitableEvent->signal();
248 } 247 }
249 248
250 void obtainReader() 249 void obtainReader()
251 { 250 {
252 m_reader = m_handle->obtainReader(&m_client); 251 m_reader = m_handle->obtainReader(&m_client);
253 postTaskToUpdatingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self: :update, this))); 252 postTaskToUpdatingThread(BLINK_FROM_HERE, threadSafeBind(&Self::update, this));
254 // Stalls this thread while updating handles. 253 // Stalls this thread while updating handles.
255 m_updateEvent->wait(); 254 m_updateEvent->wait();
256 } 255 }
257 void update() 256 void update()
258 { 257 {
259 m_updater->update(DataConsumerHandle::create("handle2", m_context)); 258 m_updater->update(DataConsumerHandle::create("handle2", m_context));
260 m_updater->update(DataConsumerHandle::create("handle3", m_context)); 259 m_updater->update(DataConsumerHandle::create("handle3", m_context));
261 m_updateEvent->signal(); 260 m_updateEvent->signal();
262 m_updater.clear(); 261 m_updater.clear();
263 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: resetReader, this))); 262 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::resetRead er, this));
264 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 263 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signalDon e, this));
265 } 264 }
266 265
267 OwnPtr<WebDataConsumerHandle> m_handle; 266 OwnPtr<WebDataConsumerHandle> m_handle;
268 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; 267 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater;
269 OwnPtr<WaitableEvent> m_updateEvent; 268 OwnPtr<WaitableEvent> m_updateEvent;
270 }; 269 };
271 270
272 TEST(CompositeDataConsumerHandleTest, Read) 271 TEST(CompositeDataConsumerHandleTest, Read)
273 { 272 {
274 char buffer[20]; 273 char buffer[20];
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 { 488 {
490 RefPtr<DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest> test = DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest::create(); 489 RefPtr<DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest> test = DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest::create();
491 CompositeDataConsumerHandle::Updater* updater = nullptr; 490 CompositeDataConsumerHandle::Updater* updater = nullptr;
492 // Test this function doesn't crash. 491 // Test this function doesn't crash.
493 test->run(CompositeDataConsumerHandle::create(createDoneDataConsumerHandle() , &updater)); 492 test->run(CompositeDataConsumerHandle::create(createDoneDataConsumerHandle() , &updater));
494 } 493 }
495 494
496 } // namespace 495 } // namespace
497 496
498 } // namespace blink 497 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698