| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 nullAtom, String()); | 241 nullAtom, String()); |
| 242 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); | 242 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); |
| 243 cachedImage->loader()->didReceiveResponse( | 243 cachedImage->loader()->didReceiveResponse( |
| 244 WrappedResourceResponse(multipartResponse), nullptr); | 244 WrappedResourceResponse(multipartResponse), nullptr); |
| 245 EXPECT_FALSE(cachedImage->resourceBuffer()); | 245 EXPECT_FALSE(cachedImage->resourceBuffer()); |
| 246 EXPECT_FALSE(cachedImage->getContent()->hasImage()); | 246 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
| 247 EXPECT_EQ(0, client->imageChangedCount()); | 247 EXPECT_EQ(0, client->imageChangedCount()); |
| 248 EXPECT_FALSE(client->notifyFinishedCalled()); | 248 EXPECT_FALSE(client->notifyFinishedCalled()); |
| 249 EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType()); | 249 EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType()); |
| 250 | 250 |
| 251 const char firstPart[] = | 251 const char firstPartHeader[] = |
| 252 "--boundary\n" | 252 "--boundary\n" |
| 253 "Content-Type: image/svg+xml\n\n"; | 253 "Content-Type: image/svg+xml\n\n"; |
| 254 cachedImage->appendData(firstPart, strlen(firstPart)); | 254 cachedImage->appendData(firstPartHeader, strlen(firstPartHeader)); |
| 255 // Send the response for the first real part. No image or data buffer is | 255 // Send the response for the first real part. No image or data buffer is |
| 256 // created. | 256 // created. |
| 257 EXPECT_FALSE(cachedImage->resourceBuffer()); | 257 EXPECT_FALSE(cachedImage->resourceBuffer()); |
| 258 EXPECT_FALSE(cachedImage->getContent()->hasImage()); | 258 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
| 259 EXPECT_EQ(0, client->imageChangedCount()); | 259 EXPECT_EQ(0, client->imageChangedCount()); |
| 260 EXPECT_FALSE(client->notifyFinishedCalled()); | 260 EXPECT_FALSE(client->notifyFinishedCalled()); |
| 261 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); | 261 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); |
| 262 | 262 |
| 263 const char secondPart[] = | 263 const char firstPartBody[] = |
| 264 "<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect " | 264 "<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect " |
| 265 "width='1' height='1' fill='green'/></svg>\n"; | 265 "width='1' height='1' fill='green'/></svg>\n"; |
| 266 // The first bytes arrive. The data buffer is created, but no image is | 266 // The first bytes arrive. The data buffer is created, but no image is |
| 267 // created. | 267 // created. |
| 268 cachedImage->appendData(secondPart, strlen(secondPart)); | 268 cachedImage->appendData(firstPartBody, strlen(firstPartBody)); |
| 269 EXPECT_TRUE(cachedImage->resourceBuffer()); | 269 EXPECT_TRUE(cachedImage->resourceBuffer()); |
| 270 EXPECT_FALSE(cachedImage->getContent()->hasImage()); | 270 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
| 271 EXPECT_EQ(0, client->imageChangedCount()); | 271 EXPECT_EQ(0, client->imageChangedCount()); |
| 272 EXPECT_FALSE(client->notifyFinishedCalled()); | 272 EXPECT_FALSE(client->notifyFinishedCalled()); |
| 273 | 273 |
| 274 // Add a client to check an assertion error doesn't happen | 274 // Add a client to check an assertion error doesn't happen |
| 275 // (crbug.com/630983). | 275 // (crbug.com/630983). |
| 276 Persistent<MockImageResourceClient> client2 = | 276 Persistent<MockImageResourceClient> client2 = |
| 277 new MockImageResourceClient(cachedImage); | 277 new MockImageResourceClient(cachedImage); |
| 278 EXPECT_EQ(0, client2->imageChangedCount()); | 278 EXPECT_EQ(0, client2->imageChangedCount()); |
| 279 EXPECT_FALSE(client2->notifyFinishedCalled()); | 279 EXPECT_FALSE(client2->notifyFinishedCalled()); |
| 280 | 280 |
| 281 const char thirdPart[] = "--boundary"; | 281 const char secondPartHeader[] = |
| 282 cachedImage->appendData(thirdPart, strlen(thirdPart)); | 282 "--boundary\n" |
| 283 "Content-Type: image/jpeg\n\n"; |
| 284 cachedImage->appendData(secondPartHeader, strlen(secondPartHeader)); |
| 283 ASSERT_TRUE(cachedImage->resourceBuffer()); | 285 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 284 EXPECT_EQ(strlen(secondPart) - 1, cachedImage->resourceBuffer()->size()); | 286 EXPECT_EQ(strlen(firstPartBody) - 1, cachedImage->resourceBuffer()->size()); |
| 285 | 287 // The first part finishes. |
| 286 // This part finishes. The image is created, callbacks are sent, and the data | 288 // The image is created, callbacks are sent, and the data buffer is cleared. |
| 287 // buffer is cleared. | |
| 288 cachedImage->loader()->didFinishLoading(0.0, 0, 0); | |
| 289 EXPECT_TRUE(cachedImage->resourceBuffer()); | 289 EXPECT_TRUE(cachedImage->resourceBuffer()); |
| 290 EXPECT_FALSE(cachedImage->errorOccurred()); | 290 EXPECT_FALSE(cachedImage->errorOccurred()); |
| 291 ASSERT_TRUE(cachedImage->getContent()->hasImage()); | 291 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
| 292 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); | 292 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
| 293 EXPECT_EQ(1, cachedImage->getContent()->getImage()->width()); | 293 EXPECT_EQ(1, cachedImage->getContent()->getImage()->width()); |
| 294 EXPECT_EQ(1, cachedImage->getContent()->getImage()->height()); | 294 EXPECT_EQ(1, cachedImage->getContent()->getImage()->height()); |
| 295 EXPECT_EQ(1, client->imageChangedCount()); | 295 EXPECT_EQ(1, client->imageChangedCount()); |
| 296 EXPECT_TRUE(client->notifyFinishedCalled()); | 296 EXPECT_TRUE(client->notifyFinishedCalled()); |
| 297 EXPECT_EQ(1, client2->imageChangedCount()); | 297 EXPECT_EQ(1, client2->imageChangedCount()); |
| 298 EXPECT_TRUE(client2->notifyFinishedCalled()); | 298 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 299 |
| 300 // The body of the second part arrives. |
| 301 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2), |
| 302 sizeof(kJpegImage2)); |
| 303 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 304 |
| 305 // The last boundary arrives. |
| 306 // The second part is processed. |
| 307 const char lastBoundary[] = "\n--boundary"; |
| 308 cachedImage->appendData(lastBoundary, strlen(lastBoundary)); |
| 309 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 310 EXPECT_EQ(sizeof(kJpegImage2), cachedImage->resourceBuffer()->size()); |
| 311 |
| 312 // Load finishes. |
| 313 cachedImage->loader()->didFinishLoading(0.0, 0, 0); |
| 314 |
| 315 EXPECT_FALSE(cachedImage->errorOccurred()); |
| 316 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
| 317 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
| 318 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
| 319 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
| 320 EXPECT_EQ(2, client->imageChangedCount()); |
| 321 EXPECT_EQ(2, client2->imageChangedCount()); |
| 299 } | 322 } |
| 300 | 323 |
| 301 TEST(ImageResourceTest, CancelOnDetach) { | 324 TEST(ImageResourceTest, CancelOnDetach) { |
| 302 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 325 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 303 ScopedRegisteredURL scopedRegisteredURL(testURL); | 326 ScopedRegisteredURL scopedRegisteredURL(testURL); |
| 304 | 327 |
| 305 ResourceFetcher* fetcher = | 328 ResourceFetcher* fetcher = |
| 306 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 329 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
| 307 | 330 |
| 308 // Emulate starting a real load. | 331 // Emulate starting a real load. |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 EXPECT_TRUE(client->notifyFinishedCalled()); | 1228 EXPECT_TRUE(client->notifyFinishedCalled()); |
| 1206 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); | 1229 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
| 1207 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); | 1230 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
| 1208 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); | 1231 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
| 1209 | 1232 |
| 1210 WTF::setTimeFunctionsForTesting(nullptr); | 1233 WTF::setTimeFunctionsForTesting(nullptr); |
| 1211 } | 1234 } |
| 1212 | 1235 |
| 1213 } // namespace | 1236 } // namespace |
| 1214 } // namespace blink | 1237 } // namespace blink |
| OLD | NEW |