| 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. | 540 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. |
| 541 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, | 541 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, |
| 542 Resource::kReloadAlways); | 542 Resource::kReloadAlways); |
| 543 | 543 |
| 544 EXPECT_EQ(3, observer->imageChangedCount()); | 544 EXPECT_EQ(3, observer->imageChangedCount()); |
| 545 testThatReloadIsStartedThenServeReload( | 545 testThatReloadIsStartedThenServeReload( |
| 546 testURL, imageResource, imageResource->getContent(), observer.get(), | 546 testURL, imageResource, imageResource->getContent(), observer.get(), |
| 547 WebCachePolicy::BypassingCache); | 547 WebCachePolicy::BypassingCache); |
| 548 } | 548 } |
| 549 | 549 |
| 550 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinishedWithOldHeaders) { |
| 551 KURL testURL(ParsedURLString, kTestURL); |
| 552 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 553 ResourceRequest request = ResourceRequest(testURL); |
| 554 ImageResource* imageResource = ImageResource::create(request); |
| 555 imageResource->setStatus(ResourceStatus::Pending); |
| 556 |
| 557 std::unique_ptr<MockImageResourceObserver> observer = |
| 558 MockImageResourceObserver::create(imageResource->getContent()); |
| 559 ResourceFetcher* fetcher = createFetcher(); |
| 560 |
| 561 // Send the image response. |
| 562 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), |
| 563 nullAtom); |
| 564 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 565 |
| 566 imageResource->responseReceived(resourceResponse, nullptr); |
| 567 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), |
| 568 sizeof(kJpegImage)); |
| 569 imageResource->finish(); |
| 570 EXPECT_FALSE(imageResource->errorOccurred()); |
| 571 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 572 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 573 EXPECT_EQ(2, observer->imageChangedCount()); |
| 574 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); |
| 575 // The observer should have been notified that the image load completed. |
| 576 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 577 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 578 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 579 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width()); |
| 580 EXPECT_EQ(kJpegImageHeight, |
| 581 imageResource->getContent()->getImage()->height()); |
| 582 |
| 583 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. |
| 584 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, |
| 585 Resource::kReloadAlways); |
| 586 |
| 587 EXPECT_EQ(3, observer->imageChangedCount()); |
| 588 testThatReloadIsStartedThenServeReload( |
| 589 testURL, imageResource, imageResource->getContent(), observer.get(), |
| 590 WebCachePolicy::BypassingCache); |
| 591 } |
| 592 |
| 550 TEST(ImageResourceTest, | 593 TEST(ImageResourceTest, |
| 551 ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) { | 594 ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) { |
| 552 KURL testURL(ParsedURLString, kTestURL); | 595 KURL testURL(ParsedURLString, kTestURL); |
| 553 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 596 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 554 ResourceRequest request = ResourceRequest(testURL); | 597 ResourceRequest request = ResourceRequest(testURL); |
| 555 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 598 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 556 ImageResource* imageResource = ImageResource::create(request); | 599 ImageResource* imageResource = ImageResource::create(request); |
| 557 imageResource->setStatus(ResourceStatus::Pending); | 600 imageResource->setStatus(ResourceStatus::Pending); |
| 558 | 601 |
| 559 std::unique_ptr<MockImageResourceObserver> observer = | 602 std::unique_ptr<MockImageResourceObserver> observer = |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1584 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1542 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1585 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1543 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1586 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1544 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1587 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1545 | 1588 |
| 1546 WTF::setTimeFunctionsForTesting(nullptr); | 1589 WTF::setTimeFunctionsForTesting(nullptr); |
| 1547 } | 1590 } |
| 1548 | 1591 |
| 1549 } // namespace | 1592 } // namespace |
| 1550 } // namespace blink | 1593 } // namespace blink |
| OLD | NEW |