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

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

Issue 2054643003: Remove duplication of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove a comment Created 4 years, 5 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
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 ASSERT_EQ(client->imageChangedCount(), 0); 230 ASSERT_EQ(client->imageChangedCount(), 0);
231 ASSERT_FALSE(client->notifyFinishedCalled()); 231 ASSERT_FALSE(client->notifyFinishedCalled());
232 232
233 const char thirdPart[] = "--boundary"; 233 const char thirdPart[] = "--boundary";
234 cachedImage->appendData(thirdPart, strlen(thirdPart)); 234 cachedImage->appendData(thirdPart, strlen(thirdPart));
235 ASSERT_TRUE(cachedImage->resourceBuffer()); 235 ASSERT_TRUE(cachedImage->resourceBuffer());
236 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); 236 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1);
237 237
238 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared. 238 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared.
239 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); 239 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0);
240 ASSERT_FALSE(cachedImage->resourceBuffer()); 240 ASSERT_TRUE(cachedImage->resourceBuffer());
241 ASSERT_FALSE(cachedImage->errorOccurred()); 241 ASSERT_FALSE(cachedImage->errorOccurred());
242 ASSERT_TRUE(cachedImage->hasImage()); 242 ASSERT_TRUE(cachedImage->hasImage());
243 ASSERT_FALSE(cachedImage->getImage()->isNull()); 243 ASSERT_FALSE(cachedImage->getImage()->isNull());
244 ASSERT_EQ(cachedImage->getImage()->width(), 1); 244 ASSERT_EQ(cachedImage->getImage()->width(), 1);
245 ASSERT_EQ(cachedImage->getImage()->height(), 1); 245 ASSERT_EQ(cachedImage->getImage()->height(), 1);
246 ASSERT_EQ(client->imageChangedCount(), 1); 246 ASSERT_EQ(client->imageChangedCount(), 1);
247 ASSERT_TRUE(client->notifyFinishedCalled()); 247 ASSERT_TRUE(client->notifyFinishedCalled());
248 } 248 }
249 249
250 TEST(ImageResourceTest, CancelOnDetach) 250 TEST(ImageResourceTest, CancelOnDetach)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 ASSERT_TRUE(cachedImage->hasImage()); 295 ASSERT_TRUE(cachedImage->hasImage());
296 ASSERT_FALSE(cachedImage->getImage()->isNull()); 296 ASSERT_FALSE(cachedImage->getImage()->isNull());
297 ASSERT_TRUE(client->notifyFinishedCalled()); 297 ASSERT_TRUE(client->notifyFinishedCalled());
298 298
299 // The prune comes when the ImageResource still has clients. The image shoul d not be deleted. 299 // The prune comes when the ImageResource still has clients. The image shoul d not be deleted.
300 cachedImage->prune(); 300 cachedImage->prune();
301 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); 301 ASSERT_TRUE(cachedImage->hasClientsOrObservers());
302 ASSERT_TRUE(cachedImage->hasImage()); 302 ASSERT_TRUE(cachedImage->hasImage());
303 ASSERT_FALSE(cachedImage->getImage()->isNull()); 303 ASSERT_FALSE(cachedImage->getImage()->isNull());
304 304
305 // The ImageResource no longer has clients. The image should be deleted by p rune. 305 // The ImageResource no longer has clients. The decoded image data should be
306 // deleted by prune.
306 client->removeAsClient(); 307 client->removeAsClient();
307 cachedImage->prune(); 308 cachedImage->prune();
308 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); 309 ASSERT_FALSE(cachedImage->hasClientsOrObservers());
309 ASSERT_FALSE(cachedImage->hasImage()); 310 ASSERT_TRUE(cachedImage->hasImage());
310 ASSERT_TRUE(cachedImage->getImage()->isNull()); 311 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image
312 // data.
311 } 313 }
312 314
313 TEST(ImageResourceTest, UpdateBitmapImages) 315 TEST(ImageResourceTest, UpdateBitmapImages)
314 { 316 {
315 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); 317 ImageResource* cachedImage = ImageResource::create(ResourceRequest());
316 cachedImage->setStatus(Resource::Pending); 318 cachedImage->setStatus(Resource::Pending);
317 319
318 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac hedImage); 320 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac hedImage);
319 321
320 // Send the image response. 322 // Send the image response.
(...skipping 29 matching lines...) Expand all
350 cachedImage->finish(); 352 cachedImage->finish();
351 ASSERT_FALSE(cachedImage->errorOccurred()); 353 ASSERT_FALSE(cachedImage->errorOccurred());
352 ASSERT_TRUE(cachedImage->hasImage()); 354 ASSERT_TRUE(cachedImage->hasImage());
353 ASSERT_FALSE(cachedImage->getImage()->isNull()); 355 ASSERT_FALSE(cachedImage->getImage()->isNull());
354 ASSERT_EQ(client->imageChangedCount(), 2); 356 ASSERT_EQ(client->imageChangedCount(), 2);
355 ASSERT_TRUE(client->notifyFinishedCalled()); 357 ASSERT_TRUE(client->notifyFinishedCalled());
356 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 358 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
357 359
358 cachedImage->reloadIfLoFi(fetcher); 360 cachedImage->reloadIfLoFi(fetcher);
359 ASSERT_FALSE(cachedImage->errorOccurred()); 361 ASSERT_FALSE(cachedImage->errorOccurred());
360 ASSERT_FALSE(cachedImage->resourceBuffer()); 362 ASSERT_TRUE(cachedImage->resourceBuffer());
361 ASSERT_TRUE(cachedImage->hasImage()); 363 ASSERT_TRUE(cachedImage->hasImage());
362 ASSERT_EQ(client->imageChangedCount(), 3); 364 ASSERT_EQ(client->imageChangedCount(), 3);
363 365
364 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr); 366 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr);
365 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size()); 367 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size());
366 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); 368 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size());
367 ASSERT_FALSE(cachedImage->errorOccurred()); 369 ASSERT_FALSE(cachedImage->errorOccurred());
368 ASSERT_TRUE(cachedImage->hasImage()); 370 ASSERT_TRUE(cachedImage->hasImage());
369 ASSERT_FALSE(cachedImage->getImage()->isNull()); 371 ASSERT_FALSE(cachedImage->getImage()->isNull());
370 ASSERT_TRUE(client->notifyFinishedCalled()); 372 ASSERT_TRUE(client->notifyFinishedCalled());
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 ASSERT_TRUE(imageResource->hasImage()); 570 ASSERT_TRUE(imageResource->hasImage());
569 EXPECT_FALSE(imageResource->getImage()->isNull()); 571 EXPECT_FALSE(imageResource->getImage()->isNull());
570 EXPECT_EQ(2, client->imageChangedCount()); 572 EXPECT_EQ(2, client->imageChangedCount());
571 EXPECT_TRUE(client->notifyFinishedCalled()); 573 EXPECT_TRUE(client->notifyFinishedCalled());
572 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); 574 EXPECT_FALSE(imageResource->getImage()->isBitmapImage());
573 EXPECT_EQ(300, imageResource->getImage()->width()); 575 EXPECT_EQ(300, imageResource->getImage()->width());
574 EXPECT_EQ(300, imageResource->getImage()->height()); 576 EXPECT_EQ(300, imageResource->getImage()->height());
575 } 577 }
576 578
577 } // namespace blink 579 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698