OLD | NEW |
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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 response.setHTTPStatusCode(200); | 506 response.setHTTPStatusCode(200); |
507 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); | 507 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
508 | 508 |
509 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); | 509 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
510 FetchRequest request(url, FetchInitiatorInfo()); | 510 FetchRequest request(url, FetchInitiatorInfo()); |
511 request.makeSynchronous(); | 511 request.makeSynchronous(); |
512 Resource* resource = fetcher->requestResource(request, TestResourceFactory()
); | 512 Resource* resource = fetcher->requestResource(request, TestResourceFactory()
); |
513 EXPECT_TRUE(resource->isLoaded()); | 513 EXPECT_TRUE(resource->isLoaded()); |
514 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority(
)); | 514 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority(
)); |
515 | 515 |
| 516 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
516 memoryCache()->remove(resource); | 517 memoryCache()->remove(resource); |
517 } | 518 } |
518 | 519 |
| 520 TEST_F(ResourceFetcherTest, PreloadImageTwice) |
| 521 { |
| 522 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 523 |
| 524 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 525 ResourceResponse response; |
| 526 response.setURL(url); |
| 527 response.setHTTPStatusCode(200); |
| 528 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 529 |
| 530 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 531 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso
urceFactory(Resource::Image)); |
| 532 ASSERT_TRUE(resource); |
| 533 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 534 fetcher->preloadStarted(resource); |
| 535 |
| 536 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 537 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 538 EXPECT_EQ(resource, newResource); |
| 539 fetcher->preloadStarted(resource); |
| 540 |
| 541 fetcher->clearPreloads(ResourceFetcher::ClearAllPreloads); |
| 542 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 543 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 544 EXPECT_FALSE(resource->isPreloaded()); |
| 545 } |
| 546 |
| 547 |
| 548 TEST_F(ResourceFetcherTest, LinkPreloadImageAndUse) |
| 549 { |
| 550 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 551 |
| 552 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 553 ResourceResponse response; |
| 554 response.setURL(url); |
| 555 response.setHTTPStatusCode(200); |
| 556 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 557 |
| 558 // Link preload preload scanner |
| 559 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 560 fetchRequestOriginal.setLinkPreload(true); |
| 561 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso
urceFactory(Resource::Image)); |
| 562 ASSERT_TRUE(resource); |
| 563 EXPECT_TRUE(resource->isLinkPreload()); |
| 564 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 565 fetcher->preloadStarted(resource); |
| 566 |
| 567 // Image preload scanner |
| 568 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn
fo()); |
| 569 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP
reloadScanner, TestResourceFactory(Resource::Image)); |
| 570 EXPECT_EQ(resource, imgPreloadScannerResource); |
| 571 EXPECT_FALSE(resource->isLinkPreload()); |
| 572 fetcher->preloadStarted(resource); |
| 573 |
| 574 // Image created by parser |
| 575 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 576 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 577 EXPECT_EQ(resource, newResource); |
| 578 EXPECT_FALSE(resource->isLinkPreload()); |
| 579 |
| 580 // DCL reached |
| 581 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); |
| 582 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 583 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 584 EXPECT_FALSE(resource->isPreloaded()); |
| 585 } |
| 586 |
| 587 TEST_F(ResourceFetcherTest, LinkPreloadImageMultipleFetchersAndUse) |
| 588 { |
| 589 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 590 ResourceFetcher* fetcher2 = ResourceFetcher::create(ResourceFetcherTestMockF
etchContext::create()); |
| 591 |
| 592 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 593 ResourceResponse response; |
| 594 response.setURL(url); |
| 595 response.setHTTPStatusCode(200); |
| 596 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 597 |
| 598 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 599 fetchRequestOriginal.setLinkPreload(true); |
| 600 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso
urceFactory(Resource::Image)); |
| 601 ASSERT_TRUE(resource); |
| 602 EXPECT_TRUE(resource->isLinkPreload()); |
| 603 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 604 fetcher->preloadStarted(resource); |
| 605 |
| 606 FetchRequest fetchRequestSecond = FetchRequest(url, FetchInitiatorInfo()); |
| 607 fetchRequestSecond.setLinkPreload(true); |
| 608 Resource* secondResource = fetcher2->requestResource(fetchRequestSecond, Tes
tResourceFactory(Resource::Image)); |
| 609 ASSERT_TRUE(secondResource); |
| 610 EXPECT_TRUE(secondResource->isLinkPreload()); |
| 611 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 612 fetcher->preloadStarted(secondResource); |
| 613 |
| 614 // Image preload scanner |
| 615 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn
fo()); |
| 616 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP
reloadScanner, TestResourceFactory(Resource::Image)); |
| 617 EXPECT_EQ(resource, imgPreloadScannerResource); |
| 618 EXPECT_FALSE(resource->isLinkPreload()); |
| 619 fetcher->preloadStarted(resource); |
| 620 |
| 621 // Image created by parser |
| 622 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 623 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 624 EXPECT_EQ(resource, newResource); |
| 625 EXPECT_FALSE(resource->isLinkPreload()); |
| 626 |
| 627 // DCL reached on first fetcher |
| 628 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); |
| 629 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 630 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 631 EXPECT_FALSE(resource->isPreloaded()); |
| 632 |
| 633 // DCL reached on second fetcher |
| 634 fetcher2->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); |
| 635 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 636 EXPECT_FALSE(resource->isPreloaded()); |
| 637 } |
| 638 |
519 } // namespace blink | 639 } // namespace blink |
OLD | NEW |