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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 memoryCache()->remove(resource); | 516 memoryCache()->remove(resource); |
517 } | 517 } |
518 | 518 |
| 519 TEST_F(ResourceFetcherTest, PreloadImageTwice) |
| 520 { |
| 521 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 522 |
| 523 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 524 ResourceResponse response; |
| 525 response.setURL(url); |
| 526 response.setHTTPStatusCode(200); |
| 527 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 528 |
| 529 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 530 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso
urceFactory(Resource::Image)); |
| 531 ASSERT_TRUE(resource); |
| 532 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 533 fetcher->preloadStarted(resource); |
| 534 |
| 535 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 536 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 537 EXPECT_EQ(resource, newResource); |
| 538 fetcher->preloadStarted(resource); |
| 539 |
| 540 fetcher->clearPreloads(ResourceFetcher::ClearAllPreloads); |
| 541 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 542 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 543 EXPECT_FALSE(resource->isPreloaded()); |
| 544 } |
| 545 |
| 546 |
| 547 TEST_F(ResourceFetcherTest, LinkPreloadImageAndUse) |
| 548 { |
| 549 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 550 |
| 551 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 552 ResourceResponse response; |
| 553 response.setURL(url); |
| 554 response.setHTTPStatusCode(200); |
| 555 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena
me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 556 |
| 557 // Link preload preload scanner |
| 558 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 559 fetchRequestOriginal.setLinkPreload(true); |
| 560 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso
urceFactory(Resource::Image)); |
| 561 ASSERT_TRUE(resource); |
| 562 EXPECT_TRUE(resource->isLinkPreload()); |
| 563 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 564 fetcher->preloadStarted(resource); |
| 565 |
| 566 // Image preload scanner |
| 567 FetchRequest fetchRequestPreloadScanner = FetchRequest(url, FetchInitiatorIn
fo()); |
| 568 Resource* imgPreloadScannerResource = fetcher->requestResource(fetchRequestP
reloadScanner, TestResourceFactory(Resource::Image)); |
| 569 EXPECT_EQ(resource, imgPreloadScannerResource); |
| 570 EXPECT_FALSE(resource->isLinkPreload()); |
| 571 fetcher->preloadStarted(resource); |
| 572 |
| 573 // Image created by parser |
| 574 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 575 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 576 EXPECT_EQ(resource, newResource); |
| 577 EXPECT_FALSE(resource->isLinkPreload()); |
| 578 |
| 579 // DCL reached |
| 580 fetcher->clearPreloads(ResourceFetcher::ClearSpeculativeMarkupPreloads); |
| 581 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 582 EXPECT_FALSE(memoryCache()->contains(resource)); |
| 583 EXPECT_FALSE(resource->isPreloaded()); |
| 584 } |
519 } // namespace blink | 585 } // namespace blink |
OLD | NEW |