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

Unified Diff: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcherTest.cpp

Issue 2584423002: Loading: move core/fetch to platform/loader/fetch (Closed)
Patch Set: rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcherTest.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp b/third_party/WebKit/Source/platform/loader/fetch/ResourceFetcherTest.cpp
similarity index 89%
rename from third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
rename to third_party/WebKit/Source/platform/loader/fetch/ResourceFetcherTest.cpp
index 595f3b97acc8279cd8d947f1026bd0b63c9b2008..4adda9e94f284fd0c3d4e73c1356d431e3445067 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
+++ b/third_party/WebKit/Source/platform/loader/fetch/ResourceFetcherTest.cpp
@@ -28,29 +28,32 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "core/fetch/ResourceFetcher.h"
-
-#include "core/fetch/FetchInitiatorInfo.h"
-#include "core/fetch/FetchInitiatorTypeNames.h"
-#include "core/fetch/FetchRequest.h"
-#include "core/fetch/MemoryCache.h"
-#include "core/fetch/MockFetchContext.h"
-#include "core/fetch/MockResource.h"
-#include "core/fetch/MockResourceClient.h"
-#include "core/fetch/RawResource.h"
-#include "core/fetch/ResourceLoader.h"
+#include "platform/loader/fetch/ResourceFetcher.h"
+
#include "platform/WebTaskRunner.h"
#include "platform/exported/WrappedResourceResponse.h"
#include "platform/heap/Handle.h"
#include "platform/heap/HeapAllocator.h"
#include "platform/heap/Member.h"
+#include "platform/loader/fetch/FetchInitiatorInfo.h"
+#include "platform/loader/fetch/FetchInitiatorTypeNames.h"
+#include "platform/loader/fetch/FetchRequest.h"
+#include "platform/loader/fetch/MemoryCache.h"
+#include "platform/loader/fetch/MockFetchContext.h"
+#include "platform/loader/fetch/MockResource.h"
+#include "platform/loader/fetch/MockResourceClient.h"
+#include "platform/loader/fetch/RawResource.h"
+#include "platform/loader/fetch/ResourceLoader.h"
+#include "platform/network/ResourceError.h"
#include "platform/network/ResourceRequest.h"
#include "platform/network/ResourceTimingInfo.h"
#include "platform/scheduler/test/fake_web_task_runner.h"
+#include "platform/testing/TestingPlatformSupport.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/testing/weburl_loader_mock.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebURLLoader.h"
#include "public/platform/WebURLLoaderMockFactory.h"
#include "public/platform/WebURLResponse.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -67,9 +70,50 @@ constexpr char kTestResourceMimeType[] = "image/png";
constexpr int kTestResourceSize = 103; // size of web/tests/data/white-1x1.png
}
-class ResourceFetcherTest : public ::testing::Test {};
+class MockDefaultWebURLLoader : public WebURLLoader {
+ public:
+ ~MockDefaultWebURLLoader() override {}
+ void loadSynchronously(const WebURLRequest&,
+ WebURLResponse&,
+ WebURLError&,
+ WebData&,
+ int64_t& encodedDataLength,
+ int64_t& encodedBodyLength) override {}
+ void loadAsynchronously(const WebURLRequest&, WebURLLoaderClient*) override {}
+ void cancel() override {}
+ void setDefersLoading(bool) override {}
+ void didChangePriority(WebURLRequest::Priority newPriority) override {}
+ void didChangePriority(WebURLRequest::Priority newPriority,
+ int intraPriorityValue) override {}
+ void setLoadingTaskRunner(base::SingleThreadTaskRunner*) override {}
+};
+
+class FetchTestingPlatform : public TestingPlatformSupportWithMockScheduler {
+ public:
+ WebURLError cancelledError(const WebURL& url) const override {
+ return ResourceError::ResourceError(errorDomainBlinkInternal, -1,
+ url.string(),
+ "cancelledError for testing");
+ }
+ WebURLLoaderMockFactory* getURLLoaderMockFactory() override {
+ if (!m_urlLoaderMockFactory.get())
+ m_urlLoaderMockFactory = WebURLLoaderMockFactory::create();
+ return m_urlLoaderMockFactory.get();
+ }
+ WebURLLoader* createURLLoader() override {
+ return getURLLoaderMockFactory()->createURLLoader(
+ new MockDefaultWebURLLoader);
+ }
+
+ private:
+ std::unique_ptr<WebURLLoaderMockFactory> m_urlLoaderMockFactory;
+};
+
+using ResourceFetcherTest = ::testing::Test;
TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
// Try to request a url. The request should fail, and a resource in an error
// state should be returned, and no resource should be present in the cache.
@@ -90,6 +134,8 @@ TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) {
}
TEST_F(ResourceFetcherTest, UseExistingResource) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
@@ -116,6 +162,8 @@ TEST_F(ResourceFetcherTest, UseExistingResource) {
}
TEST_F(ResourceFetcherTest, Vary) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
Resource* resource = RawResource::create(url, Resource::Raw);
memoryCache()->add(resource);
@@ -146,6 +194,8 @@ TEST_F(ResourceFetcherTest, Vary) {
}
TEST_F(ResourceFetcherTest, NavigationTimingInfo) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
ResourceResponse response;
response.setURL(url);
@@ -186,6 +236,8 @@ TEST_F(ResourceFetcherTest, NavigationTimingInfo) {
}
TEST_F(ResourceFetcherTest, VaryOnBack) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
MockFetchContext* context =
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource);
context->setCachePolicy(CachePolicyHistoryBuffer);
@@ -214,6 +266,8 @@ TEST_F(ResourceFetcherTest, VaryOnBack) {
}
TEST_F(ResourceFetcherTest, VaryResource) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
@@ -276,6 +330,8 @@ class RequestSameResourceOnComplete
};
TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.png");
ResourceResponse response;
response.setURL(url);
@@ -302,6 +358,8 @@ TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) {
}
TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo"));
@@ -364,6 +422,8 @@ class ServeRequestsOnCompleteClient final
// WebURLLoader before notifying its clients, a nested run loop may send a
// network response, leading to an invalid state transition in ResourceLoader.
TEST_F(ResourceFetcherTest, ResponseOnCancel) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.png");
URLTestHelpers::registerMockedURLLoad(url, kTestResourceFilename,
kTestResourceMimeType);
@@ -433,6 +493,8 @@ class ScopedMockRedirectRequester {
};
TEST_F(ResourceFetcherTest, SameOriginRedirect) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
const char redirectURL[] = "http://127.0.0.1:8000/redirect.html";
const char finalURL[] = "http://127.0.0.1:8000/final.html";
ScopedMockRedirectRequester requester;
@@ -445,6 +507,8 @@ TEST_F(ResourceFetcherTest, SameOriginRedirect) {
}
TEST_F(ResourceFetcherTest, CrossOriginRedirect) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
const char redirectURL[] = "http://otherorigin.test/redirect.html";
const char finalURL[] = "http://127.0.0.1:8000/final.html";
ScopedMockRedirectRequester requester;
@@ -456,6 +520,8 @@ TEST_F(ResourceFetcherTest, CrossOriginRedirect) {
}
TEST_F(ResourceFetcherTest, ComplexCrossOriginRedirect) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
const char redirectURL1[] = "http://127.0.0.1:8000/redirect1.html";
const char redirectURL2[] = "http://otherorigin.test/redirect2.html";
const char redirectURL3[] = "http://127.0.0.1:8000/redirect3.html";
@@ -471,6 +537,8 @@ TEST_F(ResourceFetcherTest, ComplexCrossOriginRedirect) {
}
TEST_F(ResourceFetcherTest, SynchronousRequest) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.png");
URLTestHelpers::registerMockedURLLoad(url, kTestResourceFilename,
kTestResourceMimeType);
@@ -491,6 +559,8 @@ TEST_F(ResourceFetcherTest, SynchronousRequest) {
}
TEST_F(ResourceFetcherTest, PreloadResourceTwice) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
@@ -516,6 +586,8 @@ TEST_F(ResourceFetcherTest, PreloadResourceTwice) {
}
TEST_F(ResourceFetcherTest, LinkPreloadResourceAndUse) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
@@ -556,6 +628,8 @@ TEST_F(ResourceFetcherTest, LinkPreloadResourceAndUse) {
}
TEST_F(ResourceFetcherTest, LinkPreloadResourceMultipleFetchersAndUse) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
ResourceFetcher* fetcher2 = ResourceFetcher::create(
@@ -637,6 +711,8 @@ TEST_F(ResourceFetcherTest, LinkPreloadResourceMultipleFetchersAndUse) {
}
TEST_F(ResourceFetcherTest, Revalidate304) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
Resource* resource = RawResource::create(url, Resource::Raw);
memoryCache()->add(resource);
@@ -663,6 +739,8 @@ TEST_F(ResourceFetcherTest, Revalidate304) {
}
TEST_F(ResourceFetcherTest, LinkPreloadResourceMultipleFetchersAndMove) {
+ ScopedTestingPlatformSupport<FetchTestingPlatform> platform;
+
ResourceFetcher* fetcher = ResourceFetcher::create(
MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
ResourceFetcher* fetcher2 = ResourceFetcher::create(

Powered by Google App Engine
This is Rietveld 408576698