| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4,
0x00, 0x14, 0x11, | 73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4,
0x00, 0x14, 0x11, |
| 74 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, | 74 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, |
| 75 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03,
0x11, 0x00, 0x3f, | 75 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03,
0x11, 0x00, 0x3f, |
| 76 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 | 76 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 jpeg.append(data, sizeof(data)); | 79 jpeg.append(data, sizeof(data)); |
| 80 return jpeg; | 80 return jpeg; |
| 81 } | 81 } |
| 82 | 82 |
| 83 namespace { |
| 84 |
| 85 class MockTaskRunner : public blink::WebTaskRunner { |
| 86 void postTask(const WebTraceLocation&, Task*) override { } |
| 87 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } |
| 88 WebTaskRunner* clone() override { return nullptr; } |
| 89 double virtualTimeSeconds() const override { return 0.0; } |
| 90 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0
.0; } |
| 91 }; |
| 92 |
| 93 } |
| 94 |
| 95 class ImageResourceTestMockFetchContext : public FetchContext { |
| 96 public: |
| 97 static ImageResourceTestMockFetchContext* create() |
| 98 { |
| 99 return new ImageResourceTestMockFetchContext; |
| 100 } |
| 101 |
| 102 virtual ~ImageResourceTestMockFetchContext() { } |
| 103 |
| 104 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } |
| 105 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } |
| 106 bool shouldLoadNewResource(Resource::Type) const override { return true; } |
| 107 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } |
| 108 |
| 109 private: |
| 110 ImageResourceTestMockFetchContext() |
| 111 : m_runner(adoptPtr(new MockTaskRunner)) |
| 112 { } |
| 113 |
| 114 OwnPtr<MockTaskRunner> m_runner; |
| 115 }; |
| 116 |
| 83 TEST(ImageResourceTest, MultipartImage) | 117 TEST(ImageResourceTest, MultipartImage) |
| 84 { | 118 { |
| 85 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 119 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 86 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 120 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 87 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 121 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 88 | 122 |
| 89 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. | 123 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. |
| 90 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 124 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
| 91 cachedImage->setIdentifier(createUniqueIdentifier()); | 125 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 92 cachedImage->load(fetcher); | 126 cachedImage->load(fetcher); |
| 93 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); | 127 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); |
| 94 | 128 |
| 95 MockImageResourceClient client(cachedImage); | 129 MockImageResourceClient client(cachedImage); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ASSERT_EQ(cachedImage->getImage()->height(), 1); | 175 ASSERT_EQ(cachedImage->getImage()->height(), 1); |
| 142 ASSERT_EQ(client.imageChangedCount(), 1); | 176 ASSERT_EQ(client.imageChangedCount(), 1); |
| 143 ASSERT_TRUE(client.notifyFinishedCalled()); | 177 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 144 } | 178 } |
| 145 | 179 |
| 146 TEST(ImageResourceTest, CancelOnDetach) | 180 TEST(ImageResourceTest, CancelOnDetach) |
| 147 { | 181 { |
| 148 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 182 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 149 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 183 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 150 | 184 |
| 151 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 185 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 152 | 186 |
| 153 // Emulate starting a real load. | 187 // Emulate starting a real load. |
| 154 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 188 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
| 155 cachedImage->setIdentifier(createUniqueIdentifier()); | 189 cachedImage->setIdentifier(createUniqueIdentifier()); |
| 156 | 190 |
| 157 cachedImage->load(fetcher); | 191 cachedImage->load(fetcher); |
| 158 memoryCache()->add(cachedImage); | 192 memoryCache()->add(cachedImage); |
| 159 | 193 |
| 160 MockImageResourceClient client(cachedImage); | 194 MockImageResourceClient client(cachedImage); |
| 161 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); | 195 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 261 } |
| 228 | 262 |
| 229 TEST(ImageResourceTest, ReloadIfLoFi) | 263 TEST(ImageResourceTest, ReloadIfLoFi) |
| 230 { | 264 { |
| 231 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 265 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 232 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 266 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 233 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 267 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
| 234 cachedImage->setStatus(Resource::Pending); | 268 cachedImage->setStatus(Resource::Pending); |
| 235 | 269 |
| 236 MockImageResourceClient client(cachedImage); | 270 MockImageResourceClient client(cachedImage); |
| 237 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 271 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
| 238 | 272 |
| 239 // Send the image response. | 273 // Send the image response. |
| 240 Vector<unsigned char> jpeg = jpegImage(); | 274 Vector<unsigned char> jpeg = jpegImage(); |
| 241 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); | 275 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); |
| 242 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 276 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 243 | 277 |
| 244 cachedImage->responseReceived(resourceResponse, nullptr); | 278 cachedImage->responseReceived(resourceResponse, nullptr); |
| 245 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 279 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 246 cachedImage->finish(); | 280 cachedImage->finish(); |
| 247 ASSERT_FALSE(cachedImage->errorOccurred()); | 281 ASSERT_FALSE(cachedImage->errorOccurred()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 295 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 262 cachedImage->finish(); | 296 cachedImage->finish(); |
| 263 ASSERT_FALSE(cachedImage->errorOccurred()); | 297 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 264 ASSERT_TRUE(cachedImage->hasImage()); | 298 ASSERT_TRUE(cachedImage->hasImage()); |
| 265 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 299 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 266 ASSERT_TRUE(client.notifyFinishedCalled()); | 300 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 301 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 268 } | 302 } |
| 269 | 303 |
| 270 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |