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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp

Issue 2453813004: WebFonts cache-aware timeout adaptation (Closed)
Patch Set: rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 #include "core/fetch/MemoryCache.h" 38 #include "core/fetch/MemoryCache.h"
39 #include "core/fetch/MockFetchContext.h" 39 #include "core/fetch/MockFetchContext.h"
40 #include "core/fetch/MockResourceClients.h" 40 #include "core/fetch/MockResourceClients.h"
41 #include "core/fetch/RawResource.h" 41 #include "core/fetch/RawResource.h"
42 #include "core/fetch/ResourceLoader.h" 42 #include "core/fetch/ResourceLoader.h"
43 #include "platform/WebTaskRunner.h" 43 #include "platform/WebTaskRunner.h"
44 #include "platform/exported/WrappedResourceResponse.h" 44 #include "platform/exported/WrappedResourceResponse.h"
45 #include "platform/heap/Handle.h" 45 #include "platform/heap/Handle.h"
46 #include "platform/heap/HeapAllocator.h" 46 #include "platform/heap/HeapAllocator.h"
47 #include "platform/heap/Member.h" 47 #include "platform/heap/Member.h"
48 #include "platform/network/ResourceError.h"
48 #include "platform/network/ResourceRequest.h" 49 #include "platform/network/ResourceRequest.h"
49 #include "platform/network/ResourceTimingInfo.h" 50 #include "platform/network/ResourceTimingInfo.h"
50 #include "platform/scheduler/test/fake_web_task_runner.h" 51 #include "platform/scheduler/test/fake_web_task_runner.h"
51 #include "platform/testing/URLTestHelpers.h" 52 #include "platform/testing/URLTestHelpers.h"
52 #include "platform/testing/weburl_loader_mock.h" 53 #include "platform/testing/weburl_loader_mock.h"
53 #include "platform/weborigin/KURL.h" 54 #include "platform/weborigin/KURL.h"
54 #include "public/platform/Platform.h" 55 #include "public/platform/Platform.h"
55 #include "public/platform/WebURLLoaderMockFactory.h" 56 #include "public/platform/WebURLLoaderMockFactory.h"
56 #include "public/platform/WebURLResponse.h" 57 #include "public/platform/WebURLResponse.h"
57 #include "testing/gtest/include/gtest/gtest.h" 58 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 FetchRequest(resourceRequest, FetchInitiatorInfo()); 666 FetchRequest(resourceRequest, FetchInitiatorInfo());
666 Platform::current()->getURLLoaderMockFactory()->registerURL( 667 Platform::current()->getURLLoaderMockFactory()->registerURL(
667 url, WebURLResponse(), ""); 668 url, WebURLResponse(), "");
668 Resource* newResource = RawResource::fetch(fetchRequest, fetcher); 669 Resource* newResource = RawResource::fetch(fetchRequest, fetcher);
669 fetcher->stopFetching(); 670 fetcher->stopFetching();
670 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 671 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
671 672
672 EXPECT_NE(resource, newResource); 673 EXPECT_NE(resource, newResource);
673 } 674 }
674 675
676 TEST_F(ResourceFetcherTest, CacheAwareFontLoading) {
677 KURL url(ParsedURLString, "http://127.0.0.1:8000/font.woff");
678 ResourceResponse response;
679 response.setURL(url);
680 response.setHTTPStatusCode(200);
681 Platform::current()->getURLLoaderMockFactory()->registerURL(
682 url, WrappedResourceResponse(response), "");
683
684 ResourceFetcher* fetcher = ResourceFetcher::create(
685 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
686
687 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
688 fetchRequest.setCacheAwareLoadingEnabled(IsCacheAwareLoadingEnabled);
689 FontResource* resource = FontResource::fetch(fetchRequest, fetcher);
690 ASSERT_TRUE(resource);
691
692 Persistent<MockFontResourceClient> client =
693 new MockFontResourceClient(resource);
694 fetcher->startLoad(resource);
695 EXPECT_TRUE(resource->loader()->isCacheAwareLoadingActivated());
696 resource->m_loadLimitState = FontResource::UnderLimit;
697
698 // FontResource callbacks should be blocked during cache-aware loading.
699 resource->fontLoadShortLimitCallback(nullptr);
700 EXPECT_FALSE(client->fontLoadShortLimitExceededCalled());
701
702 // Fail first request as disk cache miss.
703 resource->loader()->didFail(ResourceError::cacheMissError(url));
704
705 // Once cache miss error returns, previously blocked callbacks should be
706 // called immediately.
707 EXPECT_FALSE(resource->loader()->isCacheAwareLoadingActivated());
708 EXPECT_TRUE(client->fontLoadShortLimitExceededCalled());
709 EXPECT_FALSE(client->fontLoadLongLimitExceededCalled());
710
711 // Add client now, fontLoadShortLimitExceeded() should be called.
712 Persistent<MockFontResourceClient> client2 =
713 new MockFontResourceClient(resource);
714 EXPECT_TRUE(client2->fontLoadShortLimitExceededCalled());
715 EXPECT_FALSE(client2->fontLoadLongLimitExceededCalled());
716
717 // FontResource callbacks are not blocked now.
718 resource->fontLoadLongLimitCallback(nullptr);
719 EXPECT_TRUE(client->fontLoadLongLimitExceededCalled());
720
721 // Add client now, both callbacks should be called.
722 Persistent<MockFontResourceClient> client3 =
723 new MockFontResourceClient(resource);
724 EXPECT_TRUE(client3->fontLoadShortLimitExceededCalled());
725 EXPECT_TRUE(client3->fontLoadLongLimitExceededCalled());
726
727 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
728 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
729 memoryCache()->remove(resource);
730 }
731
675 } // namespace blink 732 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698