Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 17 matching lines...) Expand all Loading... | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/fetch/ImageResource.h" | 32 #include "core/fetch/ImageResource.h" |
| 33 | 33 |
| 34 #include "core/fetch/ImageResourceClient.h" | 34 #include "core/fetch/ImageResourceClient.h" |
| 35 #include "core/fetch/MemoryCache.h" | 35 #include "core/fetch/MemoryCache.h" |
| 36 #include "core/fetch/MockImageResourceClient.h" | 36 #include "core/fetch/MockImageResourceClient.h" |
| 37 #include "core/fetch/ResourceFetcher.h" | 37 #include "core/fetch/ResourceFetcher.h" |
| 38 #include "core/fetch/ResourceLoader.h" | |
| 38 #include "core/fetch/ResourcePtr.h" | 39 #include "core/fetch/ResourcePtr.h" |
| 39 #include "core/fetch/UniqueIdentifier.h" | 40 #include "core/fetch/UniqueIdentifier.h" |
| 40 #include "platform/SharedBuffer.h" | 41 #include "platform/SharedBuffer.h" |
| 42 #include "platform/exported/WrappedResourceResponse.h" | |
| 41 #include "platform/graphics/Image.h" | 43 #include "platform/graphics/Image.h" |
| 42 #include "platform/testing/URLTestHelpers.h" | 44 #include "platform/testing/URLTestHelpers.h" |
| 43 #include "platform/testing/UnitTestHelpers.h" | 45 #include "platform/testing/UnitTestHelpers.h" |
| 44 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebURL.h" | 47 #include "public/platform/WebURL.h" |
| 46 #include "public/platform/WebURLResponse.h" | 48 #include "public/platform/WebURLResponse.h" |
| 47 #include "public/platform/WebUnitTestSupport.h" | 49 #include "public/platform/WebUnitTestSupport.h" |
| 48 | 50 |
| 49 using namespace blink; | 51 using namespace blink; |
| 50 | 52 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 77 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, | 79 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, |
| 78 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 | 80 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 jpeg.append(data, sizeof(data)); | 83 jpeg.append(data, sizeof(data)); |
| 82 return jpeg; | 84 return jpeg; |
| 83 } | 85 } |
| 84 | 86 |
| 85 TEST(ImageResourceTest, MultipartImage) | 87 TEST(ImageResourceTest, MultipartImage) |
| 86 { | 88 { |
| 87 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest() ); | 89 RefPtrWillBeRawPtr<ResourceFetcher> fetcher = ResourceFetcher::create(nullpt r); |
| 88 cachedImage->setLoading(true); | 90 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 91 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); | |
| 92 | |
| 93 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. | |
| 94 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t estURL)); | |
| 95 cachedImage->setIdentifier(createUniqueIdentifier()); | |
| 96 cachedImage->load(fetcher.get(), ResourceLoaderOptions()); | |
| 97 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | |
| 89 | 98 |
| 90 MockImageResourceClient client; | 99 MockImageResourceClient client; |
| 91 cachedImage->addClient(&client); | 100 cachedImage->addClient(&client); |
| 101 EXPECT_EQ(Resource::Pending, cachedImage->status()); | |
| 92 | 102 |
| 93 // Send the multipart response. No image or data buffer is created. | 103 // Send the multipart response. No image or data buffer is created. |
| 94 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr); | 104 // Note that the response must be routed through ResourceLoader to |
| 105 // ensure the load is flagged as multipart. | |
| 106 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String()); | |
| 107 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m ultipartResponse), nullptr); | |
| 95 ASSERT_FALSE(cachedImage->resourceBuffer()); | 108 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 96 ASSERT_FALSE(cachedImage->hasImage()); | 109 ASSERT_FALSE(cachedImage->hasImage()); |
| 97 ASSERT_EQ(client.imageChangedCount(), 0); | 110 ASSERT_EQ(client.imageChangedCount(), 0); |
| 98 ASSERT_FALSE(client.notifyFinishedCalled()); | 111 ASSERT_FALSE(client.notifyFinishedCalled()); |
| 99 | 112 |
| 100 // Send the response for the first real part. No image or data buffer is cre ated. | 113 // Send the response for the first real part. No image or data buffer is cre ated. |
| 101 const char* svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1' hei ght='1'><rect width='1' height='1' fill='green'/></svg>"; | 114 const char* svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1' hei ght='1'><rect width='1' height='1' fill='green'/></svg>"; |
| 102 unsigned svgDataLength = strlen(svgData); | 115 unsigned svgDataLength = strlen(svgData); |
| 103 cachedImage->responseReceived(ResourceResponse(KURL(), "image/svg+xml", svgD ataLength, nullAtom, String()), nullptr); | 116 ResourceResponse payloadResponse(KURL(), "image/svg+xml", svgDataLength, nul lAtom, String()); |
| 117 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(p ayloadResponse), nullptr); | |
| 104 ASSERT_FALSE(cachedImage->resourceBuffer()); | 118 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 105 ASSERT_FALSE(cachedImage->hasImage()); | 119 ASSERT_FALSE(cachedImage->hasImage()); |
| 106 ASSERT_EQ(client.imageChangedCount(), 0); | 120 ASSERT_EQ(client.imageChangedCount(), 0); |
| 107 ASSERT_FALSE(client.notifyFinishedCalled()); | 121 ASSERT_FALSE(client.notifyFinishedCalled()); |
| 108 | 122 |
| 109 // The first bytes arrive. The data buffer is created, but no image is creat ed. | 123 // The first bytes arrive. The data buffer is created, but no image is creat ed. |
| 110 cachedImage->appendData(svgData, svgDataLength); | 124 cachedImage->appendData(svgData, svgDataLength); |
| 111 ASSERT_TRUE(cachedImage->resourceBuffer()); | 125 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 112 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); | 126 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); |
| 113 ASSERT_FALSE(cachedImage->hasImage()); | 127 ASSERT_FALSE(cachedImage->hasImage()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 207 |
| 194 TEST(ImageResourceTest, UpdateBitmapImages) | 208 TEST(ImageResourceTest, UpdateBitmapImages) |
| 195 { | 209 { |
| 196 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest() ); | 210 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest() ); |
| 197 cachedImage->setLoading(true); | 211 cachedImage->setLoading(true); |
| 198 | 212 |
| 199 MockImageResourceClient client; | 213 MockImageResourceClient client; |
| 200 cachedImage->addClient(&client); | 214 cachedImage->addClient(&client); |
| 201 | 215 |
| 202 // Send the image response. | 216 // Send the image response. |
| 203 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re place", 0, nullAtom, String()), nullptr); | |
| 204 | |
| 205 Vector<unsigned char> jpeg = jpegImage(); | 217 Vector<unsigned char> jpeg = jpegImage(); |
| 206 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); | 218 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si ze(), nullAtom, String()), nullptr); |
| 207 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); | 219 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); |
| 208 cachedImage->finish(); | 220 cachedImage->finish(); |
| 209 ASSERT_FALSE(cachedImage->errorOccurred()); | 221 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 210 ASSERT_TRUE(cachedImage->hasImage()); | 222 ASSERT_TRUE(cachedImage->hasImage()); |
| 211 ASSERT_FALSE(cachedImage->image()->isNull()); | 223 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 212 ASSERT_EQ(client.imageChangedCount(), 1); | 224 ASSERT_EQ(client.imageChangedCount(), 2); |
|
Nate Chapin
2015/05/27 20:45:24
Because this test no longer unnecessarily uses mul
| |
| 213 ASSERT_TRUE(client.notifyFinishedCalled()); | 225 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 214 | 226 |
| 215 HashSet<ImageResource*> bitmapImages; | 227 HashSet<ImageResource*> bitmapImages; |
| 216 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 228 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); |
| 217 bitmapImages.add(cachedImage.get()); | 229 bitmapImages.add(cachedImage.get()); |
| 218 } | 230 } |
| 219 | 231 |
| 220 } // namespace | 232 } // namespace |
| OLD | NEW |