| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); | 122 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); |
| 123 ASSERT_FALSE(cachedImage->hasImage()); | 123 ASSERT_FALSE(cachedImage->hasImage()); |
| 124 ASSERT_EQ(client.imageChangedCount(), 0); | 124 ASSERT_EQ(client.imageChangedCount(), 0); |
| 125 ASSERT_FALSE(client.notifyFinishedCalled()); | 125 ASSERT_FALSE(client.notifyFinishedCalled()); |
| 126 | 126 |
| 127 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. | 127 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. |
| 128 cachedImage->finish(); | 128 cachedImage->finish(); |
| 129 ASSERT_FALSE(cachedImage->resourceBuffer()); | 129 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 130 ASSERT_FALSE(cachedImage->errorOccurred()); | 130 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 131 ASSERT_TRUE(cachedImage->hasImage()); | 131 ASSERT_TRUE(cachedImage->hasImage()); |
| 132 ASSERT_FALSE(cachedImage->image()->isNull()); | 132 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 133 ASSERT_EQ(cachedImage->image()->width(), 1); | 133 ASSERT_EQ(cachedImage->getImage()->width(), 1); |
| 134 ASSERT_EQ(cachedImage->image()->height(), 1); | 134 ASSERT_EQ(cachedImage->getImage()->height(), 1); |
| 135 ASSERT_EQ(client.imageChangedCount(), 1); | 135 ASSERT_EQ(client.imageChangedCount(), 1); |
| 136 ASSERT_TRUE(client.notifyFinishedCalled()); | 136 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST(ImageResourceTest, CancelOnDetach) | 139 TEST(ImageResourceTest, CancelOnDetach) |
| 140 { | 140 { |
| 141 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 141 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 142 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 142 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 143 | 143 |
| 144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 144 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 175 | 175 |
| 176 // Send the image response. | 176 // Send the image response. |
| 177 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); | 177 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); |
| 178 | 178 |
| 179 Vector<unsigned char> jpeg = jpegImage(); | 179 Vector<unsigned char> jpeg = jpegImage(); |
| 180 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 180 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
| 181 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 181 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 182 cachedImage->finish(); | 182 cachedImage->finish(); |
| 183 ASSERT_FALSE(cachedImage->errorOccurred()); | 183 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 184 ASSERT_TRUE(cachedImage->hasImage()); | 184 ASSERT_TRUE(cachedImage->hasImage()); |
| 185 ASSERT_FALSE(cachedImage->image()->isNull()); | 185 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 186 ASSERT_TRUE(client.notifyFinishedCalled()); | 186 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 187 | 187 |
| 188 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 188 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
| 189 cachedImage->prune(); | 189 cachedImage->prune(); |
| 190 ASSERT_TRUE(cachedImage->hasClients()); | 190 ASSERT_TRUE(cachedImage->hasClients()); |
| 191 ASSERT_TRUE(cachedImage->hasImage()); | 191 ASSERT_TRUE(cachedImage->hasImage()); |
| 192 ASSERT_FALSE(cachedImage->image()->isNull()); | 192 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 193 | 193 |
| 194 // The ImageResource no longer has clients. The image should be deleted by p
rune. | 194 // The ImageResource no longer has clients. The image should be deleted by p
rune. |
| 195 client.removeAsClient(); | 195 client.removeAsClient(); |
| 196 cachedImage->prune(); | 196 cachedImage->prune(); |
| 197 ASSERT_FALSE(cachedImage->hasClients()); | 197 ASSERT_FALSE(cachedImage->hasClients()); |
| 198 ASSERT_FALSE(cachedImage->hasImage()); | 198 ASSERT_FALSE(cachedImage->hasImage()); |
| 199 ASSERT_TRUE(cachedImage->image()->isNull()); | 199 ASSERT_TRUE(cachedImage->getImage()->isNull()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST(ImageResourceTest, UpdateBitmapImages) | 202 TEST(ImageResourceTest, UpdateBitmapImages) |
| 203 { | 203 { |
| 204 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 204 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
| 205 cachedImage->setLoading(true); | 205 cachedImage->setLoading(true); |
| 206 | 206 |
| 207 MockImageResourceClient client(cachedImage); | 207 MockImageResourceClient client(cachedImage); |
| 208 | 208 |
| 209 // Send the image response. | 209 // Send the image response. |
| 210 Vector<unsigned char> jpeg = jpegImage(); | 210 Vector<unsigned char> jpeg = jpegImage(); |
| 211 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 211 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
| 212 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 212 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 213 cachedImage->finish(); | 213 cachedImage->finish(); |
| 214 ASSERT_FALSE(cachedImage->errorOccurred()); | 214 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 215 ASSERT_TRUE(cachedImage->hasImage()); | 215 ASSERT_TRUE(cachedImage->hasImage()); |
| 216 ASSERT_FALSE(cachedImage->image()->isNull()); | 216 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 217 ASSERT_EQ(client.imageChangedCount(), 2); | 217 ASSERT_EQ(client.imageChangedCount(), 2); |
| 218 ASSERT_TRUE(client.notifyFinishedCalled()); | 218 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 219 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 219 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 TEST(ImageResourceTest, ReloadIfLoFi) | 222 TEST(ImageResourceTest, ReloadIfLoFi) |
| 223 { | 223 { |
| 224 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 224 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 225 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 225 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
| 226 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); | 226 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(testURL), nullptr); |
| 227 cachedImage->setLoading(true); | 227 cachedImage->setLoading(true); |
| 228 | 228 |
| 229 MockImageResourceClient client(cachedImage); | 229 MockImageResourceClient client(cachedImage); |
| 230 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 230 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
| 231 | 231 |
| 232 // Send the image response. | 232 // Send the image response. |
| 233 Vector<unsigned char> jpeg = jpegImage(); | 233 Vector<unsigned char> jpeg = jpegImage(); |
| 234 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); | 234 ResourceResponse resourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAto
m, String()); |
| 235 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 235 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
| 236 | 236 |
| 237 cachedImage->responseReceived(resourceResponse, nullptr); | 237 cachedImage->responseReceived(resourceResponse, nullptr); |
| 238 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 238 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 239 cachedImage->finish(); | 239 cachedImage->finish(); |
| 240 ASSERT_FALSE(cachedImage->errorOccurred()); | 240 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 241 ASSERT_TRUE(cachedImage->hasImage()); | 241 ASSERT_TRUE(cachedImage->hasImage()); |
| 242 ASSERT_FALSE(cachedImage->image()->isNull()); | 242 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 243 ASSERT_EQ(client.imageChangedCount(), 2); | 243 ASSERT_EQ(client.imageChangedCount(), 2); |
| 244 ASSERT_TRUE(client.notifyFinishedCalled()); | 244 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 245 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 245 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 246 | 246 |
| 247 cachedImage->reloadIfLoFi(fetcher); | 247 cachedImage->reloadIfLoFi(fetcher); |
| 248 ASSERT_FALSE(cachedImage->errorOccurred()); | 248 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 249 ASSERT_FALSE(cachedImage->resourceBuffer()); | 249 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 250 ASSERT_FALSE(cachedImage->hasImage()); | 250 ASSERT_FALSE(cachedImage->hasImage()); |
| 251 ASSERT_EQ(client.imageChangedCount(), 3); | 251 ASSERT_EQ(client.imageChangedCount(), 3); |
| 252 | 252 |
| 253 cachedImage->responseReceived(resourceResponse, nullptr); | 253 cachedImage->responseReceived(resourceResponse, nullptr); |
| 254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 254 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 255 cachedImage->finish(); | 255 cachedImage->finish(); |
| 256 ASSERT_FALSE(cachedImage->errorOccurred()); | 256 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 257 ASSERT_TRUE(cachedImage->hasImage()); | 257 ASSERT_TRUE(cachedImage->hasImage()); |
| 258 ASSERT_FALSE(cachedImage->image()->isNull()); | 258 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 259 ASSERT_TRUE(client.notifyFinishedCalled()); | 259 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 260 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 260 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace blink | 263 } // namespace blink |
| OLD | NEW |