| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/ThreadableLoader.h" | 5 #include "core/loader/ThreadableLoader.h" |
| 6 | 6 |
| 7 #include "core/dom/CrossThreadTask.h" | 7 #include "core/dom/CrossThreadTask.h" |
| 8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
| 9 #include "core/fetch/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
| 10 #include "core/loader/DocumentThreadableLoader.h" | 10 #include "core/loader/DocumentThreadableLoader.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 class WorkerThreadableLoaderTestHelper : public ThreadableLoaderTestHelper, publ
ic WorkerLoaderProxyProvider { | 163 class WorkerThreadableLoaderTestHelper : public ThreadableLoaderTestHelper, publ
ic WorkerLoaderProxyProvider { |
| 164 public: | 164 public: |
| 165 WorkerThreadableLoaderTestHelper() | 165 WorkerThreadableLoaderTestHelper() |
| 166 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) | 166 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) |
| 167 { | 167 { |
| 168 } | 168 } |
| 169 | 169 |
| 170 void createLoader(ThreadableLoaderClient* client, CrossOriginRequestPolicy c
rossOriginRequestPolicy) override | 170 void createLoader(ThreadableLoaderClient* client, CrossOriginRequestPolicy c
rossOriginRequestPolicy) override |
| 171 { | 171 { |
| 172 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); | 172 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); |
| 173 postTaskToWorkerGlobalScope(createCrossThreadTask( | 173 postTaskToWorkerGlobalScope(BLINK_FROM_HERE, |
| 174 &WorkerThreadableLoaderTestHelper::workerCreateLoader, | 174 createCrossThreadTask( |
| 175 crossThreadUnretained(this), | 175 &WorkerThreadableLoaderTestHelper::workerCreateLoader, |
| 176 crossThreadUnretained(client), | 176 crossThreadUnretained(this), |
| 177 crossThreadUnretained(completionEvent.get()), | 177 crossThreadUnretained(client), |
| 178 crossOriginRequestPolicy)); | 178 crossThreadUnretained(completionEvent.get()), |
| 179 crossOriginRequestPolicy)); |
| 179 completionEvent->wait(); | 180 completionEvent->wait(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void startLoader(const ResourceRequest& request) override | 183 void startLoader(const ResourceRequest& request) override |
| 183 { | 184 { |
| 184 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); | 185 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); |
| 185 postTaskToWorkerGlobalScope(createCrossThreadTask( | 186 postTaskToWorkerGlobalScope(BLINK_FROM_HERE, |
| 186 &WorkerThreadableLoaderTestHelper::workerStartLoader, | 187 createCrossThreadTask( |
| 187 crossThreadUnretained(this), | 188 &WorkerThreadableLoaderTestHelper::workerStartLoader, |
| 188 crossThreadUnretained(completionEvent.get()), | 189 crossThreadUnretained(this), |
| 189 request)); | 190 crossThreadUnretained(completionEvent.get()), |
| 191 request)); |
| 190 completionEvent->wait(); | 192 completionEvent->wait(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 // Must be called on the worker thread. | 195 // Must be called on the worker thread. |
| 194 void cancelLoader() override | 196 void cancelLoader() override |
| 195 { | 197 { |
| 196 ASSERT(m_workerThread); | 198 ASSERT(m_workerThread); |
| 197 ASSERT(m_workerThread->isCurrentThread()); | 199 ASSERT(m_workerThread->isCurrentThread()); |
| 198 m_loader->cancel(); | 200 m_loader->cancel(); |
| 199 } | 201 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 Checkpoint& checkpoint() override | 219 Checkpoint& checkpoint() override |
| 218 { | 220 { |
| 219 return m_checkpoint; | 221 return m_checkpoint; |
| 220 } | 222 } |
| 221 | 223 |
| 222 void callCheckpoint(int n) override | 224 void callCheckpoint(int n) override |
| 223 { | 225 { |
| 224 testing::runPendingTasks(); | 226 testing::runPendingTasks(); |
| 225 | 227 |
| 226 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); | 228 std::unique_ptr<WaitableEvent> completionEvent = wrapUnique(new Waitable
Event()); |
| 227 postTaskToWorkerGlobalScope(createCrossThreadTask( | 229 postTaskToWorkerGlobalScope(BLINK_FROM_HERE, |
| 228 &WorkerThreadableLoaderTestHelper::workerCallCheckpoint, | 230 createCrossThreadTask( |
| 229 crossThreadUnretained(this), | 231 &WorkerThreadableLoaderTestHelper::workerCallCheckpoint, |
| 230 crossThreadUnretained(completionEvent.get()), | 232 crossThreadUnretained(this), |
| 231 n)); | 233 crossThreadUnretained(completionEvent.get()), |
| 234 n)); |
| 232 completionEvent->wait(); | 235 completionEvent->wait(); |
| 233 } | 236 } |
| 234 | 237 |
| 235 void onSetUp() override | 238 void onSetUp() override |
| 236 { | 239 { |
| 237 m_mockWorkerReportingProxy = wrapUnique(new MockWorkerReportingProxy()); | 240 m_mockWorkerReportingProxy = wrapUnique(new MockWorkerReportingProxy()); |
| 238 m_securityOrigin = document().getSecurityOrigin(); | 241 m_securityOrigin = document().getSecurityOrigin(); |
| 239 m_workerThread = wrapUnique(new WorkerThreadForTest( | 242 m_workerThread = wrapUnique(new WorkerThreadForTest( |
| 240 this, | 243 this, |
| 241 *m_mockWorkerReportingProxy)); | 244 *m_mockWorkerReportingProxy)); |
| 242 | 245 |
| 243 expectWorkerLifetimeReportingCalls(); | 246 expectWorkerLifetimeReportingCalls(); |
| 244 m_workerThread->startWithSourceCode(m_securityOrigin.get(), "//fake sour
ce code"); | 247 m_workerThread->startWithSourceCode(m_securityOrigin.get(), "//fake sour
ce code"); |
| 245 m_workerThread->waitForInit(); | 248 m_workerThread->waitForInit(); |
| 246 } | 249 } |
| 247 | 250 |
| 248 void onServeRequests() override | 251 void onServeRequests() override |
| 249 { | 252 { |
| 250 testing::runPendingTasks(); | 253 testing::runPendingTasks(); |
| 251 } | 254 } |
| 252 | 255 |
| 253 void onTearDown() override | 256 void onTearDown() override |
| 254 { | 257 { |
| 255 postTaskToWorkerGlobalScope(createCrossThreadTask(&WorkerThreadableLoade
rTestHelper::clearLoader, crossThreadUnretained(this))); | 258 postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThreadTask(&Work
erThreadableLoaderTestHelper::clearLoader, crossThreadUnretained(this))); |
| 256 m_workerThread->terminateAndWait(); | 259 m_workerThread->terminateAndWait(); |
| 257 | 260 |
| 258 // Needed to clean up the things on the main thread side and | 261 // Needed to clean up the things on the main thread side and |
| 259 // avoid Resource leaks. | 262 // avoid Resource leaks. |
| 260 testing::runPendingTasks(); | 263 testing::runPendingTasks(); |
| 261 | 264 |
| 262 m_workerThread->workerLoaderProxy()->detachProvider(this); | 265 m_workerThread->workerLoaderProxy()->detachProvider(this); |
| 263 } | 266 } |
| 264 | 267 |
| 265 private: | 268 private: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 308 |
| 306 void workerCallCheckpoint(WaitableEvent* event, int n) | 309 void workerCallCheckpoint(WaitableEvent* event, int n) |
| 307 { | 310 { |
| 308 ASSERT(m_workerThread); | 311 ASSERT(m_workerThread); |
| 309 ASSERT(m_workerThread->isCurrentThread()); | 312 ASSERT(m_workerThread->isCurrentThread()); |
| 310 m_checkpoint.Call(n); | 313 m_checkpoint.Call(n); |
| 311 event->signal(); | 314 event->signal(); |
| 312 } | 315 } |
| 313 | 316 |
| 314 // WorkerLoaderProxyProvider methods. | 317 // WorkerLoaderProxyProvider methods. |
| 315 void postTaskToLoader(std::unique_ptr<ExecutionContextTask> task) override | 318 void postTaskToLoader(const WebTraceLocation& location, std::unique_ptr<Exec
utionContextTask> task) override |
| 316 { | 319 { |
| 317 ASSERT(m_workerThread); | 320 ASSERT(m_workerThread); |
| 318 ASSERT(m_workerThread->isCurrentThread()); | 321 ASSERT(m_workerThread->isCurrentThread()); |
| 319 document().postTask(BLINK_FROM_HERE, std::move(task)); | 322 document().postTask(location, std::move(task)); |
| 320 } | 323 } |
| 321 | 324 |
| 322 bool postTaskToWorkerGlobalScope(std::unique_ptr<ExecutionContextTask> task)
override | 325 bool postTaskToWorkerGlobalScope(const WebTraceLocation& location, std::uniq
ue_ptr<ExecutionContextTask> task) override |
| 323 { | 326 { |
| 324 ASSERT(m_workerThread); | 327 ASSERT(m_workerThread); |
| 325 m_workerThread->postTask(BLINK_FROM_HERE, std::move(task)); | 328 m_workerThread->postTask(location, std::move(task)); |
| 326 return true; | 329 return true; |
| 327 } | 330 } |
| 328 | 331 |
| 329 RefPtr<SecurityOrigin> m_securityOrigin; | 332 RefPtr<SecurityOrigin> m_securityOrigin; |
| 330 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 333 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
| 331 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 334 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
| 332 | 335 |
| 333 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 336 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 334 Checkpoint m_checkpoint; | 337 Checkpoint m_checkpoint; |
| 335 // |m_loader| must be touched only from the worker thread only. | 338 // |m_loader| must be touched only from the worker thread only. |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th
is, &ThreadableLoaderTest::clearLoader)); | 849 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th
is, &ThreadableLoaderTest::clearLoader)); |
| 847 | 850 |
| 848 startLoader(redirectLoopURL()); | 851 startLoader(redirectLoopURL()); |
| 849 callCheckpoint(2); | 852 callCheckpoint(2); |
| 850 serveRequests(); | 853 serveRequests(); |
| 851 } | 854 } |
| 852 | 855 |
| 853 } // namespace | 856 } // namespace |
| 854 | 857 |
| 855 } // namespace blink | 858 } // namespace blink |
| OLD | NEW |