| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 "core/loader/resource/ImageResource.h" | 31 #include "core/loader/resource/ImageResource.h" |
| 32 | 32 |
| 33 #include <memory> |
| 33 #include "core/loader/resource/MockImageResourceClient.h" | 34 #include "core/loader/resource/MockImageResourceClient.h" |
| 34 #include "core/loader/resource/MockImageResourceObserver.h" | 35 #include "core/loader/resource/MockImageResourceObserver.h" |
| 35 #include "platform/SharedBuffer.h" | 36 #include "platform/SharedBuffer.h" |
| 36 #include "platform/exported/WrappedResourceResponse.h" | 37 #include "platform/exported/WrappedResourceResponse.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 38 #include "platform/graphics/BitmapImage.h" |
| 38 #include "platform/graphics/Image.h" | 39 #include "platform/graphics/Image.h" |
| 39 #include "platform/loader/fetch/FetchInitiatorInfo.h" | 40 #include "platform/loader/fetch/FetchInitiatorInfo.h" |
| 40 #include "platform/loader/fetch/FetchRequest.h" | 41 #include "platform/loader/fetch/FetchRequest.h" |
| 41 #include "platform/loader/fetch/MemoryCache.h" | 42 #include "platform/loader/fetch/MemoryCache.h" |
| 42 #include "platform/loader/fetch/MockResourceClient.h" | 43 #include "platform/loader/fetch/MockResourceClient.h" |
| 43 #include "platform/loader/fetch/ResourceFetcher.h" | 44 #include "platform/loader/fetch/ResourceFetcher.h" |
| 44 #include "platform/loader/fetch/ResourceLoader.h" | 45 #include "platform/loader/fetch/ResourceLoader.h" |
| 45 #include "platform/loader/fetch/UniqueIdentifier.h" | 46 #include "platform/loader/fetch/UniqueIdentifier.h" |
| 46 #include "platform/scheduler/test/fake_web_task_runner.h" | 47 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 48 #include "platform/testing/ScopedMockedURL.h" |
| 47 #include "platform/testing/TestingPlatformSupport.h" | 49 #include "platform/testing/TestingPlatformSupport.h" |
| 48 #include "platform/testing/URLTestHelpers.h" | |
| 49 #include "platform/testing/UnitTestHelpers.h" | 50 #include "platform/testing/UnitTestHelpers.h" |
| 50 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 51 #include "public/platform/WebCachePolicy.h" | 52 #include "public/platform/WebCachePolicy.h" |
| 52 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
| 53 #include "public/platform/WebURLLoaderMockFactory.h" | 54 #include "public/platform/WebURLLoaderMockFactory.h" |
| 54 #include "public/platform/WebURLResponse.h" | 55 #include "public/platform/WebURLResponse.h" |
| 55 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 56 #include "wtf/PtrUtil.h" | 57 #include "wtf/PtrUtil.h" |
| 57 #include "wtf/text/Base64.h" | 58 #include "wtf/text/Base64.h" |
| 58 #include <memory> | |
| 59 | 59 |
| 60 namespace blink { | 60 namespace blink { |
| 61 | 61 |
| 62 using testing::ScopedMockedURLLoad; |
| 63 |
| 62 namespace { | 64 namespace { |
| 63 | 65 |
| 64 // An image of size 1x1. | 66 // An image of size 1x1. |
| 65 const unsigned char kJpegImage[] = { | 67 constexpr unsigned char kJpegImage[] = { |
| 66 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, | 68 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, |
| 67 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, | 69 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, |
| 68 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, | 70 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, |
| 69 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x05, 0x03, | 71 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x05, 0x03, |
| 70 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, | 72 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, |
| 71 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, | 73 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, |
| 72 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13, 0x16, 0x1c, 0x17, | 74 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13, 0x16, 0x1c, 0x17, |
| 73 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1a, 0x1d, 0x1d, | 75 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1a, 0x1d, 0x1d, |
| 74 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e, 0x24, 0x1c, 0x1e, | 76 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e, 0x24, 0x1c, 0x1e, |
| 75 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05, 0x05, 0x07, 0x06, | 77 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05, 0x05, 0x07, 0x06, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 104 Image::SizeAvailable, | 106 Image::SizeAvailable, |
| 105 image->setData(SharedBuffer::create( | 107 image->setData(SharedBuffer::create( |
| 106 kJpegImage, kJpegImageSubrangeWithDimensionsLength), | 108 kJpegImage, kJpegImageSubrangeWithDimensionsLength), |
| 107 true)); | 109 true)); |
| 108 EXPECT_TRUE(image->isBitmapImage()); | 110 EXPECT_TRUE(image->isBitmapImage()); |
| 109 EXPECT_EQ(1, image->width()); | 111 EXPECT_EQ(1, image->width()); |
| 110 EXPECT_EQ(1, image->height()); | 112 EXPECT_EQ(1, image->height()); |
| 111 } | 113 } |
| 112 | 114 |
| 113 // An image of size 50x50. | 115 // An image of size 50x50. |
| 114 const unsigned char kJpegImage2[] = { | 116 constexpr unsigned char kJpegImage2[] = { |
| 115 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, | 117 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, |
| 116 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, | 118 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, |
| 117 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 119 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 118 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 120 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 119 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 121 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 120 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 122 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 121 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 123 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 122 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, | 124 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, |
| 123 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 125 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 124 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 126 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 125 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 127 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 126 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 128 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 127 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 129 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 128 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x32, 0x00, 0x32, 0x03, | 130 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x32, 0x00, 0x32, 0x03, |
| 129 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00, | 131 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00, |
| 130 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 132 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x10, | 133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x10, |
| 132 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 134 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 133 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x15, 0x01, 0x01, 0x01, | 135 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x15, 0x01, 0x01, 0x01, |
| 134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 135 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, | 137 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, |
| 136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 137 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, | 139 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, |
| 138 0x11, 0x00, 0x3f, 0x00, 0x00, 0x94, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | 140 0x11, 0x00, 0x3f, 0x00, 0x00, 0x94, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 140 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xd9}; | 142 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xd9}; |
| 141 | 143 |
| 142 constexpr int kJpegImage2Width = 50; | 144 constexpr int kJpegImage2Width = 50; |
| 143 | 145 |
| 144 const char kSvgImage[] = | 146 constexpr char kSvgImage[] = |
| 145 "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" " | 147 "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" " |
| 146 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" | 148 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" |
| 147 "<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" fill=\"red\"/>" | 149 "<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" fill=\"red\"/>" |
| 148 "</svg>"; | 150 "</svg>"; |
| 149 | 151 |
| 150 const char kSvgImage2[] = | 152 constexpr char kSvgImage2[] = |
| 151 "<svg width=\"300\" height=\"300\" xmlns=\"http://www.w3.org/2000/svg\" " | 153 "<svg width=\"300\" height=\"300\" xmlns=\"http://www.w3.org/2000/svg\" " |
| 152 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" | 154 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" |
| 153 "<rect x=\"0\" y=\"0\" width=\"200px\" height=\"200px\" fill=\"green\"/>" | 155 "<rect x=\"0\" y=\"0\" width=\"200px\" height=\"200px\" fill=\"green\"/>" |
| 154 "</svg>"; | 156 "</svg>"; |
| 155 | 157 |
| 158 constexpr char kTestURL[] = "http://www.test.com/cancelTest.html"; |
| 159 |
| 160 String GetTestFilePath() { |
| 161 return testing::webTestDataPath("cancelTest.html"); |
| 162 } |
| 163 |
| 156 void receiveResponse(ImageResource* imageResource, | 164 void receiveResponse(ImageResource* imageResource, |
| 157 const KURL& url, | 165 const KURL& url, |
| 158 const AtomicString& mimeType, | 166 const AtomicString& mimeType, |
| 159 const char* data, | 167 const char* data, |
| 160 size_t dataSize) { | 168 size_t dataSize) { |
| 161 ResourceResponse response; | 169 ResourceResponse response; |
| 162 response.setURL(url); | 170 response.setURL(url); |
| 163 response.setHTTPStatusCode(200); | 171 response.setHTTPStatusCode(200); |
| 164 response.setMimeType(mimeType); | 172 response.setMimeType(mimeType); |
| 165 imageResource->responseReceived(response, nullptr); | 173 imageResource->responseReceived(response, nullptr); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 190 bool shouldLoadNewResource(Resource::Type) const override { return true; } | 198 bool shouldLoadNewResource(Resource::Type) const override { return true; } |
| 191 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; } | 199 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; } |
| 192 | 200 |
| 193 private: | 201 private: |
| 194 ImageResourceTestMockFetchContext() | 202 ImageResourceTestMockFetchContext() |
| 195 : m_runner(adoptRef(new scheduler::FakeWebTaskRunner)) {} | 203 : m_runner(adoptRef(new scheduler::FakeWebTaskRunner)) {} |
| 196 | 204 |
| 197 RefPtr<scheduler::FakeWebTaskRunner> m_runner; | 205 RefPtr<scheduler::FakeWebTaskRunner> m_runner; |
| 198 }; | 206 }; |
| 199 | 207 |
| 200 // Convenience class that registers a mocked URL load on construction, and | |
| 201 // unregisters it on destruction. This allows for a test to use constructs like | |
| 202 // ASSERT_TRUE() without needing to worry about unregistering the mocked URL | |
| 203 // load to avoid putting other tests into inconsistent states in case the | |
| 204 // assertion fails. | |
| 205 // TODO(toyoshim): Generalize and move to platform/testing/URLTestHelpers. | |
| 206 class ScopedRegisteredURL { | |
| 207 public: | |
| 208 ScopedRegisteredURL(const KURL& url, | |
| 209 const String& fileName = "cancelTest.html", | |
| 210 const String& mimeType = "text/html") | |
| 211 : m_url(url) { | |
| 212 URLTestHelpers::registerMockedURLLoad( | |
| 213 m_url, testing::webTestDataPath(fileName.utf8().data()), mimeType); | |
| 214 } | |
| 215 | |
| 216 ~ScopedRegisteredURL() { | |
| 217 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url); | |
| 218 } | |
| 219 | |
| 220 private: | |
| 221 KURL m_url; | |
| 222 }; | |
| 223 | |
| 224 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) { | 208 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) { |
| 225 return AtomicString(String("bytes 0-" + String::number(rangeLength) + "/" + | 209 return AtomicString(String("bytes 0-" + String::number(rangeLength) + "/" + |
| 226 String::number(totalLength))); | 210 String::number(totalLength))); |
| 227 } | 211 } |
| 228 | 212 |
| 229 TEST(ImageResourceTest, MultipartImage) { | 213 TEST(ImageResourceTest, MultipartImage) { |
| 230 ResourceFetcher* fetcher = | 214 ResourceFetcher* fetcher = |
| 231 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 215 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 232 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 216 KURL testURL(ParsedURLString, kTestURL); |
| 233 ScopedRegisteredURL scopedRegisteredURL(testURL); | 217 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 234 | 218 |
| 235 // Emulate starting a real load, but don't expect any "real" | 219 // Emulate starting a real load, but don't expect any "real" |
| 236 // WebURLLoaderClient callbacks. | 220 // WebURLLoaderClient callbacks. |
| 237 ImageResource* imageResource = | 221 ImageResource* imageResource = |
| 238 ImageResource::create(ResourceRequest(testURL)); | 222 ImageResource::create(ResourceRequest(testURL)); |
| 239 imageResource->setIdentifier(createUniqueIdentifier()); | 223 imageResource->setIdentifier(createUniqueIdentifier()); |
| 240 fetcher->startLoad(imageResource); | 224 fetcher->startLoad(imageResource); |
| 241 | 225 |
| 242 std::unique_ptr<MockImageResourceObserver> observer = | 226 std::unique_ptr<MockImageResourceObserver> observer = |
| 243 MockImageResourceObserver::create(imageResource->getContent()); | 227 MockImageResourceObserver::create(imageResource->getContent()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 285 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 302 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 286 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 303 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 287 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 304 EXPECT_EQ(1, observer->imageChangedCount()); | 288 EXPECT_EQ(1, observer->imageChangedCount()); |
| 305 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 289 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 306 EXPECT_EQ(1, observer2->imageChangedCount()); | 290 EXPECT_EQ(1, observer2->imageChangedCount()); |
| 307 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); | 291 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); |
| 308 } | 292 } |
| 309 | 293 |
| 310 TEST(ImageResourceTest, CancelOnRemoveObserver) { | 294 TEST(ImageResourceTest, CancelOnRemoveObserver) { |
| 311 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 295 KURL testURL(ParsedURLString, kTestURL); |
| 312 ScopedRegisteredURL scopedRegisteredURL(testURL); | 296 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 313 | 297 |
| 314 ResourceFetcher* fetcher = | 298 ResourceFetcher* fetcher = |
| 315 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 299 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 316 | 300 |
| 317 // Emulate starting a real load. | 301 // Emulate starting a real load. |
| 318 ImageResource* imageResource = | 302 ImageResource* imageResource = |
| 319 ImageResource::create(ResourceRequest(testURL)); | 303 ImageResource::create(ResourceRequest(testURL)); |
| 320 imageResource->setIdentifier(createUniqueIdentifier()); | 304 imageResource->setIdentifier(createUniqueIdentifier()); |
| 321 | 305 |
| 322 fetcher->startLoad(imageResource); | 306 fetcher->startLoad(imageResource); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 imageResource->finish(); | 384 imageResource->finish(); |
| 401 EXPECT_FALSE(imageResource->errorOccurred()); | 385 EXPECT_FALSE(imageResource->errorOccurred()); |
| 402 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 386 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 403 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 387 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 404 EXPECT_EQ(2, observer->imageChangedCount()); | 388 EXPECT_EQ(2, observer->imageChangedCount()); |
| 405 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 389 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 406 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 390 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 407 } | 391 } |
| 408 | 392 |
| 409 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { | 393 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { |
| 410 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 394 KURL testURL(ParsedURLString, kTestURL); |
| 411 ScopedRegisteredURL scopedRegisteredURL(testURL); | 395 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 412 ResourceRequest request = ResourceRequest(testURL); | 396 ResourceRequest request = ResourceRequest(testURL); |
| 413 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 397 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 414 ImageResource* imageResource = ImageResource::create(request); | 398 ImageResource* imageResource = ImageResource::create(request); |
| 415 imageResource->setStatus(ResourceStatus::Pending); | 399 imageResource->setStatus(ResourceStatus::Pending); |
| 416 | 400 |
| 417 std::unique_ptr<MockImageResourceObserver> observer = | 401 std::unique_ptr<MockImageResourceObserver> observer = |
| 418 MockImageResourceObserver::create(imageResource->getContent()); | 402 MockImageResourceObserver::create(imageResource->getContent()); |
| 419 ResourceFetcher* fetcher = | 403 ResourceFetcher* fetcher = |
| 420 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 404 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 421 | 405 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 448 |
| 465 // The observer should not have been notified of completion again. | 449 // The observer should not have been notified of completion again. |
| 466 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 450 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 467 | 451 |
| 468 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 452 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 469 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 453 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 470 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 454 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 471 } | 455 } |
| 472 | 456 |
| 473 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { | 457 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { |
| 474 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 458 KURL testURL(ParsedURLString, kTestURL); |
| 475 ScopedRegisteredURL scopedRegisteredURL(testURL); | 459 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 476 | 460 |
| 477 ResourceRequest request(testURL); | 461 ResourceRequest request(testURL); |
| 478 request.setPreviewsState(WebURLRequest::ServerLoFiOn); | 462 request.setPreviewsState(WebURLRequest::ServerLoFiOn); |
| 479 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 463 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
| 480 ResourceFetcher* fetcher = | 464 ResourceFetcher* fetcher = |
| 481 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 465 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 482 | 466 |
| 483 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); | 467 ImageResource* imageResource = ImageResource::fetch(fetchRequest, fetcher); |
| 484 std::unique_ptr<MockImageResourceObserver> observer = | 468 std::unique_ptr<MockImageResourceObserver> observer = |
| 485 MockImageResourceObserver::create(imageResource->getContent()); | 469 MockImageResourceObserver::create(imageResource->getContent()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // The observer should have been notified of completion only after the reload | 517 // The observer should have been notified of completion only after the reload |
| 534 // completed. | 518 // completed. |
| 535 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 519 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 536 EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnImageNotifyFinished()); | 520 EXPECT_EQ(kJpegImage2Width, observer->imageWidthOnImageNotifyFinished()); |
| 537 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 521 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 538 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 522 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 539 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 523 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 540 } | 524 } |
| 541 | 525 |
| 542 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { | 526 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { |
| 543 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 527 KURL testURL(ParsedURLString, kTestURL); |
| 544 ScopedRegisteredURL scopedRegisteredURL(testURL); | 528 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 545 | 529 |
| 546 ResourceFetcher* fetcher = | 530 ResourceFetcher* fetcher = |
| 547 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 531 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 548 FetchRequest request(testURL, FetchInitiatorInfo()); | 532 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 549 request.setAllowImagePlaceholder(); | 533 request.setAllowImagePlaceholder(); |
| 550 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 534 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 551 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 535 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 552 request.placeholderImageRequestType()); | 536 request.placeholderImageRequestType()); |
| 553 EXPECT_EQ("bytes=0-2047", | 537 EXPECT_EQ("bytes=0-2047", |
| 554 imageResource->resourceRequest().httpHeaderField("range")); | 538 imageResource->resourceRequest().httpHeaderField("range")); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 new MockResourceClient(imageResource); | 825 new MockResourceClient(imageResource); |
| 842 | 826 |
| 843 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 827 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 844 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 828 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 845 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 829 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 846 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 830 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 847 EXPECT_TRUE(client2->notifyFinishedCalled()); | 831 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 848 } | 832 } |
| 849 | 833 |
| 850 TEST(ImageResourceTest, CancelOnDecodeError) { | 834 TEST(ImageResourceTest, CancelOnDecodeError) { |
| 851 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 835 KURL testURL(ParsedURLString, kTestURL); |
| 852 ScopedRegisteredURL scopedRegisteredURL(testURL); | 836 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 853 | 837 |
| 854 ResourceFetcher* fetcher = | 838 ResourceFetcher* fetcher = |
| 855 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 839 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 856 FetchRequest request(testURL, FetchInitiatorInfo()); | 840 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 857 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 841 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 858 std::unique_ptr<MockImageResourceObserver> observer = | 842 std::unique_ptr<MockImageResourceObserver> observer = |
| 859 MockImageResourceObserver::create(imageResource->getContent()); | 843 MockImageResourceObserver::create(imageResource->getContent()); |
| 860 | 844 |
| 861 imageResource->loader()->didReceiveResponse( | 845 imageResource->loader()->didReceiveResponse( |
| 862 WrappedResourceResponse( | 846 WrappedResourceResponse( |
| 863 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), | 847 ResourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), |
| 864 nullptr); | 848 nullptr); |
| 865 | 849 |
| 866 EXPECT_EQ(0, observer->imageChangedCount()); | 850 EXPECT_EQ(0, observer->imageChangedCount()); |
| 867 | 851 |
| 868 imageResource->loader()->didReceiveData("notactuallyanimage", 18); | 852 imageResource->loader()->didReceiveData("notactuallyanimage", 18); |
| 869 | 853 |
| 870 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); | 854 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
| 871 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 855 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 872 EXPECT_EQ(ResourceStatus::DecodeError, | 856 EXPECT_EQ(ResourceStatus::DecodeError, |
| 873 observer->statusOnImageNotifyFinished()); | 857 observer->statusOnImageNotifyFinished()); |
| 874 EXPECT_EQ(2, observer->imageChangedCount()); | 858 EXPECT_EQ(2, observer->imageChangedCount()); |
| 875 EXPECT_FALSE(imageResource->isLoading()); | 859 EXPECT_FALSE(imageResource->isLoading()); |
| 876 } | 860 } |
| 877 | 861 |
| 878 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { | 862 TEST(ImageResourceTest, DecodeErrorWithEmptyBody) { |
| 879 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 863 KURL testURL(ParsedURLString, kTestURL); |
| 880 ScopedRegisteredURL scopedRegisteredURL(testURL); | 864 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 881 | 865 |
| 882 ResourceFetcher* fetcher = | 866 ResourceFetcher* fetcher = |
| 883 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 867 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 884 FetchRequest request(testURL, FetchInitiatorInfo()); | 868 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 885 ImageResource* imageResource = ImageResource::fetch(request, fetcher); | 869 ImageResource* imageResource = ImageResource::fetch(request, fetcher); |
| 886 std::unique_ptr<MockImageResourceObserver> observer = | 870 std::unique_ptr<MockImageResourceObserver> observer = |
| 887 MockImageResourceObserver::create(imageResource->getContent()); | 871 MockImageResourceObserver::create(imageResource->getContent()); |
| 888 | 872 |
| 889 imageResource->loader()->didReceiveResponse( | 873 imageResource->loader()->didReceiveResponse( |
| 890 WrappedResourceResponse( | 874 WrappedResourceResponse( |
| 891 ResourceResponse(testURL, "image/jpeg", 0, nullAtom, String())), | 875 ResourceResponse(testURL, "image/jpeg", 0, nullAtom, String())), |
| 892 nullptr); | 876 nullptr); |
| 893 | 877 |
| 894 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); | 878 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 895 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 879 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 896 EXPECT_EQ(0, observer->imageChangedCount()); | 880 EXPECT_EQ(0, observer->imageChangedCount()); |
| 897 | 881 |
| 898 imageResource->loader()->didFinishLoading(0.0, 0, 0); | 882 imageResource->loader()->didFinishLoading(0.0, 0, 0); |
| 899 | 883 |
| 900 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); | 884 EXPECT_EQ(ResourceStatus::DecodeError, imageResource->getStatus()); |
| 901 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 885 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 902 EXPECT_EQ(ResourceStatus::DecodeError, | 886 EXPECT_EQ(ResourceStatus::DecodeError, |
| 903 observer->statusOnImageNotifyFinished()); | 887 observer->statusOnImageNotifyFinished()); |
| 904 EXPECT_EQ(1, observer->imageChangedCount()); | 888 EXPECT_EQ(1, observer->imageChangedCount()); |
| 905 EXPECT_FALSE(imageResource->isLoading()); | 889 EXPECT_FALSE(imageResource->isLoading()); |
| 906 } | 890 } |
| 907 | 891 |
| 908 TEST(ImageResourceTest, FetchDisallowPlaceholder) { | 892 TEST(ImageResourceTest, FetchDisallowPlaceholder) { |
| 909 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 893 KURL testURL(ParsedURLString, kTestURL); |
| 910 ScopedRegisteredURL scopedRegisteredURL(testURL); | 894 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 911 | 895 |
| 912 FetchRequest request(testURL, FetchInitiatorInfo()); | 896 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 913 ImageResource* imageResource = ImageResource::fetch( | 897 ImageResource* imageResource = ImageResource::fetch( |
| 914 request, | 898 request, |
| 915 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 899 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 916 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 900 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 917 request.placeholderImageRequestType()); | 901 request.placeholderImageRequestType()); |
| 918 EXPECT_EQ(nullAtom, | 902 EXPECT_EQ(nullAtom, |
| 919 imageResource->resourceRequest().httpHeaderField("range")); | 903 imageResource->resourceRequest().httpHeaderField("range")); |
| 920 EXPECT_FALSE(imageResource->isPlaceholder()); | 904 EXPECT_FALSE(imageResource->isPlaceholder()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 request, | 938 request, |
| 955 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 939 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 956 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 940 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 957 request.placeholderImageRequestType()); | 941 request.placeholderImageRequestType()); |
| 958 EXPECT_EQ(nullAtom, | 942 EXPECT_EQ(nullAtom, |
| 959 imageResource->resourceRequest().httpHeaderField("range")); | 943 imageResource->resourceRequest().httpHeaderField("range")); |
| 960 EXPECT_FALSE(imageResource->isPlaceholder()); | 944 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 961 } | 945 } |
| 962 | 946 |
| 963 TEST(ImageResourceTest, FetchAllowPlaceholderPostRequest) { | 947 TEST(ImageResourceTest, FetchAllowPlaceholderPostRequest) { |
| 964 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 948 KURL testURL(ParsedURLString, kTestURL); |
| 965 ScopedRegisteredURL scopedRegisteredURL(testURL); | 949 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 966 ResourceRequest resourceRequest(testURL); | 950 ResourceRequest resourceRequest(testURL); |
| 967 resourceRequest.setHTTPMethod("POST"); | 951 resourceRequest.setHTTPMethod("POST"); |
| 968 FetchRequest request(resourceRequest, FetchInitiatorInfo()); | 952 FetchRequest request(resourceRequest, FetchInitiatorInfo()); |
| 969 request.setAllowImagePlaceholder(); | 953 request.setAllowImagePlaceholder(); |
| 970 ImageResource* imageResource = ImageResource::fetch( | 954 ImageResource* imageResource = ImageResource::fetch( |
| 971 request, | 955 request, |
| 972 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 956 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 973 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 957 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 974 request.placeholderImageRequestType()); | 958 request.placeholderImageRequestType()); |
| 975 EXPECT_EQ(nullAtom, | 959 EXPECT_EQ(nullAtom, |
| 976 imageResource->resourceRequest().httpHeaderField("range")); | 960 imageResource->resourceRequest().httpHeaderField("range")); |
| 977 EXPECT_FALSE(imageResource->isPlaceholder()); | 961 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 978 | 962 |
| 979 imageResource->loader()->cancel(); | 963 imageResource->loader()->cancel(); |
| 980 } | 964 } |
| 981 | 965 |
| 982 TEST(ImageResourceTest, FetchAllowPlaceholderExistingRangeHeader) { | 966 TEST(ImageResourceTest, FetchAllowPlaceholderExistingRangeHeader) { |
| 983 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 967 KURL testURL(ParsedURLString, kTestURL); |
| 984 ScopedRegisteredURL scopedRegisteredURL(testURL); | 968 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 985 ResourceRequest resourceRequest(testURL); | 969 ResourceRequest resourceRequest(testURL); |
| 986 resourceRequest.setHTTPHeaderField("range", "bytes=128-255"); | 970 resourceRequest.setHTTPHeaderField("range", "bytes=128-255"); |
| 987 FetchRequest request(resourceRequest, FetchInitiatorInfo()); | 971 FetchRequest request(resourceRequest, FetchInitiatorInfo()); |
| 988 request.setAllowImagePlaceholder(); | 972 request.setAllowImagePlaceholder(); |
| 989 ImageResource* imageResource = ImageResource::fetch( | 973 ImageResource* imageResource = ImageResource::fetch( |
| 990 request, | 974 request, |
| 991 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 975 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 992 EXPECT_EQ(FetchRequest::DisallowPlaceholder, | 976 EXPECT_EQ(FetchRequest::DisallowPlaceholder, |
| 993 request.placeholderImageRequestType()); | 977 request.placeholderImageRequestType()); |
| 994 EXPECT_EQ("bytes=128-255", | 978 EXPECT_EQ("bytes=128-255", |
| 995 imageResource->resourceRequest().httpHeaderField("range")); | 979 imageResource->resourceRequest().httpHeaderField("range")); |
| 996 EXPECT_FALSE(imageResource->isPlaceholder()); | 980 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 997 | 981 |
| 998 imageResource->loader()->cancel(); | 982 imageResource->loader()->cancel(); |
| 999 } | 983 } |
| 1000 | 984 |
| 1001 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) { | 985 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) { |
| 1002 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 986 KURL testURL(ParsedURLString, kTestURL); |
| 1003 ScopedRegisteredURL scopedRegisteredURL(testURL); | 987 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1004 | 988 |
| 1005 FetchRequest request(testURL, FetchInitiatorInfo()); | 989 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1006 request.setAllowImagePlaceholder(); | 990 request.setAllowImagePlaceholder(); |
| 1007 ImageResource* imageResource = ImageResource::fetch( | 991 ImageResource* imageResource = ImageResource::fetch( |
| 1008 request, | 992 request, |
| 1009 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 993 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 1010 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 994 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1011 request.placeholderImageRequestType()); | 995 request.placeholderImageRequestType()); |
| 1012 EXPECT_EQ("bytes=0-2047", | 996 EXPECT_EQ("bytes=0-2047", |
| 1013 imageResource->resourceRequest().httpHeaderField("range")); | 997 imageResource->resourceRequest().httpHeaderField("range")); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1041 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 1025 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 1042 | 1026 |
| 1043 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1027 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 1044 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1028 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 1045 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1029 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 1046 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); | 1030 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1047 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage()); | 1031 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage()); |
| 1048 } | 1032 } |
| 1049 | 1033 |
| 1050 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { | 1034 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { |
| 1051 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1035 KURL testURL(ParsedURLString, kTestURL); |
| 1052 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1036 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1053 | 1037 |
| 1054 FetchRequest request(testURL, FetchInitiatorInfo()); | 1038 FetchRequest request(testURL, FetchInitiatorInfo()); |
| 1055 request.setAllowImagePlaceholder(); | 1039 request.setAllowImagePlaceholder(); |
| 1056 ImageResource* imageResource = ImageResource::fetch( | 1040 ImageResource* imageResource = ImageResource::fetch( |
| 1057 request, | 1041 request, |
| 1058 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); | 1042 ResourceFetcher::create(ImageResourceTestMockFetchContext::create())); |
| 1059 EXPECT_EQ(FetchRequest::AllowPlaceholder, | 1043 EXPECT_EQ(FetchRequest::AllowPlaceholder, |
| 1060 request.placeholderImageRequestType()); | 1044 request.placeholderImageRequestType()); |
| 1061 EXPECT_EQ("bytes=0-2047", | 1045 EXPECT_EQ("bytes=0-2047", |
| 1062 imageResource->resourceRequest().httpHeaderField("range")); | 1046 imageResource->resourceRequest().httpHeaderField("range")); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1086 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1103 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); | 1087 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); |
| 1104 | 1088 |
| 1105 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 1089 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 1106 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); | 1090 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
| 1107 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); | 1091 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
| 1108 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1092 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1109 } | 1093 } |
| 1110 | 1094 |
| 1111 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { | 1095 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { |
| 1112 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1096 KURL testURL(ParsedURLString, kTestURL); |
| 1113 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1097 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1114 | 1098 |
| 1115 ResourceFetcher* fetcher = | 1099 ResourceFetcher* fetcher = |
| 1116 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 1100 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 1117 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1101 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
| 1118 placeholderRequest.setAllowImagePlaceholder(); | 1102 placeholderRequest.setAllowImagePlaceholder(); |
| 1119 ImageResource* imageResource = | 1103 ImageResource* imageResource = |
| 1120 ImageResource::fetch(placeholderRequest, fetcher); | 1104 ImageResource::fetch(placeholderRequest, fetcher); |
| 1121 std::unique_ptr<MockImageResourceObserver> observer = | 1105 std::unique_ptr<MockImageResourceObserver> observer = |
| 1122 MockImageResourceObserver::create(imageResource->getContent()); | 1106 MockImageResourceObserver::create(imageResource->getContent()); |
| 1123 | 1107 |
| 1124 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); | 1108 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); |
| 1125 ImageResource* secondImageResource = | 1109 ImageResource* secondImageResource = |
| 1126 ImageResource::fetch(nonPlaceholderRequest, fetcher); | 1110 ImageResource::fetch(nonPlaceholderRequest, fetcher); |
| 1127 EXPECT_EQ(imageResource, secondImageResource); | 1111 EXPECT_EQ(imageResource, secondImageResource); |
| 1128 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); | 1112 EXPECT_EQ(ResourceStatus::Pending, imageResource->getStatus()); |
| 1129 EXPECT_FALSE(imageResource->isPlaceholder()); | 1113 EXPECT_FALSE(imageResource->isPlaceholder()); |
| 1130 EXPECT_EQ(nullAtom, | 1114 EXPECT_EQ(nullAtom, |
| 1131 imageResource->resourceRequest().httpHeaderField("range")); | 1115 imageResource->resourceRequest().httpHeaderField("range")); |
| 1132 EXPECT_EQ( | 1116 EXPECT_EQ( |
| 1133 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1117 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1134 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1118 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1135 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); | 1119 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 1136 | 1120 |
| 1137 imageResource->loader()->cancel(); | 1121 imageResource->loader()->cancel(); |
| 1138 } | 1122 } |
| 1139 | 1123 |
| 1140 TEST(ImageResourceTest, | 1124 TEST(ImageResourceTest, |
| 1141 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { | 1125 FetchAllowPlaceholderThenDisallowPlaceholderAfterLoaded) { |
| 1142 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1126 KURL testURL(ParsedURLString, kTestURL); |
| 1143 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1127 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1144 | 1128 |
| 1145 ResourceFetcher* fetcher = | 1129 ResourceFetcher* fetcher = |
| 1146 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 1130 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 1147 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1131 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
| 1148 placeholderRequest.setAllowImagePlaceholder(); | 1132 placeholderRequest.setAllowImagePlaceholder(); |
| 1149 ImageResource* imageResource = | 1133 ImageResource* imageResource = |
| 1150 ImageResource::fetch(placeholderRequest, fetcher); | 1134 ImageResource::fetch(placeholderRequest, fetcher); |
| 1151 std::unique_ptr<MockImageResourceObserver> observer = | 1135 std::unique_ptr<MockImageResourceObserver> observer = |
| 1152 MockImageResourceObserver::create(imageResource->getContent()); | 1136 MockImageResourceObserver::create(imageResource->getContent()); |
| 1153 | 1137 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 EXPECT_EQ( | 1169 EXPECT_EQ( |
| 1186 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1170 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1187 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1171 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1188 | 1172 |
| 1189 imageResource->loader()->cancel(); | 1173 imageResource->loader()->cancel(); |
| 1190 } | 1174 } |
| 1191 | 1175 |
| 1192 TEST(ImageResourceTest, PeriodicFlushTest) { | 1176 TEST(ImageResourceTest, PeriodicFlushTest) { |
| 1193 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> | 1177 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 1194 platform; | 1178 platform; |
| 1195 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1179 KURL testURL(ParsedURLString, kTestURL); |
| 1196 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1180 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); |
| 1197 ResourceRequest request = ResourceRequest(testURL); | 1181 ResourceRequest request = ResourceRequest(testURL); |
| 1198 ImageResource* imageResource = ImageResource::create(request); | 1182 ImageResource* imageResource = ImageResource::create(request); |
| 1199 imageResource->setStatus(ResourceStatus::Pending); | 1183 imageResource->setStatus(ResourceStatus::Pending); |
| 1200 | 1184 |
| 1201 std::unique_ptr<MockImageResourceObserver> observer = | 1185 std::unique_ptr<MockImageResourceObserver> observer = |
| 1202 MockImageResourceObserver::create(imageResource->getContent()); | 1186 MockImageResourceObserver::create(imageResource->getContent()); |
| 1203 | 1187 |
| 1204 // Send the image response. | 1188 // Send the image response. |
| 1205 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), | 1189 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), |
| 1206 nullAtom, String()); | 1190 nullAtom, String()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1254 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1271 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1255 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1256 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1273 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1257 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1274 | 1258 |
| 1275 WTF::setTimeFunctionsForTesting(nullptr); | 1259 WTF::setTimeFunctionsForTesting(nullptr); |
| 1276 } | 1260 } |
| 1277 | 1261 |
| 1278 } // namespace | 1262 } // namespace |
| 1279 } // namespace blink | 1263 } // namespace blink |
| OLD | NEW |