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

Side by Side Diff: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp

Issue 2795073003: Treat responses with LoFi headers as being LoFi images. (Closed)
Patch Set: addressed comments Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 500 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
501 EXPECT_EQ(2, observer->imageChangedCount()); 501 EXPECT_EQ(2, observer->imageChangedCount());
502 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 502 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
503 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 503 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
504 } 504 }
505 505
506 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { 506 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
507 KURL testURL(ParsedURLString, kTestURL); 507 KURL testURL(ParsedURLString, kTestURL);
508 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 508 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
509 ResourceRequest request = ResourceRequest(testURL); 509 ResourceRequest request = ResourceRequest(testURL);
510 request.setPreviewsState(WebURLRequest::ServerLoFiOn);
511 ImageResource* imageResource = ImageResource::create(request); 510 ImageResource* imageResource = ImageResource::create(request);
512 imageResource->setStatus(ResourceStatus::Pending); 511 imageResource->setStatus(ResourceStatus::Pending);
513 512
514 std::unique_ptr<MockImageResourceObserver> observer = 513 std::unique_ptr<MockImageResourceObserver> observer =
515 MockImageResourceObserver::create(imageResource->getContent()); 514 MockImageResourceObserver::create(imageResource->getContent());
516 ResourceFetcher* fetcher = createFetcher(); 515 ResourceFetcher* fetcher = createFetcher();
517 516
518 // Send the image response. 517 // Send the image response.
519 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), 518 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage),
520 nullAtom); 519 nullAtom);
(...skipping 20 matching lines...) Expand all
541 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. 540 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading.
542 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, 541 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher,
543 Resource::kReloadAlways); 542 Resource::kReloadAlways);
544 543
545 EXPECT_EQ(3, observer->imageChangedCount()); 544 EXPECT_EQ(3, observer->imageChangedCount());
546 testThatReloadIsStartedThenServeReload( 545 testThatReloadIsStartedThenServeReload(
547 testURL, imageResource, imageResource->getContent(), observer.get(), 546 testURL, imageResource, imageResource->getContent(), observer.get(),
548 WebCachePolicy::BypassingCache); 547 WebCachePolicy::BypassingCache);
549 } 548 }
550 549
550 TEST(ImageResourceTest,
551 ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) {
552 KURL testURL(ParsedURLString, kTestURL);
553 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
554 ResourceRequest request = ResourceRequest(testURL);
555 request.setPreviewsState(WebURLRequest::ServerLoFiOn);
556 ImageResource* imageResource = ImageResource::create(request);
557 imageResource->setStatus(ResourceStatus::Pending);
558
559 std::unique_ptr<MockImageResourceObserver> observer =
560 MockImageResourceObserver::create(imageResource->getContent());
561 ResourceFetcher* fetcher = createFetcher();
562
563 // Send the image response, without any LoFi image response headers.
564 imageResource->responseReceived(
565 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom),
566 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 // The image should not have been reloaded, since it didn't have the LoFi
588 // image response headers.
589 EXPECT_EQ(2, observer->imageChangedCount());
590 EXPECT_TRUE(imageResource->isLoaded());
591 }
592
551 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) { 593 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) {
552 ResourceFetcher* fetcher = createFetcher(); 594 ResourceFetcher* fetcher = createFetcher();
553 595
554 KURL testURL(ParsedURLString, kTestURL); 596 KURL testURL(ParsedURLString, kTestURL);
555 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 597 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
556 598
557 ResourceRequest request = ResourceRequest(testURL); 599 ResourceRequest request = ResourceRequest(testURL);
558 request.setPreviewsState(WebURLRequest::ServerLoFiOn); 600 request.setPreviewsState(WebURLRequest::ServerLoFiOn);
559 FetchRequest fetchRequest(request, FetchInitiatorInfo()); 601 FetchRequest fetchRequest(request, FetchInitiatorInfo());
560 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); 602 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 ResourceRequest request(testURL); 639 ResourceRequest request(testURL);
598 request.setPreviewsState(WebURLRequest::ServerLoFiOn); 640 request.setPreviewsState(WebURLRequest::ServerLoFiOn);
599 FetchRequest fetchRequest(request, FetchInitiatorInfo()); 641 FetchRequest fetchRequest(request, FetchInitiatorInfo());
600 ResourceFetcher* fetcher = createFetcher(); 642 ResourceFetcher* fetcher = createFetcher();
601 643
602 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); 644 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher);
603 std::unique_ptr<MockImageResourceObserver> observer = 645 std::unique_ptr<MockImageResourceObserver> observer =
604 MockImageResourceObserver::create(imageResource->getContent()); 646 MockImageResourceObserver::create(imageResource->getContent());
605 647
606 // Send the image response. 648 // Send the image response.
607 ResourceResponse initialResourceResponse(testURL, "image/jpeg", 649 imageResource->loader()->didReceiveResponse(WrappedResourceResponse(
608 sizeof(kJpegImage), nullAtom); 650 ResourceResponse(testURL, "image/jpeg", sizeof(kJpegImage), nullAtom)));
609 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
610
611 imageResource->loader()->didReceiveResponse(
612 WrappedResourceResponse(initialResourceResponse));
613 imageResource->loader()->didReceiveData( 651 imageResource->loader()->didReceiveData(
614 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); 652 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
615 653
616 EXPECT_FALSE(imageResource->errorOccurred()); 654 EXPECT_FALSE(imageResource->errorOccurred());
617 ASSERT_TRUE(imageResource->getContent()->hasImage()); 655 ASSERT_TRUE(imageResource->getContent()->hasImage());
618 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 656 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
619 EXPECT_EQ(1, observer->imageChangedCount()); 657 EXPECT_EQ(1, observer->imageChangedCount());
620 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); 658 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
621 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); 659 EXPECT_FALSE(observer->imageNotifyFinishedCalled());
622 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 660 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 1541 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1504 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 1542 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
1505 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); 1543 EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
1506 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); 1544 EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
1507 1545
1508 WTF::setTimeFunctionsForTesting(nullptr); 1546 WTF::setTimeFunctionsForTesting(nullptr);
1509 } 1547 }
1510 1548
1511 } // namespace 1549 } // namespace
1512 } // namespace blink 1550 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698