| Index: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp b/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
|
| index dd6c63b3ef34b5e2ecd9d4ac52c942e52d258548..4e9a25a8d7b13ffbba2dac473be34ef374efa194 100644
|
| --- a/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
|
| +++ b/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp
|
| @@ -45,6 +45,7 @@
|
| #include "platform/heap/Handle.h"
|
| #include "platform/heap/HeapAllocator.h"
|
| #include "platform/heap/Member.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"
|
| @@ -672,4 +673,60 @@ TEST_F(ResourceFetcherTest, Revalidate304) {
|
| EXPECT_NE(resource, newResource);
|
| }
|
|
|
| +TEST_F(ResourceFetcherTest, CacheAwareFontLoading) {
|
| + KURL url(ParsedURLString, "http://127.0.0.1:8000/font.woff");
|
| + ResourceResponse response;
|
| + response.setURL(url);
|
| + response.setHTTPStatusCode(200);
|
| + Platform::current()->getURLLoaderMockFactory()->registerURL(
|
| + url, WrappedResourceResponse(response), "");
|
| +
|
| + ResourceFetcher* fetcher = ResourceFetcher::create(
|
| + MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
|
| +
|
| + FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
|
| + fetchRequest.setCacheAwareLoadingEnabled(IsCacheAwareLoadingEnabled);
|
| + FontResource* resource = FontResource::fetch(fetchRequest, fetcher);
|
| + ASSERT_TRUE(resource);
|
| +
|
| + Persistent<MockFontResourceClient> client =
|
| + new MockFontResourceClient(resource);
|
| + fetcher->startLoad(resource);
|
| + EXPECT_TRUE(resource->loader()->isCacheAwareLoadingActivated());
|
| + resource->m_loadLimitState = FontResource::UnderLimit;
|
| +
|
| + // FontResource callbacks should be blocked during cache-aware loading.
|
| + resource->fontLoadShortLimitCallback(nullptr);
|
| + EXPECT_FALSE(client->fontLoadShortLimitExceededCalled());
|
| +
|
| + // Fail first request as disk cache miss.
|
| + resource->loader()->didFail(ResourceError::cacheMissError(url));
|
| +
|
| + // Once cache miss error returns, previously blocked callbacks should be
|
| + // called immediately.
|
| + EXPECT_FALSE(resource->loader()->isCacheAwareLoadingActivated());
|
| + EXPECT_TRUE(client->fontLoadShortLimitExceededCalled());
|
| + EXPECT_FALSE(client->fontLoadLongLimitExceededCalled());
|
| +
|
| + // Add client now, fontLoadShortLimitExceeded() should be called.
|
| + Persistent<MockFontResourceClient> client2 =
|
| + new MockFontResourceClient(resource);
|
| + EXPECT_TRUE(client2->fontLoadShortLimitExceededCalled());
|
| + EXPECT_FALSE(client2->fontLoadLongLimitExceededCalled());
|
| +
|
| + // FontResource callbacks are not blocked now.
|
| + resource->fontLoadLongLimitCallback(nullptr);
|
| + EXPECT_TRUE(client->fontLoadLongLimitExceededCalled());
|
| +
|
| + // Add client now, both callbacks should be called.
|
| + Persistent<MockFontResourceClient> client3 =
|
| + new MockFontResourceClient(resource);
|
| + EXPECT_TRUE(client3->fontLoadShortLimitExceededCalled());
|
| + EXPECT_TRUE(client3->fontLoadLongLimitExceededCalled());
|
| +
|
| + Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
|
| + Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
|
| + memoryCache()->remove(resource);
|
| +}
|
| +
|
| } // namespace blink
|
|
|