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

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

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