| Index: third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp
|
| index 6604abe08287fd704c2f389e6ec15eca3477e2d2..2eaa28efcc87883654c8e1253a83ffcfba447c25 100644
|
| --- a/third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp
|
| +++ b/third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp
|
| @@ -8,11 +8,13 @@
|
| #include "core/fetch/FetchRequest.h"
|
| #include "core/fetch/MemoryCache.h"
|
| #include "core/fetch/MockFetchContext.h"
|
| -#include "core/fetch/MockResourceClients.h"
|
| #include "core/fetch/ResourceFetcher.h"
|
| #include "core/fetch/ResourceLoader.h"
|
| +#include "core/loader/resource/MockFontResourceClient.h"
|
| #include "platform/exported/WrappedResourceResponse.h"
|
| +#include "platform/network/ResourceError.h"
|
| #include "platform/network/ResourceRequest.h"
|
| +#include "platform/network/ResourceResponse.h"
|
| #include "platform/weborigin/KURL.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebURLLoaderMockFactory.h"
|
| @@ -82,4 +84,61 @@ TEST_F(FontResourceTest,
|
| memoryCache()->remove(resource1);
|
| }
|
|
|
| +// Tests if cache-aware font loading works correctly.
|
| +TEST_F(FontResourceTest, 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
|
|
|