| 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/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
| 9 #include "core/loader/DocumentThreadableLoader.h" | 10 #include "core/loader/DocumentThreadableLoader.h" |
| 10 #include "core/loader/ThreadableLoaderClient.h" | 11 #include "core/loader/ThreadableLoaderClient.h" |
| 11 #include "core/loader/WorkerThreadableLoader.h" | 12 #include "core/loader/WorkerThreadableLoader.h" |
| 12 #include "core/testing/DummyPageHolder.h" | 13 #include "core/testing/DummyPageHolder.h" |
| 13 #include "core/workers/WorkerLoaderProxy.h" | 14 #include "core/workers/WorkerLoaderProxy.h" |
| 14 #include "core/workers/WorkerThreadTestHelper.h" | 15 #include "core/workers/WorkerThreadTestHelper.h" |
| 15 #include "platform/WaitableEvent.h" | 16 #include "platform/WaitableEvent.h" |
| 16 #include "platform/geometry/IntSize.h" | 17 #include "platform/geometry/IntSize.h" |
| 17 #include "platform/network/ResourceError.h" | 18 #include "platform/network/ResourceError.h" |
| 18 #include "platform/network/ResourceRequest.h" | 19 #include "platform/network/ResourceRequest.h" |
| 19 #include "platform/network/ResourceResponse.h" | 20 #include "platform/network/ResourceResponse.h" |
| 20 #include "platform/network/ResourceTimingInfo.h" | 21 #include "platform/network/ResourceTimingInfo.h" |
| 21 #include "platform/testing/URLTestHelpers.h" | 22 #include "platform/testing/URLTestHelpers.h" |
| 22 #include "platform/testing/UnitTestHelpers.h" | 23 #include "platform/testing/UnitTestHelpers.h" |
| 23 #include "platform/weborigin/KURL.h" | 24 #include "platform/weborigin/KURL.h" |
| 24 #include "platform/weborigin/SecurityOrigin.h" | 25 #include "platform/weborigin/SecurityOrigin.h" |
| 25 #include "public/platform/Platform.h" | 26 #include "public/platform/Platform.h" |
| 26 #include "public/platform/WebURLLoadTiming.h" | 27 #include "public/platform/WebURLLoadTiming.h" |
| 28 #include "public/platform/WebURLLoaderMockFactory.h" |
| 27 #include "public/platform/WebURLResponse.h" | 29 #include "public/platform/WebURLResponse.h" |
| 28 #include "public/platform/WebUnitTestSupport.h" | |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
| 32 #include "wtf/OwnPtr.h" | 33 #include "wtf/OwnPtr.h" |
| 33 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
| 34 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 337 } |
| 337 | 338 |
| 338 void cancelLoader() { m_helper->cancelLoader(); } | 339 void cancelLoader() { m_helper->cancelLoader(); } |
| 339 void clearLoader() { m_helper->clearLoader(); } | 340 void clearLoader() { m_helper->clearLoader(); } |
| 340 Checkpoint& checkpoint() { return m_helper->checkpoint(); } | 341 Checkpoint& checkpoint() { return m_helper->checkpoint(); } |
| 341 void callCheckpoint(int n) { m_helper->callCheckpoint(n); } | 342 void callCheckpoint(int n) { m_helper->callCheckpoint(n); } |
| 342 | 343 |
| 343 void serveRequests() | 344 void serveRequests() |
| 344 { | 345 { |
| 345 m_helper->onServeRequests(); | 346 m_helper->onServeRequests(); |
| 346 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); | 347 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); |
| 347 } | 348 } |
| 348 | 349 |
| 349 void createLoader(CrossOriginRequestPolicy crossOriginRequestPolicy = AllowC
rossOriginRequests) | 350 void createLoader(CrossOriginRequestPolicy crossOriginRequestPolicy = AllowC
rossOriginRequests) |
| 350 { | 351 { |
| 351 m_helper->createLoader(client(), crossOriginRequestPolicy); | 352 m_helper->createLoader(client(), crossOriginRequestPolicy); |
| 352 } | 353 } |
| 353 | 354 |
| 354 MockThreadableLoaderClient* client() const { return m_client.get(); } | 355 MockThreadableLoaderClient* client() const { return m_client.get(); } |
| 355 | 356 |
| 356 private: | 357 private: |
| 357 void SetUp() override | 358 void SetUp() override |
| 358 { | 359 { |
| 359 setUpSuccessURL(); | 360 setUpSuccessURL(); |
| 360 setUpErrorURL(); | 361 setUpErrorURL(); |
| 361 setUpRedirectURL(); | 362 setUpRedirectURL(); |
| 362 setUpRedirectLoopURL(); | 363 setUpRedirectLoopURL(); |
| 363 | 364 |
| 364 m_client = MockThreadableLoaderClient::create(); | 365 m_client = MockThreadableLoaderClient::create(); |
| 365 m_helper->onSetUp(); | 366 m_helper->onSetUp(); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void TearDown() override | 369 void TearDown() override |
| 369 { | 370 { |
| 370 m_helper->onTearDown(); | 371 m_helper->onTearDown(); |
| 371 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 372 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 373 memoryCache()->evictResources(); |
| 372 m_client.clear(); | 374 m_client.clear(); |
| 373 } | 375 } |
| 374 | 376 |
| 375 void setUpSuccessURL() | 377 void setUpSuccessURL() |
| 376 { | 378 { |
| 377 URLTestHelpers::registerMockedURLLoad(successURL(), "fox-null-terminated
.html", "text/html"); | 379 URLTestHelpers::registerMockedURLLoad(successURL(), "fox-null-terminated
.html", "text/html"); |
| 378 } | 380 } |
| 379 | 381 |
| 380 void setUpErrorURL() | 382 void setUpErrorURL() |
| 381 { | 383 { |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th
is, &ThreadableLoaderTest::clearLoader)); | 829 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th
is, &ThreadableLoaderTest::clearLoader)); |
| 828 | 830 |
| 829 startLoader(redirectLoopURL()); | 831 startLoader(redirectLoopURL()); |
| 830 callCheckpoint(2); | 832 callCheckpoint(2); |
| 831 serveRequests(); | 833 serveRequests(); |
| 832 } | 834 } |
| 833 | 835 |
| 834 } // namespace | 836 } // namespace |
| 835 | 837 |
| 836 } // namespace blink | 838 } // namespace blink |
| OLD | NEW |