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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 blink::testing::runPendingTasks(); | 166 blink::testing::runPendingTasks(); |
167 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); | 167 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); |
168 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); | 168 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test
URL)); |
169 | 169 |
170 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | 170 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); |
171 } | 171 } |
172 | 172 |
173 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) | 173 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) |
174 { | 174 { |
175 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 175 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
176 cachedImage->setLoading(true); | 176 cachedImage->setStatus(Resource::Pending); |
177 | 177 |
178 MockImageResourceClient client(cachedImage); | 178 MockImageResourceClient client(cachedImage); |
179 | 179 |
180 // Send the image response. | 180 // Send the image response. |
181 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); | 181 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); |
182 | 182 |
183 Vector<unsigned char> jpeg = jpegImage(); | 183 Vector<unsigned char> jpeg = jpegImage(); |
184 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 184 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
185 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 185 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
186 cachedImage->finish(); | 186 cachedImage->finish(); |
(...skipping 12 matching lines...) Expand all Loading... |
199 client.removeAsClient(); | 199 client.removeAsClient(); |
200 cachedImage->prune(); | 200 cachedImage->prune(); |
201 ASSERT_FALSE(cachedImage->hasClients()); | 201 ASSERT_FALSE(cachedImage->hasClients()); |
202 ASSERT_FALSE(cachedImage->hasImage()); | 202 ASSERT_FALSE(cachedImage->hasImage()); |
203 ASSERT_TRUE(cachedImage->getImage()->isNull()); | 203 ASSERT_TRUE(cachedImage->getImage()->isNull()); |
204 } | 204 } |
205 | 205 |
206 TEST(ImageResourceTest, UpdateBitmapImages) | 206 TEST(ImageResourceTest, UpdateBitmapImages) |
207 { | 207 { |
208 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 208 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
209 cachedImage->setLoading(true); | 209 cachedImage->setStatus(Resource::Pending); |
210 | 210 |
211 MockImageResourceClient client(cachedImage); | 211 MockImageResourceClient client(cachedImage); |
212 | 212 |
213 // Send the image response. | 213 // Send the image response. |
214 Vector<unsigned char> jpeg = jpegImage(); | 214 Vector<unsigned char> jpeg = jpegImage(); |
215 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 215 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
216 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 216 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
217 cachedImage->finish(); | 217 cachedImage->finish(); |
218 ASSERT_FALSE(cachedImage->errorOccurred()); | 218 ASSERT_FALSE(cachedImage->errorOccurred()); |
219 ASSERT_TRUE(cachedImage->hasImage()); | 219 ASSERT_TRUE(cachedImage->hasImage()); |
220 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 220 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
221 ASSERT_EQ(client.imageChangedCount(), 2); | 221 ASSERT_EQ(client.imageChangedCount(), 2); |
222 ASSERT_TRUE(client.notifyFinishedCalled()); | 222 ASSERT_TRUE(client.notifyFinishedCalled()); |
223 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 223 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
224 } | 224 } |
225 | 225 |
226 TEST(ImageResourceTest, ReloadIfLoFi) | 226 TEST(ImageResourceTest, ReloadIfLoFi) |
227 { | 227 { |
228 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 228 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
229 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 229 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
230 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); | 230 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); |
231 cachedImage->setLoading(true); | 231 cachedImage->setStatus(Resource::Pending); |
232 | 232 |
233 MockImageResourceClient client(cachedImage); | 233 MockImageResourceClient client(cachedImage); |
234 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 234 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
235 | 235 |
236 // Send the image response. | 236 // Send the image response. |
237 Vector<unsigned char> jpeg = jpegImage(); | 237 Vector<unsigned char> jpeg = jpegImage(); |
238 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); | 238 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); |
239 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 239 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
240 | 240 |
241 cachedImage->responseReceived(resourceResponse, nullptr); | 241 cachedImage->responseReceived(resourceResponse, nullptr); |
(...skipping 16 matching lines...) Expand all Loading... |
258 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 258 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
259 cachedImage->finish(); | 259 cachedImage->finish(); |
260 ASSERT_FALSE(cachedImage->errorOccurred()); | 260 ASSERT_FALSE(cachedImage->errorOccurred()); |
261 ASSERT_TRUE(cachedImage->hasImage()); | 261 ASSERT_TRUE(cachedImage->hasImage()); |
262 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 262 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
263 ASSERT_TRUE(client.notifyFinishedCalled()); | 263 ASSERT_TRUE(client.notifyFinishedCalled()); |
264 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 264 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
265 } | 265 } |
266 | 266 |
267 } // namespace blink | 267 } // namespace blink |
OLD | NEW |