Chromium Code Reviews| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. | 541 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. |
| 542 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, | 542 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, |
| 543 Resource::kReloadAlways); | 543 Resource::kReloadAlways); |
| 544 | 544 |
| 545 EXPECT_EQ(3, observer->imageChangedCount()); | 545 EXPECT_EQ(3, observer->imageChangedCount()); |
| 546 testThatReloadIsStartedThenServeReload( | 546 testThatReloadIsStartedThenServeReload( |
| 547 testURL, imageResource, imageResource->getContent(), observer.get(), | 547 testURL, imageResource, imageResource->getContent(), observer.get(), |
| 548 WebCachePolicy::BypassingCache); | 548 WebCachePolicy::BypassingCache); |
| 549 } | 549 } |
| 550 | 550 |
| 551 TEST(ImageResourceTest, | |
| 552 ReloadIfLoFiOrPlaceholderAfterFinishedWithoutServerLoFiOnBit) { | |
|
megjablon
2017/04/04 00:52:06
Do we need this and the above test? Since the prev
sclittle
2017/04/04 03:12:16
Done.
| |
| 553 KURL testURL(ParsedURLString, kTestURL); | |
| 554 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | |
| 555 ResourceRequest request = ResourceRequest(testURL); | |
| 556 request.setPreviewsState(WebURLRequest::PreviewsUnspecified); | |
| 557 ImageResource* imageResource = ImageResource::create(request); | |
| 558 imageResource->setStatus(ResourceStatus::Pending); | |
| 559 | |
| 560 std::unique_ptr<MockImageResourceObserver> observer = | |
| 561 MockImageResourceObserver::create(imageResource->getContent()); | |
| 562 ResourceFetcher* fetcher = createFetcher(); | |
| 563 | |
| 564 // Send the image response. | |
| 565 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), | |
| 566 nullAtom); | |
| 567 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", | |
| 568 "empty-image"); | |
| 569 | |
| 570 imageResource->responseReceived(resourceResponse, nullptr); | |
| 571 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), | |
| 572 sizeof(kJpegImage)); | |
| 573 imageResource->finish(); | |
| 574 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 575 ASSERT_TRUE(imageResource->getContent()->hasImage()); | |
| 576 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | |
| 577 EXPECT_EQ(2, observer->imageChangedCount()); | |
| 578 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | |
| 579 // The observer should have been notified that the image load completed. | |
| 580 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | |
| 581 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | |
| 582 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | |
| 583 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width()); | |
| 584 EXPECT_EQ(kJpegImageHeight, | |
| 585 imageResource->getContent()->getImage()->height()); | |
| 586 | |
| 587 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. | |
| 588 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, | |
| 589 Resource::kReloadAlways); | |
| 590 | |
| 591 EXPECT_EQ(3, observer->imageChangedCount()); | |
| 592 testThatReloadIsStartedThenServeReload( | |
| 593 testURL, imageResource, imageResource->getContent(), observer.get(), | |
| 594 WebCachePolicy::BypassingCache); | |
| 595 } | |
| 596 | |
| 597 TEST(ImageResourceTest, | |
| 598 ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) { | |
| 599 KURL testURL(ParsedURLString, kTestURL); | |
| 600 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | |
| 601 ResourceRequest request = ResourceRequest(testURL); | |
| 602 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | |
| 603 ImageResource* imageResource = ImageResource::create(request); | |
| 604 imageResource->setStatus(ResourceStatus::Pending); | |
| 605 | |
| 606 std::unique_ptr<MockImageResourceObserver> observer = | |
| 607 MockImageResourceObserver::create(imageResource->getContent()); | |
| 608 ResourceFetcher* fetcher = createFetcher(); | |
| 609 | |
| 610 // Send the image response, without any LoFi image response headers. | |
| 611 imageResource->responseReceived( | |
| 612 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom), | |
| 613 nullptr); | |
| 614 imageResource->appendData(reinterpret_cast<const char*>(kJpegImage), | |
| 615 sizeof(kJpegImage)); | |
| 616 imageResource->finish(); | |
| 617 EXPECT_FALSE(imageResource->errorOccurred()); | |
| 618 ASSERT_TRUE(imageResource->getContent()->hasImage()); | |
| 619 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | |
| 620 EXPECT_EQ(2, observer->imageChangedCount()); | |
| 621 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); | |
| 622 // The observer should have been notified that the image load completed. | |
| 623 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | |
| 624 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | |
| 625 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | |
| 626 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width()); | |
| 627 EXPECT_EQ(kJpegImageHeight, | |
| 628 imageResource->getContent()->getImage()->height()); | |
| 629 | |
| 630 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. | |
| 631 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, | |
| 632 Resource::kReloadAlways); | |
| 633 | |
| 634 // The image should not have been reloaded, since it didn't have the LoFi | |
| 635 // image response headers. | |
| 636 EXPECT_EQ(2, observer->imageChangedCount()); | |
| 637 EXPECT_TRUE(imageResource->isLoaded()); | |
| 638 } | |
| 639 | |
| 551 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) { | 640 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) { |
| 552 ResourceFetcher* fetcher = createFetcher(); | 641 ResourceFetcher* fetcher = createFetcher(); |
| 553 | 642 |
| 554 KURL testURL(ParsedURLString, kTestURL); | 643 KURL testURL(ParsedURLString, kTestURL); |
| 555 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); | 644 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 556 | 645 |
| 557 ResourceRequest request = ResourceRequest(testURL); | 646 ResourceRequest request = ResourceRequest(testURL); |
| 558 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 647 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 559 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 648 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
| 560 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); | 649 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 688 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
| 600 ResourceFetcher* fetcher = createFetcher(); | 689 ResourceFetcher* fetcher = createFetcher(); |
| 601 | 690 |
| 602 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); | 691 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); |
| 603 std::unique_ptr<MockImageResourceObserver> observer = | 692 std::unique_ptr<MockImageResourceObserver> observer = |
| 604 MockImageResourceObserver::create(imageResource->getContent()); | 693 MockImageResourceObserver::create(imageResource->getContent()); |
| 605 | 694 |
| 606 // Send the image response. | 695 // Send the image response. |
| 607 ResourceResponse initialResourceResponse(testURL, "image/jpeg", | 696 ResourceResponse initialResourceResponse(testURL, "image/jpeg", |
| 608 sizeof(kJpegImage), nullAtom); | 697 sizeof(kJpegImage), nullAtom); |
| 609 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 698 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
|
megjablon
2017/04/04 00:52:06
This is an old test, but I was checking our covera
sclittle
2017/04/04 03:12:16
Done.
| |
| 610 | 699 |
| 611 imageResource->loader()->didReceiveResponse( | 700 imageResource->loader()->didReceiveResponse( |
| 612 WrappedResourceResponse(initialResourceResponse)); | 701 WrappedResourceResponse(initialResourceResponse)); |
| 613 imageResource->loader()->didReceiveData( | 702 imageResource->loader()->didReceiveData( |
| 614 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); | 703 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); |
| 615 | 704 |
| 616 EXPECT_FALSE(imageResource->errorOccurred()); | 705 EXPECT_FALSE(imageResource->errorOccurred()); |
| 617 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 706 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 618 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 707 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 619 EXPECT_EQ(1, observer->imageChangedCount()); | 708 EXPECT_EQ(1, observer->imageChangedCount()); |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1503 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1592 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1504 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1593 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1505 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1594 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1506 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1595 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1507 | 1596 |
| 1508 WTF::setTimeFunctionsForTesting(nullptr); | 1597 WTF::setTimeFunctionsForTesting(nullptr); |
| 1509 } | 1598 } |
| 1510 | 1599 |
| 1511 } // namespace | 1600 } // namespace |
| 1512 } // namespace blink | 1601 } // namespace blink |
| OLD | NEW |