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

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

Issue 2607023002: Replace MockImageResourceClient with MockImageResourceObserver (Closed)
Patch Set: Rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
index d909bf257a34e59f663b311ad73c3232714cf42c..32ff4d324d03dd3bff21ce6a55357a8662c312ae 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -37,7 +37,7 @@
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourceLoader.h"
#include "core/fetch/UniqueIdentifier.h"
-#include "core/loader/resource/MockImageResourceClient.h"
+#include "core/loader/resource/MockImageResourceObserver.h"
#include "platform/SharedBuffer.h"
#include "platform/exported/WrappedResourceResponse.h"
#include "platform/graphics/BitmapImage.h"
@@ -89,7 +89,10 @@ const unsigned char kJpegImage[] = {
0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f,
0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9};
-const size_t kJpegImageSubrangeWithDimensionsLength = sizeof(kJpegImage) - 1;
+constexpr int kJpegImageWidth = 1;
+
+constexpr size_t kJpegImageSubrangeWithDimensionsLength =
+ sizeof(kJpegImage) - 1;
// Ensure that the image decoder can determine the dimensions of kJpegImage from
// just the first kJpegImageSubrangeWithDimensionsLength bytes. If this test
@@ -135,6 +138,8 @@ const unsigned char kJpegImage2[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xd9};
+constexpr int kJpegImage2Width = 50;
+
const char kSvgImage[] =
"<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" "
"xmlns:xlink=\"http://www.w3.org/1999/xlink\">"
@@ -231,8 +236,8 @@ TEST(ImageResourceTest, MultipartImage) {
imageResource->setIdentifier(createUniqueIdentifier());
fetcher->startLoad(imageResource);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
EXPECT_EQ(Resource::Pending, imageResource->getStatus());
// Send the multipart response. No image or data buffer is created. Note that
@@ -245,8 +250,8 @@ TEST(ImageResourceTest, MultipartImage) {
WrappedResourceResponse(multipartResponse), nullptr);
EXPECT_FALSE(imageResource->resourceBuffer());
EXPECT_FALSE(imageResource->getContent()->hasImage());
- EXPECT_EQ(0, client->imageChangedCount());
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(0, observer->imageChangedCount());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
EXPECT_EQ("multipart/x-mixed-replace", imageResource->response().mimeType());
const char firstPart[] =
@@ -257,8 +262,8 @@ TEST(ImageResourceTest, MultipartImage) {
// created.
EXPECT_FALSE(imageResource->resourceBuffer());
EXPECT_FALSE(imageResource->getContent()->hasImage());
- EXPECT_EQ(0, client->imageChangedCount());
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(0, observer->imageChangedCount());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
EXPECT_EQ("image/svg+xml", imageResource->response().mimeType());
const char secondPart[] =
@@ -269,15 +274,15 @@ TEST(ImageResourceTest, MultipartImage) {
imageResource->appendData(secondPart, strlen(secondPart));
EXPECT_TRUE(imageResource->resourceBuffer());
EXPECT_FALSE(imageResource->getContent()->hasImage());
- EXPECT_EQ(0, client->imageChangedCount());
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(0, observer->imageChangedCount());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
- // Add a client to check an assertion error doesn't happen
+ // Add an observer to check an assertion error doesn't happen
// (crbug.com/630983).
- Persistent<MockImageResourceClient> client2 =
- new MockImageResourceClient(imageResource);
- EXPECT_EQ(0, client2->imageChangedCount());
- EXPECT_FALSE(client2->notifyFinishedCalled());
+ std::unique_ptr<MockImageResourceObserver> observer2 =
+ MockImageResourceObserver::create(imageResource->getContent());
+ EXPECT_EQ(0, observer2->imageChangedCount());
+ EXPECT_FALSE(observer2->imageNotifyFinishedCalled());
const char thirdPart[] = "--boundary";
imageResource->appendData(thirdPart, strlen(thirdPart));
@@ -293,13 +298,13 @@ TEST(ImageResourceTest, MultipartImage) {
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(1, client2->imageChangedCount());
- EXPECT_TRUE(client2->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(1, observer2->imageChangedCount());
+ EXPECT_TRUE(observer2->imageNotifyFinishedCalled());
}
-TEST(ImageResourceTest, CancelOnDetach) {
+TEST(ImageResourceTest, CancelOnRemoveObserver) {
KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
ScopedRegisteredURL scopedRegisteredURL(testURL);
@@ -314,13 +319,13 @@ TEST(ImageResourceTest, CancelOnDetach) {
fetcher->startLoad(imageResource);
memoryCache()->add(imageResource);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
EXPECT_EQ(Resource::Pending, imageResource->getStatus());
// The load should still be alive, but a timer should be started to cancel the
// load inside removeClient().
- client->removeAsClient();
+ observer->removeAsObserver();
EXPECT_EQ(Resource::Pending, imageResource->getStatus());
EXPECT_TRUE(memoryCache()->resourceForURL(testURL));
@@ -335,8 +340,8 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) {
ImageResource* imageResource = ImageResource::create(ResourceRequest());
imageResource->setStatus(Resource::Pending);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
// Send the image response.
imageResource->responseReceived(
@@ -356,18 +361,18 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
- // The prune comes when the ImageResource still has clients. The image should
- // not be deleted.
+ // The prune comes when the ImageResource still has observers. The image
+ // should not be deleted.
imageResource->prune();
EXPECT_TRUE(imageResource->isAlive());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- // The ImageResource no longer has clients. The decoded image data should be
+ // The ImageResource no longer has observers. The decoded image data should be
// deleted by prune.
- client->removeAsClient();
+ observer->removeAsObserver();
imageResource->prune();
EXPECT_FALSE(imageResource->isAlive());
EXPECT_TRUE(imageResource->getContent()->hasImage());
@@ -379,8 +384,8 @@ TEST(ImageResourceTest, UpdateBitmapImages) {
ImageResource* imageResource = ImageResource::create(ResourceRequest());
imageResource->setStatus(Resource::Pending);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
// Send the image response.
imageResource->responseReceived(
@@ -393,8 +398,8 @@ TEST(ImageResourceTest, UpdateBitmapImages) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
}
@@ -406,8 +411,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
ImageResource* imageResource = ImageResource::create(request);
imageResource->setStatus(Resource::Pending);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
ResourceFetcher* fetcher =
ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
@@ -424,13 +429,11 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- // The client should have been notified that the image load completed.
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ // The observer should have been notified that the image load completed.
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -441,8 +444,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
EXPECT_FALSE(imageResource->errorOccurred());
EXPECT_FALSE(imageResource->resourceBuffer());
EXPECT_FALSE(imageResource->getContent()->hasImage());
- EXPECT_EQ(3, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
+ EXPECT_EQ(3, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
imageResource->loader()->didReceiveResponse(
WrappedResourceResponse(resourceResponse), nullptr);
@@ -453,12 +456,11 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnLastImageChanged());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
- // The client should not have been notified of completion again.
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
+ // The observer should not have been notified of completion again.
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
@@ -476,8 +478,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
// Send the image response.
ResourceResponse initialResourceResponse(
@@ -492,9 +494,9 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -505,11 +507,12 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
EXPECT_FALSE(imageResource->errorOccurred());
EXPECT_FALSE(imageResource->resourceBuffer());
EXPECT_FALSE(imageResource->getContent()->hasImage());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(0U, client->encodedSizeOnLastImageChanged());
- // The client should not have been notified of completion yet, since the image
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_EQ(0, observer->imageWidthOnLastImageChanged());
+ // The observer should not have been notified of completion yet, since the
+ // image
// is still loading.
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
imageResource->loader()->didReceiveResponse(
WrappedResourceResponse(ResourceResponse(
@@ -523,12 +526,11 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged());
- // The client should have been notified of completion only after the reload
+ EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnLastImageChanged());
+ // The observer should have been notified of completion only after the reload
// completed.
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnImageNotifyFinished());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnImageNotifyFinished());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
@@ -547,8 +549,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
request.placeholderImageRequestType());
EXPECT_EQ("bytes=0-2047",
imageResource->resourceRequest().httpHeaderField("range"));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
ResourceResponse response(testURL, "image/jpeg",
kJpegImageSubrangeWithDimensionsLength, nullAtom,
@@ -586,8 +588,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
TEST(ImageResourceTest, SVGImage) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
strlen(kSvgImage));
@@ -595,16 +597,16 @@ TEST(ImageResourceTest, SVGImage) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
}
TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/jpeg",
reinterpret_cast<const char*>(kJpegImage),
@@ -613,9 +615,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -630,9 +631,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -641,8 +641,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
strlen(kSvgImage));
@@ -650,9 +650,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getContent()->getImage()->width());
EXPECT_EQ(200, imageResource->getContent()->getImage()->height());
@@ -666,9 +665,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getContent()->getImage()->width());
EXPECT_EQ(200, imageResource->getContent()->getImage()->height());
@@ -677,8 +675,8 @@ TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/jpeg",
reinterpret_cast<const char*>(kJpegImage),
@@ -687,9 +685,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -702,9 +699,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(4, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(4, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
@@ -713,8 +709,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/jpeg",
reinterpret_cast<const char*>(kJpegImage),
@@ -723,9 +719,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -737,9 +732,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(3, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(3, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getContent()->getImage()->width());
EXPECT_EQ(200, imageResource->getContent()->getImage()->height());
@@ -748,8 +742,8 @@ TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
strlen(kSvgImage));
@@ -757,9 +751,8 @@ TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getContent()->getImage()->width());
EXPECT_EQ(200, imageResource->getContent()->getImage()->height());
@@ -772,9 +765,8 @@ TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(3, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(3, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
@@ -783,8 +775,8 @@ TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
strlen(kSvgImage));
@@ -792,9 +784,8 @@ TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(1, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(1, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getContent()->getImage()->width());
EXPECT_EQ(200, imageResource->getContent()->getImage()->height());
@@ -806,9 +797,8 @@ TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(300, imageResource->getContent()->getImage()->width());
EXPECT_EQ(300, imageResource->getContent()->getImage()->height());
@@ -885,8 +875,8 @@ TEST(ImageResourceTest, FetchDisallowPlaceholder) {
EXPECT_EQ(nullAtom,
imageResource->resourceRequest().httpHeaderField("range"));
EXPECT_FALSE(imageResource->isPlaceholder());
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
imageResource->loader()->didReceiveResponse(
WrappedResourceResponse(ResourceResponse(
@@ -899,11 +889,10 @@ TEST(ImageResourceTest, FetchDisallowPlaceholder) {
EXPECT_EQ(Resource::Cached, imageResource->getStatus());
EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize());
EXPECT_FALSE(imageResource->isPlaceholder());
- EXPECT_LT(0, client->imageChangedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
+ EXPECT_LT(0, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
@@ -980,8 +969,8 @@ TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) {
EXPECT_EQ("bytes=0-2047",
imageResource->resourceRequest().httpHeaderField("range"));
EXPECT_TRUE(imageResource->isPlaceholder());
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
ResourceResponse response(testURL, "image/jpeg",
kJpegImageSubrangeWithDimensionsLength, nullAtom,
@@ -1003,14 +992,10 @@ TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) {
EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
imageResource->encodedSize());
EXPECT_TRUE(imageResource->isPlaceholder());
- EXPECT_LT(0, client->imageChangedCount());
- EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
- client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
- client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
- client->encodedSizeOnImageNotifyFinished());
+ EXPECT_LT(0, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
@@ -1033,8 +1018,8 @@ TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
EXPECT_EQ("bytes=0-2047",
imageResource->resourceRequest().httpHeaderField("range"));
EXPECT_TRUE(imageResource->isPlaceholder());
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
const char kBadData[] = "notanimageresponse";
@@ -1052,8 +1037,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
EXPECT_EQ(
static_cast<int>(WebCachePolicy::BypassingCache),
static_cast<int>(imageResource->resourceRequest().getCachePolicy()));
- EXPECT_FALSE(client->notifyFinishedCalled());
- EXPECT_EQ(0, client->imageNotifyFinishedCount());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
imageResource->loader()->didReceiveResponse(
WrappedResourceResponse(ResourceResponse(
@@ -1066,12 +1050,10 @@ TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
EXPECT_EQ(Resource::Cached, imageResource->getStatus());
EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize());
EXPECT_FALSE(imageResource->isPlaceholder());
- EXPECT_LT(0, client->imageChangedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
+ EXPECT_LT(0, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
@@ -1089,8 +1071,8 @@ TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
placeholderRequest.setAllowImagePlaceholder();
ImageResource* imageResource =
ImageResource::fetch(placeholderRequest, fetcher);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
ImageResource* secondImageResource =
@@ -1103,7 +1085,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
EXPECT_EQ(
static_cast<int>(WebCachePolicy::UseProtocolCachePolicy),
static_cast<int>(imageResource->resourceRequest().getCachePolicy()));
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
imageResource->loader()->cancel();
}
@@ -1119,8 +1101,8 @@ TEST(ImageResourceTest,
placeholderRequest.setAllowImagePlaceholder();
ImageResource* imageResource =
ImageResource::fetch(placeholderRequest, fetcher);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
ResourceResponse response(testURL, "image/jpeg",
kJpegImageSubrangeWithDimensionsLength, nullAtom,
@@ -1142,8 +1124,8 @@ TEST(ImageResourceTest,
EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
imageResource->encodedSize());
EXPECT_TRUE(imageResource->isPlaceholder());
- EXPECT_LT(0, client->imageChangedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_LT(0, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
ImageResource* secondImageResource =
@@ -1170,8 +1152,8 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
ImageResource* imageResource = ImageResource::create(request);
imageResource->setStatus(Resource::Pending);
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(imageResource);
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
// Send the image response.
ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2),
@@ -1190,7 +1172,7 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
EXPECT_FALSE(imageResource->errorOccurred());
EXPECT_TRUE(imageResource->getContent()->hasImage());
- EXPECT_EQ(1, client->imageChangedCount());
+ EXPECT_EQ(1, observer->imageChangedCount());
platform->runForPeriodSeconds(1.);
platform->advanceClockSeconds(1.);
@@ -1199,7 +1181,7 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
// bytes just once.
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
- EXPECT_EQ(1, client->imageChangedCount());
+ EXPECT_EQ(1, observer->imageChangedCount());
for (int flushCount = 1; flushCount <= 3; ++flushCount) {
// For each of the iteration that appends data, we don't expect
@@ -1214,7 +1196,7 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
- EXPECT_EQ(flushCount, client->imageChangedCount());
+ EXPECT_EQ(flushCount, observer->imageChangedCount());
++bytesSent;
platform->runForPeriodSeconds(0.2001);
@@ -1227,7 +1209,7 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(4, client->imageChangedCount());
+ EXPECT_EQ(4, observer->imageChangedCount());
// Append the rest of the data and finish (which causes another flush).
imageResource->appendData(
@@ -1238,8 +1220,8 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->getContent()->hasImage());
EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
- EXPECT_EQ(5, client->imageChangedCount());
- EXPECT_TRUE(client->notifyFinishedCalled());
+ EXPECT_EQ(5, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
« no previous file with comments | « third_party/WebKit/Source/core/BUILD.gn ('k') | third_party/WebKit/Source/core/loader/resource/MockImageResourceClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698