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

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

Issue 2501543002: Loading: move FontResource to core/loader/resource (Closed)
Patch Set: 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/fetch/ResourceFetcher.h" 31 #include "core/fetch/ResourceFetcher.h"
32 32
33 #include "core/fetch/FetchInitiatorInfo.h" 33 #include "core/fetch/FetchInitiatorInfo.h"
34 #include "core/fetch/FetchInitiatorTypeNames.h" 34 #include "core/fetch/FetchInitiatorTypeNames.h"
35 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
36 #include "core/fetch/FontResource.h"
37 #include "core/fetch/ImageResource.h" 36 #include "core/fetch/ImageResource.h"
38 #include "core/fetch/MemoryCache.h" 37 #include "core/fetch/MemoryCache.h"
39 #include "core/fetch/MockResourceClients.h" 38 #include "core/fetch/MockResourceClients.h"
40 #include "core/fetch/RawResource.h" 39 #include "core/fetch/RawResource.h"
41 #include "core/fetch/ResourceLoader.h" 40 #include "core/fetch/ResourceLoader.h"
42 #include "platform/WebTaskRunner.h" 41 #include "platform/WebTaskRunner.h"
43 #include "platform/exported/WrappedResourceResponse.h" 42 #include "platform/exported/WrappedResourceResponse.h"
44 #include "platform/heap/Handle.h" 43 #include "platform/heap/Handle.h"
45 #include "platform/heap/HeapAllocator.h" 44 #include "platform/heap/HeapAllocator.h"
46 #include "platform/heap/Member.h" 45 #include "platform/heap/Member.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 Persistent<RequestSameResourceOnComplete> client = 297 Persistent<RequestSameResourceOnComplete> client =
299 new RequestSameResourceOnComplete(resource1); 298 new RequestSameResourceOnComplete(resource1);
300 resource1->addClient(client); 299 resource1->addClient(client);
301 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 300 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
302 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 301 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
303 EXPECT_TRUE(client->notifyFinishedCalled()); 302 EXPECT_TRUE(client->notifyFinishedCalled());
304 resource1->removeClient(client); 303 resource1->removeClient(client);
305 memoryCache()->remove(resource1); 304 memoryCache()->remove(resource1);
306 } 305 }
307 306
308 TEST_F(ResourceFetcherTest, RevalidateDeferedResourceFromTwoInitiators) {
309 KURL url(ParsedURLString, "http://127.0.0.1:8000/font.woff");
310 ResourceResponse response;
311 response.setURL(url);
312 response.setHTTPStatusCode(200);
313 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890");
314 Platform::current()->getURLLoaderMockFactory()->registerURL(
315 url, WrappedResourceResponse(response), "");
316
317 ResourceFetcherTestMockFetchContext* context =
318 ResourceFetcherTestMockFetchContext::create();
319 ResourceFetcher* fetcher = ResourceFetcher::create(context);
320
321 // Fetch to cache a resource.
322 ResourceRequest request1(url);
323 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo());
324 Resource* resource1 = FontResource::fetch(fetchRequest1, fetcher);
325 ASSERT_TRUE(resource1);
326 fetcher->startLoad(resource1);
327 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
328 EXPECT_TRUE(resource1->isLoaded());
329 EXPECT_FALSE(resource1->errorOccurred());
330
331 // Set the context as it is on reloads.
332 context->setLoadComplete(true);
333 context->setCachePolicy(CachePolicyRevalidate);
334
335 // Revalidate the resource.
336 ResourceRequest request2(url);
337 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo());
338 Resource* resource2 = FontResource::fetch(fetchRequest2, fetcher);
339 ASSERT_TRUE(resource2);
340 EXPECT_EQ(resource1, resource2);
341 EXPECT_TRUE(resource2->isCacheValidator());
342 EXPECT_TRUE(resource2->stillNeedsLoad());
343
344 // Fetch the same resource again before actual load operation starts.
345 ResourceRequest request3(url);
346 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo());
347 Resource* resource3 = FontResource::fetch(fetchRequest3, fetcher);
348 ASSERT_TRUE(resource3);
349 EXPECT_EQ(resource2, resource3);
350 EXPECT_TRUE(resource3->isCacheValidator());
351 EXPECT_TRUE(resource3->stillNeedsLoad());
352
353 // startLoad() can be called from any initiator. Here, call it from the
354 // latter.
355 fetcher->startLoad(resource3);
356 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
357 EXPECT_TRUE(resource3->isLoaded());
358 EXPECT_FALSE(resource3->errorOccurred());
359 EXPECT_TRUE(resource2->isLoaded());
360 EXPECT_FALSE(resource2->errorOccurred());
361
362 memoryCache()->remove(resource1);
363 }
364
365 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) { 307 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) {
366 ResourceFetcher* fetcher = 308 ResourceFetcher* fetcher =
367 ResourceFetcher::create(ResourceFetcherTestMockFetchContext::create()); 309 ResourceFetcher::create(ResourceFetcherTestMockFetchContext::create());
368 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); 310 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo"));
369 request.setRequestContext(WebURLRequest::RequestContextVideo); 311 request.setRequestContext(WebURLRequest::RequestContextVideo);
370 ResourceLoaderOptions options; 312 ResourceLoaderOptions options;
371 options.dataBufferingPolicy = DoNotBufferData; 313 options.dataBufferingPolicy = DoNotBufferData;
372 FetchRequest fetchRequest = 314 FetchRequest fetchRequest =
373 FetchRequest(request, FetchInitiatorTypeNames::internal, options); 315 FetchRequest(request, FetchInitiatorTypeNames::internal, options);
374 Resource* resource1 = RawResource::fetchMedia(fetchRequest, fetcher); 316 Resource* resource1 = RawResource::fetchMedia(fetchRequest, fetcher);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 Platform::current()->getURLLoaderMockFactory()->registerURL( 652 Platform::current()->getURLLoaderMockFactory()->registerURL(
711 url, WebURLResponse(), ""); 653 url, WebURLResponse(), "");
712 Resource* newResource = RawResource::fetch(fetchRequest, fetcher); 654 Resource* newResource = RawResource::fetch(fetchRequest, fetcher);
713 fetcher->stopFetching(); 655 fetcher->stopFetching();
714 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 656 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
715 657
716 EXPECT_NE(resource, newResource); 658 EXPECT_NE(resource, newResource);
717 } 659 }
718 660
719 } // namespace blink 661 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698