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

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: Refactoring 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ASSERT_EQ(client->imageChangedCount(), 0); 162 ASSERT_EQ(client->imageChangedCount(), 0);
163 ASSERT_FALSE(client->notifyFinishedCalled()); 163 ASSERT_FALSE(client->notifyFinishedCalled());
164 164
165 const char thirdPart[] = "--boundary"; 165 const char thirdPart[] = "--boundary";
166 cachedImage->appendData(thirdPart, strlen(thirdPart)); 166 cachedImage->appendData(thirdPart, strlen(thirdPart));
167 ASSERT_TRUE(cachedImage->resourceBuffer()); 167 ASSERT_TRUE(cachedImage->resourceBuffer());
168 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); 168 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1);
169 169
170 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared. 170 // This part finishes. The image is created, callbacks are sent, and the dat a buffer is cleared.
171 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); 171 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0);
172 ASSERT_FALSE(cachedImage->resourceBuffer()); 172 ASSERT_TRUE(cachedImage->resourceBuffer());
173 ASSERT_FALSE(cachedImage->errorOccurred()); 173 ASSERT_FALSE(cachedImage->errorOccurred());
174 ASSERT_TRUE(cachedImage->hasImage()); 174 ASSERT_TRUE(cachedImage->hasImage());
175 ASSERT_FALSE(cachedImage->getImage()->isNull()); 175 ASSERT_FALSE(cachedImage->getImage()->isNull());
176 ASSERT_EQ(cachedImage->getImage()->width(), 1); 176 ASSERT_EQ(cachedImage->getImage()->width(), 1);
177 ASSERT_EQ(cachedImage->getImage()->height(), 1); 177 ASSERT_EQ(cachedImage->getImage()->height(), 1);
178 ASSERT_EQ(client->imageChangedCount(), 1); 178 ASSERT_EQ(client->imageChangedCount(), 1);
179 ASSERT_TRUE(client->notifyFinishedCalled()); 179 ASSERT_TRUE(client->notifyFinishedCalled());
180 } 180 }
181 181
182 TEST(ImageResourceTest, CancelOnDetach) 182 TEST(ImageResourceTest, CancelOnDetach)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 ASSERT_TRUE(cachedImage->hasImage()); 227 ASSERT_TRUE(cachedImage->hasImage());
228 ASSERT_FALSE(cachedImage->getImage()->isNull()); 228 ASSERT_FALSE(cachedImage->getImage()->isNull());
229 ASSERT_TRUE(client->notifyFinishedCalled()); 229 ASSERT_TRUE(client->notifyFinishedCalled());
230 230
231 // The prune comes when the ImageResource still has clients. The image shoul d not be deleted. 231 // The prune comes when the ImageResource still has clients. The image shoul d not be deleted.
232 cachedImage->prune(); 232 cachedImage->prune();
233 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); 233 ASSERT_TRUE(cachedImage->hasClientsOrObservers());
234 ASSERT_TRUE(cachedImage->hasImage()); 234 ASSERT_TRUE(cachedImage->hasImage());
235 ASSERT_FALSE(cachedImage->getImage()->isNull()); 235 ASSERT_FALSE(cachedImage->getImage()->isNull());
236 236
237 // The ImageResource no longer has clients. The image should be deleted by p rune. 237 // The ImageResource no longer has clients. The decoded image data should be
238 // deleted by prune.
238 client->removeAsClient(); 239 client->removeAsClient();
239 cachedImage->prune(); 240 cachedImage->prune();
240 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); 241 ASSERT_FALSE(cachedImage->hasClientsOrObservers());
241 ASSERT_FALSE(cachedImage->hasImage()); 242 ASSERT_TRUE(cachedImage->hasImage());
242 ASSERT_TRUE(cachedImage->getImage()->isNull()); 243 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image
244 // data.
243 } 245 }
244 246
245 TEST(ImageResourceTest, UpdateBitmapImages) 247 TEST(ImageResourceTest, UpdateBitmapImages)
246 { 248 {
247 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); 249 ImageResource* cachedImage = ImageResource::create(ResourceRequest());
248 cachedImage->setStatus(Resource::Pending); 250 cachedImage->setStatus(Resource::Pending);
249 251
250 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac hedImage); 252 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac hedImage);
251 253
252 // Send the image response. 254 // Send the image response.
(...skipping 29 matching lines...) Expand all
282 cachedImage->finish(); 284 cachedImage->finish();
283 ASSERT_FALSE(cachedImage->errorOccurred()); 285 ASSERT_FALSE(cachedImage->errorOccurred());
284 ASSERT_TRUE(cachedImage->hasImage()); 286 ASSERT_TRUE(cachedImage->hasImage());
285 ASSERT_FALSE(cachedImage->getImage()->isNull()); 287 ASSERT_FALSE(cachedImage->getImage()->isNull());
286 ASSERT_EQ(client->imageChangedCount(), 2); 288 ASSERT_EQ(client->imageChangedCount(), 2);
287 ASSERT_TRUE(client->notifyFinishedCalled()); 289 ASSERT_TRUE(client->notifyFinishedCalled());
288 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 290 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
289 291
290 cachedImage->reloadIfLoFi(fetcher); 292 cachedImage->reloadIfLoFi(fetcher);
291 ASSERT_FALSE(cachedImage->errorOccurred()); 293 ASSERT_FALSE(cachedImage->errorOccurred());
292 ASSERT_FALSE(cachedImage->resourceBuffer()); 294 ASSERT_TRUE(cachedImage->resourceBuffer());
293 ASSERT_TRUE(cachedImage->hasImage()); 295 ASSERT_TRUE(cachedImage->hasImage());
294 ASSERT_EQ(client->imageChangedCount(), 3); 296 ASSERT_EQ(client->imageChangedCount(), 3);
295 297
296 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr); 298 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr);
297 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size()); 299 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size());
298 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); 300 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size());
299 ASSERT_FALSE(cachedImage->errorOccurred()); 301 ASSERT_FALSE(cachedImage->errorOccurred());
300 ASSERT_TRUE(cachedImage->hasImage()); 302 ASSERT_TRUE(cachedImage->hasImage());
301 ASSERT_FALSE(cachedImage->getImage()->isNull()); 303 ASSERT_FALSE(cachedImage->getImage()->isNull());
302 ASSERT_TRUE(client->notifyFinishedCalled()); 304 ASSERT_TRUE(client->notifyFinishedCalled());
303 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 305 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
304 } 306 }
305 307
306 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698