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

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

Issue 2343623002: Add a warning whenever link preloads are not used (Closed)
Patch Set: Added failing unit tests Created 4 years, 3 months 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 response.setHTTPStatusCode(200); 597 response.setHTTPStatusCode(200);
598 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena me, WebString::fromUTF8(""), WrappedResourceResponse(response)); 598 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena me, WebString::fromUTF8(""), WrappedResourceResponse(response));
599 599
600 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); 600 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo());
601 fetchRequestOriginal.setLinkPreload(true); 601 fetchRequestOriginal.setLinkPreload(true);
602 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso urceFactory(Resource::Image)); 602 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso urceFactory(Resource::Image));
603 ASSERT_TRUE(resource); 603 ASSERT_TRUE(resource);
604 EXPECT_TRUE(resource->isLinkPreload()); 604 EXPECT_TRUE(resource->isLinkPreload());
605 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 605 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
606 fetcher->preloadStarted(resource); 606 fetcher->preloadStarted(resource);
607 EXPECT_TRUE(fetcher->hasUnusedLinkPreloads());
607 608
608 FetchRequest fetchRequestSecond = FetchRequest(url, FetchInitiatorInfo()); 609 FetchRequest fetchRequestSecond = FetchRequest(url, FetchInitiatorInfo());
609 fetchRequestSecond.setLinkPreload(true); 610 fetchRequestSecond.setLinkPreload(true);
610 Resource* secondResource = fetcher2->requestResource(fetchRequestSecond, Tes tResourceFactory(Resource::Image)); 611 Resource* secondResource = fetcher2->requestResource(fetchRequestSecond, Tes tResourceFactory(Resource::Image));
611 ASSERT_TRUE(secondResource); 612 ASSERT_TRUE(secondResource);
612 EXPECT_TRUE(secondResource->isLinkPreload()); 613 EXPECT_TRUE(secondResource->isLinkPreload());
613 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 614 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
614 fetcher2->preloadStarted(secondResource); 615 fetcher2->preloadStarted(secondResource);
616 EXPECT_TRUE(fetcher2->hasUnusedLinkPreloads());
617
618 // Link rel preload scanner
619 FetchRequest fetchRequestLinkPreloadScanner = FetchRequest(url, FetchInitiat orInfo());
620 fetchRequestLinkPreloadScanner.setLinkPreload(true);
621 Resource* linkPreloadScannerResource = fetcher->requestResource(fetchRequest LinkPreloadScanner, TestResourceFactory(Resource::Image));
622 EXPECT_EQ(resource, linkPreloadScannerResource);
623 EXPECT_TRUE(resource->isLinkPreload());
624 fetcher->preloadStarted(resource);
625 EXPECT_TRUE(fetcher->hasUnusedLinkPreloads());
626 EXPECT_TRUE(fetcher2->hasUnusedLinkPreloads());
615 627
616 // Image preload scanner 628 // Image preload scanner
617 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn fo()); 629 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn fo());
618 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP reloadScanner, TestResourceFactory(Resource::Image)); 630 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP reloadScanner, TestResourceFactory(Resource::Image));
619 EXPECT_EQ(resource, imgPreloadScannerResource); 631 EXPECT_EQ(resource, imgPreloadScannerResource);
620 EXPECT_FALSE(resource->isLinkPreload()); 632 EXPECT_FALSE(resource->isLinkPreload());
621 fetcher->preloadStarted(resource); 633 fetcher->preloadStarted(resource);
634 EXPECT_FALSE(fetcher->hasUnusedLinkPreloads());
635 EXPECT_TRUE(fetcher2->hasUnusedLinkPreloads());
636
637 // Image preload scanner on the second fetcher
638 FetchRequest fetchRequestPreloadScanner2 = FetchRequest(url, FetchInitiatorI nfo());
639 Resource* imgPreloadScannerResource2 = fetcher2->requestResource(fetchReques tPreloadScanner2, TestResourceFactory(Resource::Image));
640 EXPECT_EQ(resource, imgPreloadScannerResource2);
641 EXPECT_FALSE(resource->isLinkPreload());
642 fetcher2->preloadStarted(resource);
643 EXPECT_FALSE(fetcher->hasUnusedLinkPreloads());
644 EXPECT_TRUE(fetcher2->hasUnusedLinkPreloads());
622 645
623 // Image created by parser 646 // Image created by parser
624 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 647 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
625 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image)); 648 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image));
626 Persistent<MockResourceClient> client = new MockResourceClient(newResource); 649 Persistent<MockResourceClient> client = new MockResourceClient(newResource);
627 EXPECT_EQ(resource, newResource); 650 EXPECT_EQ(resource, newResource);
628 EXPECT_FALSE(resource->isLinkPreload()); 651 EXPECT_FALSE(resource->isLinkPreload());
652 EXPECT_FALSE(fetcher->hasUnusedLinkPreloads());
653 EXPECT_TRUE(fetcher2->hasUnusedLinkPreloads());
629 654
655 // Image created by parser on the second fetcher
656 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo());
657 Resource* newResource2 = fetcher2->requestResource(fetchRequest, TestResourc eFactory(Resource::Image));
658 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2 );
659 EXPECT_EQ(resource, newResource2);
660 EXPECT_FALSE(resource->isLinkPreload());
661 EXPECT_FALSE(fetcher->hasUnusedLinkPreloads());
662 EXPECT_FALSE(fetcher2->hasUnusedLinkPreloads());
Yoav Weiss 2016/09/19 10:57:41 This fails because the resource->isLinkPreload() i
Charlie Harrison 2016/09/19 14:06:45 Yeah you're right. Good thing this test showed tha
630 // DCL reached on first fetcher 663 // DCL reached on first fetcher
631 EXPECT_TRUE(resource->isPreloaded()); 664 EXPECT_TRUE(resource->isPreloaded());
632 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); 665 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads);
633 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 666 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
634 EXPECT_TRUE(memoryCache()->contains(resource)); 667 EXPECT_TRUE(memoryCache()->contains(resource));
635 EXPECT_TRUE(resource->isPreloaded()); 668 EXPECT_TRUE(resource->isPreloaded());
636 669
637 // DCL reached on second fetcher 670 // DCL reached on second fetcher
638 fetcher2->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); 671 fetcher2->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads);
639 EXPECT_TRUE(memoryCache()->contains(resource)); 672 EXPECT_TRUE(memoryCache()->contains(resource));
640 EXPECT_FALSE(resource->isPreloaded()); 673 EXPECT_FALSE(resource->isPreloaded());
641 } 674 }
642 675
643 } // namespace blink 676 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp ('k') | third_party/WebKit/Source/core/frame/LocalDOMWindow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698