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

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

Issue 2169363002: Reland "Ensure |m_image| is (re-)created in ImageResource::didAddClient()" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr); 300 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r esourceResponse), nullptr);
301 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size()); 301 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*> (jpeg.data()), jpeg.size(), jpeg.size());
302 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); 302 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size());
303 ASSERT_FALSE(cachedImage->errorOccurred()); 303 ASSERT_FALSE(cachedImage->errorOccurred());
304 ASSERT_TRUE(cachedImage->hasImage()); 304 ASSERT_TRUE(cachedImage->hasImage());
305 ASSERT_FALSE(cachedImage->getImage()->isNull()); 305 ASSERT_FALSE(cachedImage->getImage()->isNull());
306 ASSERT_TRUE(client->notifyFinishedCalled()); 306 ASSERT_TRUE(client->notifyFinishedCalled());
307 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 307 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
308 } 308 }
309 309
310 // Tests for pruning.
311
312 TEST(ImageResourceTest, AddClientAfterPrune)
313 {
314 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
315 ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
316
317 // Adds a ResourceClient but not ImageResourceObserver.
318 Persistent<MockResourceClient> client1 = new MockResourceClient(imageResourc e);
319
320 Vector<unsigned char> jpeg = jpegImage();
321 ResourceResponse response;
322 response.setURL(url);
323 response.setHTTPStatusCode(200);
324 response.setMimeType("image/jpeg");
325 imageResource->responseReceived(response, nullptr);
326 imageResource->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.s ize());
327 imageResource->finish();
328
329 EXPECT_FALSE(imageResource->errorOccurred());
330 ASSERT_TRUE(imageResource->hasImage());
331 EXPECT_FALSE(imageResource->getImage()->isNull());
332 EXPECT_EQ(1, imageResource->getImage()->width());
333 EXPECT_EQ(1, imageResource->getImage()->height());
334 EXPECT_TRUE(client1->notifyFinishedCalled());
335
336 client1->removeAsClient();
337
338 EXPECT_FALSE(imageResource->hasClientsOrObservers());
339
340 imageResource->prune();
341
342 EXPECT_FALSE(imageResource->hasImage());
343
344 // Re-adds a ResourceClient but not ImageResourceObserver.
345 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc e);
346
347 ASSERT_TRUE(imageResource->hasImage());
348 EXPECT_FALSE(imageResource->getImage()->isNull());
349 EXPECT_EQ(1, imageResource->getImage()->width());
350 EXPECT_EQ(1, imageResource->getImage()->height());
351 EXPECT_TRUE(client2->notifyFinishedCalled());
352 }
353
310 } // namespace blink 354 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698