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

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: Removed the counter, since it was not accurate 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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 fetcher->preloadStarted(resource); 606 fetcher->preloadStarted(resource);
607 607
608 FetchRequest fetchRequestSecond = FetchRequest(url, FetchInitiatorInfo()); 608 FetchRequest fetchRequestSecond = FetchRequest(url, FetchInitiatorInfo());
609 fetchRequestSecond.setLinkPreload(true); 609 fetchRequestSecond.setLinkPreload(true);
610 Resource* secondResource = fetcher2->requestResource(fetchRequestSecond, Tes tResourceFactory(Resource::Image)); 610 Resource* secondResource = fetcher2->requestResource(fetchRequestSecond, Tes tResourceFactory(Resource::Image));
611 ASSERT_TRUE(secondResource); 611 ASSERT_TRUE(secondResource);
612 EXPECT_TRUE(secondResource->isLinkPreload()); 612 EXPECT_TRUE(secondResource->isLinkPreload());
613 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 613 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
614 fetcher2->preloadStarted(secondResource); 614 fetcher2->preloadStarted(secondResource);
615 615
616 // Link rel preload scanner
617 FetchRequest fetchRequestLinkPreloadScanner = FetchRequest(url, FetchInitiat orInfo());
618 fetchRequestLinkPreloadScanner.setLinkPreload(true);
619 Resource* linkPreloadScannerResource = fetcher->requestResource(fetchRequest LinkPreloadScanner, TestResourceFactory(Resource::Image));
620 EXPECT_EQ(resource, linkPreloadScannerResource);
621 EXPECT_TRUE(resource->isLinkPreload());
622 fetcher->preloadStarted(resource);
623
616 // Image preload scanner 624 // Image preload scanner
617 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn fo()); 625 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn fo());
618 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP reloadScanner, TestResourceFactory(Resource::Image)); 626 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP reloadScanner, TestResourceFactory(Resource::Image));
619 EXPECT_EQ(resource, imgPreloadScannerResource); 627 EXPECT_EQ(resource, imgPreloadScannerResource);
620 EXPECT_FALSE(resource->isLinkPreload()); 628 EXPECT_FALSE(resource->isLinkPreload());
621 fetcher->preloadStarted(resource); 629 fetcher->preloadStarted(resource);
622 630
631 // Image preload scanner on the second fetcher
632 FetchRequest fetchRequestPreloadScanner2 = FetchRequest(url, FetchInitiatorI nfo());
633 Resource* imgPreloadScannerResource2 = fetcher2->requestResource(fetchReques tPreloadScanner2, TestResourceFactory(Resource::Image));
634 EXPECT_EQ(resource, imgPreloadScannerResource2);
635 EXPECT_FALSE(resource->isLinkPreload());
636 fetcher2->preloadStarted(resource);
637
623 // Image created by parser 638 // Image created by parser
624 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 639 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
625 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image)); 640 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image));
626 Persistent<MockResourceClient> client = new MockResourceClient(newResource); 641 Persistent<MockResourceClient> client = new MockResourceClient(newResource);
627 EXPECT_EQ(resource, newResource); 642 EXPECT_EQ(resource, newResource);
628 EXPECT_FALSE(resource->isLinkPreload()); 643 EXPECT_FALSE(resource->isLinkPreload());
629 644
645 // Image created by parser on the second fetcher
646 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo());
647 Resource* newResource2 = fetcher2->requestResource(fetchRequest, TestResourc eFactory(Resource::Image));
648 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2 );
649 EXPECT_EQ(resource, newResource2);
650 EXPECT_FALSE(resource->isLinkPreload());
630 // DCL reached on first fetcher 651 // DCL reached on first fetcher
631 EXPECT_TRUE(resource->isPreloaded()); 652 EXPECT_TRUE(resource->isPreloaded());
632 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); 653 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads);
633 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 654 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
634 EXPECT_TRUE(memoryCache()->contains(resource)); 655 EXPECT_TRUE(memoryCache()->contains(resource));
635 EXPECT_TRUE(resource->isPreloaded()); 656 EXPECT_TRUE(resource->isPreloaded());
636 657
637 // DCL reached on second fetcher 658 // DCL reached on second fetcher
638 fetcher2->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); 659 fetcher2->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads);
639 EXPECT_TRUE(memoryCache()->contains(resource)); 660 EXPECT_TRUE(memoryCache()->contains(resource));
640 EXPECT_FALSE(resource->isPreloaded()); 661 EXPECT_FALSE(resource->isPreloaded());
641 } 662 }
642 663
643 } // namespace blink 664 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698