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 665986cf11d8ead0c2e3e8a9b3685cf1f82812b3..cad26129f1b9819df10c3f4cd59a90e8e08add20 100644 |
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp |
+++ b/third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp |
@@ -44,6 +44,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" |
@@ -716,4 +717,64 @@ TEST_F(ResourceFetcherTest, Revalidate304) { |
EXPECT_NE(resource, newResource); |
} |
+// Helper for accessing private members of FontResource. |
+class FontResourceTestHelper { |
+ public: |
+ static void initLoadLimitState(FontResource* resource) { |
+ resource->m_loadLimitState = FontResource::UnderLimit; |
+ } |
+ |
+ static void callFontLoadShortLimitCallback(FontResource* resource) { |
+ resource->fontLoadShortLimitCallback(nullptr); |
+ } |
+ |
+ static void callFontLoadLongLimitCallback(FontResource* resource) { |
+ resource->fontLoadLongLimitCallback(nullptr); |
+ } |
+}; |
+ |
+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(ResourceFetcherTestMockFetchContext::create()); |
+ |
+ 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()); |
+ FontResourceTestHelper::initLoadLimitState(resource); |
+ |
+ // FontResource callbacks should be blocked during cache-aware loading. |
+ FontResourceTestHelper::callFontLoadShortLimitCallback(resource); |
+ 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()); |
+ |
yhirano
2016/11/10 04:17:54
Can you add one more client to the resource and se
Shao-Chuan Lee
2016/11/14 08:08:02
Done.
|
+ // FontResource callbacks are not blocked now. |
+ FontResourceTestHelper::callFontLoadLongLimitCallback(resource); |
+ EXPECT_TRUE(client->fontLoadLongLimitExceededCalled()); |
+ |
yhirano
2016/11/10 04:17:54
ditto
Shao-Chuan Lee
2016/11/14 08:08:02
Done.
|
+ Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
+ Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
+ memoryCache()->remove(resource); |
+} |
+ |
} // namespace blink |