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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 // Send the multipart response. No image or data buffer is created. Note that | 236 // Send the multipart response. No image or data buffer is created. Note that |
237 // the response must be routed through ResourceLoader to ensure the load is | 237 // the response must be routed through ResourceLoader to ensure the load is |
238 // flagged as multipart. | 238 // flagged as multipart. |
239 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, | 239 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, |
240 nullAtom, String()); | 240 nullAtom, String()); |
241 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); | 241 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); |
242 cachedImage->loader()->didReceiveResponse( | 242 cachedImage->loader()->didReceiveResponse( |
243 WrappedResourceResponse(multipartResponse), nullptr); | 243 WrappedResourceResponse(multipartResponse), nullptr); |
244 EXPECT_FALSE(cachedImage->resourceBuffer()); | 244 EXPECT_FALSE(cachedImage->resourceBuffer()); |
245 EXPECT_FALSE(cachedImage->hasImage()); | 245 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
246 EXPECT_EQ(0, client->imageChangedCount()); | 246 EXPECT_EQ(0, client->imageChangedCount()); |
247 EXPECT_FALSE(client->notifyFinishedCalled()); | 247 EXPECT_FALSE(client->notifyFinishedCalled()); |
248 EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType()); | 248 EXPECT_EQ("multipart/x-mixed-replace", cachedImage->response().mimeType()); |
249 | 249 |
250 const char firstPart[] = | 250 const char firstPart[] = |
251 "--boundary\n" | 251 "--boundary\n" |
252 "Content-Type: image/svg+xml\n\n"; | 252 "Content-Type: image/svg+xml\n\n"; |
253 cachedImage->appendData(firstPart, strlen(firstPart)); | 253 cachedImage->appendData(firstPart, strlen(firstPart)); |
254 // Send the response for the first real part. No image or data buffer is | 254 // Send the response for the first real part. No image or data buffer is |
255 // created. | 255 // created. |
256 EXPECT_FALSE(cachedImage->resourceBuffer()); | 256 EXPECT_FALSE(cachedImage->resourceBuffer()); |
257 EXPECT_FALSE(cachedImage->hasImage()); | 257 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
258 EXPECT_EQ(0, client->imageChangedCount()); | 258 EXPECT_EQ(0, client->imageChangedCount()); |
259 EXPECT_FALSE(client->notifyFinishedCalled()); | 259 EXPECT_FALSE(client->notifyFinishedCalled()); |
260 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); | 260 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); |
261 | 261 |
262 const char secondPart[] = | 262 const char secondPart[] = |
263 "<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect " | 263 "<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect " |
264 "width='1' height='1' fill='green'/></svg>\n"; | 264 "width='1' height='1' fill='green'/></svg>\n"; |
265 // The first bytes arrive. The data buffer is created, but no image is | 265 // The first bytes arrive. The data buffer is created, but no image is |
266 // created. | 266 // created. |
267 cachedImage->appendData(secondPart, strlen(secondPart)); | 267 cachedImage->appendData(secondPart, strlen(secondPart)); |
268 EXPECT_TRUE(cachedImage->resourceBuffer()); | 268 EXPECT_TRUE(cachedImage->resourceBuffer()); |
269 EXPECT_FALSE(cachedImage->hasImage()); | 269 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
270 EXPECT_EQ(0, client->imageChangedCount()); | 270 EXPECT_EQ(0, client->imageChangedCount()); |
271 EXPECT_FALSE(client->notifyFinishedCalled()); | 271 EXPECT_FALSE(client->notifyFinishedCalled()); |
272 | 272 |
273 // Add a client to check an assertion error doesn't happen | 273 // Add a client to check an assertion error doesn't happen |
274 // (crbug.com/630983). | 274 // (crbug.com/630983). |
275 Persistent<MockImageResourceClient> client2 = | 275 Persistent<MockImageResourceClient> client2 = |
276 new MockImageResourceClient(cachedImage); | 276 new MockImageResourceClient(cachedImage); |
277 EXPECT_EQ(0, client2->imageChangedCount()); | 277 EXPECT_EQ(0, client2->imageChangedCount()); |
278 EXPECT_FALSE(client2->notifyFinishedCalled()); | 278 EXPECT_FALSE(client2->notifyFinishedCalled()); |
279 | 279 |
280 const char thirdPart[] = "--boundary"; | 280 const char thirdPart[] = "--boundary"; |
281 cachedImage->appendData(thirdPart, strlen(thirdPart)); | 281 cachedImage->appendData(thirdPart, strlen(thirdPart)); |
282 ASSERT_TRUE(cachedImage->resourceBuffer()); | 282 ASSERT_TRUE(cachedImage->resourceBuffer()); |
283 EXPECT_EQ(strlen(secondPart) - 1, cachedImage->resourceBuffer()->size()); | 283 EXPECT_EQ(strlen(secondPart) - 1, cachedImage->resourceBuffer()->size()); |
284 | 284 |
285 // This part finishes. The image is created, callbacks are sent, and the data | 285 // This part finishes. The image is created, callbacks are sent, and the data |
286 // buffer is cleared. | 286 // buffer is cleared. |
287 cachedImage->loader()->didFinishLoading(0.0, 0, 0); | 287 cachedImage->loader()->didFinishLoading(0.0, 0, 0); |
288 EXPECT_TRUE(cachedImage->resourceBuffer()); | 288 EXPECT_TRUE(cachedImage->resourceBuffer()); |
289 EXPECT_FALSE(cachedImage->errorOccurred()); | 289 EXPECT_FALSE(cachedImage->errorOccurred()); |
290 ASSERT_TRUE(cachedImage->hasImage()); | 290 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
291 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 291 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
292 EXPECT_EQ(1, cachedImage->getImage()->width()); | 292 EXPECT_EQ(1, cachedImage->getContent()->getImage()->width()); |
293 EXPECT_EQ(1, cachedImage->getImage()->height()); | 293 EXPECT_EQ(1, cachedImage->getContent()->getImage()->height()); |
294 EXPECT_EQ(1, client->imageChangedCount()); | 294 EXPECT_EQ(1, client->imageChangedCount()); |
295 EXPECT_TRUE(client->notifyFinishedCalled()); | 295 EXPECT_TRUE(client->notifyFinishedCalled()); |
296 EXPECT_EQ(1, client2->imageChangedCount()); | 296 EXPECT_EQ(1, client2->imageChangedCount()); |
297 EXPECT_TRUE(client2->notifyFinishedCalled()); | 297 EXPECT_TRUE(client2->notifyFinishedCalled()); |
298 } | 298 } |
299 | 299 |
300 TEST(ImageResourceTest, CancelOnDetach) { | 300 TEST(ImageResourceTest, CancelOnDetach) { |
301 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 301 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
302 ScopedRegisteredURL scopedRegisteredURL(testURL); | 302 ScopedRegisteredURL scopedRegisteredURL(testURL); |
303 | 303 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 cachedImage->responseReceived( | 344 cachedImage->responseReceived( |
345 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, | 345 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, |
346 String()), | 346 String()), |
347 nullptr); | 347 nullptr); |
348 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), | 348 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), |
349 sizeof(kJpegImage)); | 349 sizeof(kJpegImage)); |
350 EXPECT_NE(0u, cachedImage->encodedSizeMemoryUsageForTesting()); | 350 EXPECT_NE(0u, cachedImage->encodedSizeMemoryUsageForTesting()); |
351 cachedImage->finish(); | 351 cachedImage->finish(); |
352 EXPECT_EQ(0u, cachedImage->encodedSizeMemoryUsageForTesting()); | 352 EXPECT_EQ(0u, cachedImage->encodedSizeMemoryUsageForTesting()); |
353 EXPECT_FALSE(cachedImage->errorOccurred()); | 353 EXPECT_FALSE(cachedImage->errorOccurred()); |
354 ASSERT_TRUE(cachedImage->hasImage()); | 354 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
355 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 355 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
356 EXPECT_TRUE(client->notifyFinishedCalled()); | 356 EXPECT_TRUE(client->notifyFinishedCalled()); |
357 | 357 |
358 // The prune comes when the ImageResource still has clients. The image should | 358 // The prune comes when the ImageResource still has clients. The image should |
359 // not be deleted. | 359 // not be deleted. |
360 cachedImage->prune(); | 360 cachedImage->prune(); |
361 EXPECT_TRUE(cachedImage->isAlive()); | 361 EXPECT_TRUE(cachedImage->isAlive()); |
362 ASSERT_TRUE(cachedImage->hasImage()); | 362 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
363 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 363 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
364 | 364 |
365 // The ImageResource no longer has clients. The decoded image data should be | 365 // The ImageResource no longer has clients. The decoded image data should be |
366 // deleted by prune. | 366 // deleted by prune. |
367 client->removeAsClient(); | 367 client->removeAsClient(); |
368 cachedImage->prune(); | 368 cachedImage->prune(); |
369 EXPECT_FALSE(cachedImage->isAlive()); | 369 EXPECT_FALSE(cachedImage->isAlive()); |
370 EXPECT_TRUE(cachedImage->hasImage()); | 370 EXPECT_TRUE(cachedImage->getContent()->hasImage()); |
371 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image | 371 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image |
372 // data. | 372 // data. |
373 } | 373 } |
374 | 374 |
375 TEST(ImageResourceTest, UpdateBitmapImages) { | 375 TEST(ImageResourceTest, UpdateBitmapImages) { |
376 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); | 376 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); |
377 cachedImage->setStatus(Resource::Pending); | 377 cachedImage->setStatus(Resource::Pending); |
378 | 378 |
379 Persistent<MockImageResourceClient> client = | 379 Persistent<MockImageResourceClient> client = |
380 new MockImageResourceClient(cachedImage); | 380 new MockImageResourceClient(cachedImage); |
381 | 381 |
382 // Send the image response. | 382 // Send the image response. |
383 cachedImage->responseReceived( | 383 cachedImage->responseReceived( |
384 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, | 384 ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom, |
385 String()), | 385 String()), |
386 nullptr); | 386 nullptr); |
387 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), | 387 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), |
388 sizeof(kJpegImage)); | 388 sizeof(kJpegImage)); |
389 cachedImage->finish(); | 389 cachedImage->finish(); |
390 EXPECT_FALSE(cachedImage->errorOccurred()); | 390 EXPECT_FALSE(cachedImage->errorOccurred()); |
391 ASSERT_TRUE(cachedImage->hasImage()); | 391 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
392 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 392 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
393 EXPECT_EQ(2, client->imageChangedCount()); | 393 EXPECT_EQ(2, client->imageChangedCount()); |
394 EXPECT_TRUE(client->notifyFinishedCalled()); | 394 EXPECT_TRUE(client->notifyFinishedCalled()); |
395 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 395 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
396 } | 396 } |
397 | 397 |
398 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { | 398 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) { |
399 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 399 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
400 ScopedRegisteredURL scopedRegisteredURL(testURL); | 400 ScopedRegisteredURL scopedRegisteredURL(testURL); |
401 ResourceRequest request = ResourceRequest(testURL); | 401 ResourceRequest request = ResourceRequest(testURL); |
402 request.setLoFiState(WebURLRequest::LoFiOn); | 402 request.setLoFiState(WebURLRequest::LoFiOn); |
403 ImageResource* cachedImage = ImageResource::create(request); | 403 ImageResource* cachedImage = ImageResource::create(request); |
404 cachedImage->setStatus(Resource::Pending); | 404 cachedImage->setStatus(Resource::Pending); |
405 | 405 |
406 Persistent<MockImageResourceClient> client = | 406 Persistent<MockImageResourceClient> client = |
407 new MockImageResourceClient(cachedImage); | 407 new MockImageResourceClient(cachedImage); |
408 ResourceFetcher* fetcher = | 408 ResourceFetcher* fetcher = |
409 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 409 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
410 | 410 |
411 // Send the image response. | 411 // Send the image response. |
412 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), | 412 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), |
413 nullAtom, String()); | 413 nullAtom, String()); |
414 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", | 414 resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform", |
415 "empty-image"); | 415 "empty-image"); |
416 | 416 |
417 cachedImage->responseReceived(resourceResponse, nullptr); | 417 cachedImage->responseReceived(resourceResponse, nullptr); |
418 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), | 418 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage), |
419 sizeof(kJpegImage)); | 419 sizeof(kJpegImage)); |
420 cachedImage->finish(); | 420 cachedImage->finish(); |
421 EXPECT_FALSE(cachedImage->errorOccurred()); | 421 EXPECT_FALSE(cachedImage->errorOccurred()); |
422 ASSERT_TRUE(cachedImage->hasImage()); | 422 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
423 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 423 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
424 EXPECT_EQ(2, client->imageChangedCount()); | 424 EXPECT_EQ(2, client->imageChangedCount()); |
425 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 425 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
426 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 426 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
427 // The client should have been notified that the image load completed. | 427 // The client should have been notified that the image load completed. |
428 EXPECT_TRUE(client->notifyFinishedCalled()); | 428 EXPECT_TRUE(client->notifyFinishedCalled()); |
429 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); | 429 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); |
430 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); | 430 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); |
431 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 431 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
432 EXPECT_EQ(1, cachedImage->getImage()->width()); | 432 EXPECT_EQ(1, cachedImage->getContent()->getImage()->width()); |
433 EXPECT_EQ(1, cachedImage->getImage()->height()); | 433 EXPECT_EQ(1, cachedImage->getContent()->getImage()->height()); |
434 | 434 |
435 // Call reloadIfLoFiOrPlaceholder() after the image has finished loading. | 435 // Call reloadIfLoFiOrPlaceholder() after the image has finished loading. |
436 cachedImage->reloadIfLoFiOrPlaceholder(fetcher); | 436 cachedImage->reloadIfLoFiOrPlaceholder(fetcher); |
437 EXPECT_FALSE(cachedImage->errorOccurred()); | 437 EXPECT_FALSE(cachedImage->errorOccurred()); |
438 EXPECT_FALSE(cachedImage->resourceBuffer()); | 438 EXPECT_FALSE(cachedImage->resourceBuffer()); |
439 EXPECT_FALSE(cachedImage->hasImage()); | 439 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
440 EXPECT_EQ(3, client->imageChangedCount()); | 440 EXPECT_EQ(3, client->imageChangedCount()); |
441 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 441 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
442 | 442 |
443 cachedImage->loader()->didReceiveResponse( | 443 cachedImage->loader()->didReceiveResponse( |
444 WrappedResourceResponse(resourceResponse), nullptr); | 444 WrappedResourceResponse(resourceResponse), nullptr); |
445 cachedImage->loader()->didReceiveData( | 445 cachedImage->loader()->didReceiveData( |
446 reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2)); | 446 reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2)); |
447 cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2), | 447 cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2), |
448 sizeof(kJpegImage2)); | 448 sizeof(kJpegImage2)); |
449 EXPECT_FALSE(cachedImage->errorOccurred()); | 449 EXPECT_FALSE(cachedImage->errorOccurred()); |
450 ASSERT_TRUE(cachedImage->hasImage()); | 450 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
451 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 451 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
452 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged()); | 452 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged()); |
453 EXPECT_TRUE(client->notifyFinishedCalled()); | 453 EXPECT_TRUE(client->notifyFinishedCalled()); |
454 | 454 |
455 // The client should not have been notified of completion again. | 455 // The client should not have been notified of completion again. |
456 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); | 456 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); |
457 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); | 457 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); |
458 | 458 |
459 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 459 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
460 EXPECT_EQ(50, cachedImage->getImage()->width()); | 460 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
461 EXPECT_EQ(50, cachedImage->getImage()->height()); | 461 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
462 } | 462 } |
463 | 463 |
464 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { | 464 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) { |
465 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 465 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
466 ScopedRegisteredURL scopedRegisteredURL(testURL); | 466 ScopedRegisteredURL scopedRegisteredURL(testURL); |
467 | 467 |
468 ResourceRequest request(testURL); | 468 ResourceRequest request(testURL); |
469 request.setLoFiState(WebURLRequest::LoFiOn); | 469 request.setLoFiState(WebURLRequest::LoFiOn); |
470 FetchRequest fetchRequest(request, FetchInitiatorInfo()); | 470 FetchRequest fetchRequest(request, FetchInitiatorInfo()); |
471 ResourceFetcher* fetcher = | 471 ResourceFetcher* fetcher = |
472 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 472 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
473 | 473 |
474 ImageResource* cachedImage = ImageResource::fetch(fetchRequest, fetcher); | 474 ImageResource* cachedImage = ImageResource::fetch(fetchRequest, fetcher); |
475 Persistent<MockImageResourceClient> client = | 475 Persistent<MockImageResourceClient> client = |
476 new MockImageResourceClient(cachedImage); | 476 new MockImageResourceClient(cachedImage); |
477 | 477 |
478 // Send the image response. | 478 // Send the image response. |
479 ResourceResponse initialResourceResponse( | 479 ResourceResponse initialResourceResponse( |
480 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()); | 480 testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String()); |
481 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); | 481 initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); |
482 | 482 |
483 cachedImage->loader()->didReceiveResponse( | 483 cachedImage->loader()->didReceiveResponse( |
484 WrappedResourceResponse(initialResourceResponse)); | 484 WrappedResourceResponse(initialResourceResponse)); |
485 cachedImage->loader()->didReceiveData( | 485 cachedImage->loader()->didReceiveData( |
486 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); | 486 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); |
487 | 487 |
488 EXPECT_FALSE(cachedImage->errorOccurred()); | 488 EXPECT_FALSE(cachedImage->errorOccurred()); |
489 ASSERT_TRUE(cachedImage->hasImage()); | 489 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
490 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 490 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
491 EXPECT_EQ(1, client->imageChangedCount()); | 491 EXPECT_EQ(1, client->imageChangedCount()); |
492 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 492 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
493 EXPECT_FALSE(client->notifyFinishedCalled()); | 493 EXPECT_FALSE(client->notifyFinishedCalled()); |
494 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 494 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
495 EXPECT_EQ(1, cachedImage->getImage()->width()); | 495 EXPECT_EQ(1, cachedImage->getContent()->getImage()->width()); |
496 EXPECT_EQ(1, cachedImage->getImage()->height()); | 496 EXPECT_EQ(1, cachedImage->getContent()->getImage()->height()); |
497 | 497 |
498 // Call reloadIfLoFiOrPlaceholder() while the image is still loading. | 498 // Call reloadIfLoFiOrPlaceholder() while the image is still loading. |
499 cachedImage->reloadIfLoFiOrPlaceholder(fetcher); | 499 cachedImage->reloadIfLoFiOrPlaceholder(fetcher); |
500 EXPECT_FALSE(cachedImage->errorOccurred()); | 500 EXPECT_FALSE(cachedImage->errorOccurred()); |
501 EXPECT_FALSE(cachedImage->resourceBuffer()); | 501 EXPECT_FALSE(cachedImage->resourceBuffer()); |
502 EXPECT_FALSE(cachedImage->hasImage()); | 502 EXPECT_FALSE(cachedImage->getContent()->hasImage()); |
503 EXPECT_EQ(2, client->imageChangedCount()); | 503 EXPECT_EQ(2, client->imageChangedCount()); |
504 EXPECT_EQ(0U, client->encodedSizeOnLastImageChanged()); | 504 EXPECT_EQ(0U, client->encodedSizeOnLastImageChanged()); |
505 // The client should not have been notified of completion yet, since the image | 505 // The client should not have been notified of completion yet, since the image |
506 // is still loading. | 506 // is still loading. |
507 EXPECT_FALSE(client->notifyFinishedCalled()); | 507 EXPECT_FALSE(client->notifyFinishedCalled()); |
508 | 508 |
509 cachedImage->loader()->didReceiveResponse( | 509 cachedImage->loader()->didReceiveResponse( |
510 WrappedResourceResponse(ResourceResponse( | 510 WrappedResourceResponse(ResourceResponse( |
511 testURL, "image/jpeg", sizeof(kJpegImage2), nullAtom, String())), | 511 testURL, "image/jpeg", sizeof(kJpegImage2), nullAtom, String())), |
512 nullptr); | 512 nullptr); |
513 cachedImage->loader()->didReceiveData( | 513 cachedImage->loader()->didReceiveData( |
514 reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2)); | 514 reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2)); |
515 cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2), | 515 cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2), |
516 sizeof(kJpegImage2)); | 516 sizeof(kJpegImage2)); |
517 | 517 |
518 EXPECT_FALSE(cachedImage->errorOccurred()); | 518 EXPECT_FALSE(cachedImage->errorOccurred()); |
519 ASSERT_TRUE(cachedImage->hasImage()); | 519 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
520 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 520 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
521 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged()); | 521 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged()); |
522 // The client should have been notified of completion only after the reload | 522 // The client should have been notified of completion only after the reload |
523 // completed. | 523 // completed. |
524 EXPECT_TRUE(client->notifyFinishedCalled()); | 524 EXPECT_TRUE(client->notifyFinishedCalled()); |
525 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnNotifyFinished()); | 525 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnNotifyFinished()); |
526 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnImageNotifyFinished()); | 526 EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnImageNotifyFinished()); |
527 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 527 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
528 EXPECT_EQ(50, cachedImage->getImage()->width()); | 528 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
529 EXPECT_EQ(50, cachedImage->getImage()->height()); | 529 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
530 } | 530 } |
531 | 531 |
532 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { | 532 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { |
533 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 533 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
534 ScopedRegisteredURL scopedRegisteredURL(testURL); | 534 ScopedRegisteredURL scopedRegisteredURL(testURL); |
535 | 535 |
536 ResourceFetcher* fetcher = | 536 ResourceFetcher* fetcher = |
537 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 537 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
538 FetchRequest request(testURL, FetchInitiatorInfo()); | 538 FetchRequest request(testURL, FetchInitiatorInfo()); |
539 request.setAllowImagePlaceholder(); | 539 request.setAllowImagePlaceholder(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 TEST(ImageResourceTest, SVGImage) { | 574 TEST(ImageResourceTest, SVGImage) { |
575 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 575 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
576 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 576 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
577 Persistent<MockImageResourceClient> client = | 577 Persistent<MockImageResourceClient> client = |
578 new MockImageResourceClient(imageResource); | 578 new MockImageResourceClient(imageResource); |
579 | 579 |
580 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, | 580 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, |
581 strlen(kSvgImage)); | 581 strlen(kSvgImage)); |
582 | 582 |
583 EXPECT_FALSE(imageResource->errorOccurred()); | 583 EXPECT_FALSE(imageResource->errorOccurred()); |
584 ASSERT_TRUE(imageResource->hasImage()); | 584 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
585 EXPECT_FALSE(imageResource->getImage()->isNull()); | 585 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
586 EXPECT_EQ(1, client->imageChangedCount()); | 586 EXPECT_EQ(1, client->imageChangedCount()); |
587 EXPECT_TRUE(client->notifyFinishedCalled()); | 587 EXPECT_TRUE(client->notifyFinishedCalled()); |
588 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 588 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
589 } | 589 } |
590 | 590 |
591 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) { | 591 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) { |
592 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 592 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
593 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 593 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
594 Persistent<MockImageResourceClient> client = | 594 Persistent<MockImageResourceClient> client = |
595 new MockImageResourceClient(imageResource); | 595 new MockImageResourceClient(imageResource); |
596 | 596 |
597 receiveResponse(imageResource, url, "image/jpeg", | 597 receiveResponse(imageResource, url, "image/jpeg", |
598 reinterpret_cast<const char*>(kJpegImage), | 598 reinterpret_cast<const char*>(kJpegImage), |
599 sizeof(kJpegImage)); | 599 sizeof(kJpegImage)); |
600 | 600 |
601 EXPECT_FALSE(imageResource->errorOccurred()); | 601 EXPECT_FALSE(imageResource->errorOccurred()); |
602 ASSERT_TRUE(imageResource->hasImage()); | 602 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
603 EXPECT_FALSE(imageResource->getImage()->isNull()); | 603 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
604 EXPECT_EQ(2, client->imageChangedCount()); | 604 EXPECT_EQ(2, client->imageChangedCount()); |
605 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 605 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
606 EXPECT_TRUE(client->notifyFinishedCalled()); | 606 EXPECT_TRUE(client->notifyFinishedCalled()); |
607 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 607 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
608 EXPECT_EQ(1, imageResource->getImage()->width()); | 608 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
609 EXPECT_EQ(1, imageResource->getImage()->height()); | 609 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
610 | 610 |
611 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 611 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
612 ResourceResponse response; | 612 ResourceResponse response; |
613 response.setURL(url); | 613 response.setURL(url); |
614 response.setHTTPStatusCode(304); | 614 response.setHTTPStatusCode(304); |
615 | 615 |
616 imageResource->responseReceived(response, nullptr); | 616 imageResource->responseReceived(response, nullptr); |
617 | 617 |
618 EXPECT_FALSE(imageResource->errorOccurred()); | 618 EXPECT_FALSE(imageResource->errorOccurred()); |
619 ASSERT_TRUE(imageResource->hasImage()); | 619 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
620 EXPECT_FALSE(imageResource->getImage()->isNull()); | 620 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
621 EXPECT_EQ(2, client->imageChangedCount()); | 621 EXPECT_EQ(2, client->imageChangedCount()); |
622 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 622 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
623 EXPECT_TRUE(client->notifyFinishedCalled()); | 623 EXPECT_TRUE(client->notifyFinishedCalled()); |
624 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 624 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
625 EXPECT_EQ(1, imageResource->getImage()->width()); | 625 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
626 EXPECT_EQ(1, imageResource->getImage()->height()); | 626 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
627 } | 627 } |
628 | 628 |
629 TEST(ImageResourceTest, SuccessfulRevalidationSvg) { | 629 TEST(ImageResourceTest, SuccessfulRevalidationSvg) { |
630 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 630 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
631 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 631 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
632 Persistent<MockImageResourceClient> client = | 632 Persistent<MockImageResourceClient> client = |
633 new MockImageResourceClient(imageResource); | 633 new MockImageResourceClient(imageResource); |
634 | 634 |
635 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, | 635 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, |
636 strlen(kSvgImage)); | 636 strlen(kSvgImage)); |
637 | 637 |
638 EXPECT_FALSE(imageResource->errorOccurred()); | 638 EXPECT_FALSE(imageResource->errorOccurred()); |
639 ASSERT_TRUE(imageResource->hasImage()); | 639 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
640 EXPECT_FALSE(imageResource->getImage()->isNull()); | 640 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
641 EXPECT_EQ(1, client->imageChangedCount()); | 641 EXPECT_EQ(1, client->imageChangedCount()); |
642 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 642 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
643 EXPECT_TRUE(client->notifyFinishedCalled()); | 643 EXPECT_TRUE(client->notifyFinishedCalled()); |
644 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 644 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
645 EXPECT_EQ(200, imageResource->getImage()->width()); | 645 EXPECT_EQ(200, imageResource->getContent()->getImage()->width()); |
646 EXPECT_EQ(200, imageResource->getImage()->height()); | 646 EXPECT_EQ(200, imageResource->getContent()->getImage()->height()); |
647 | 647 |
648 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 648 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
649 ResourceResponse response; | 649 ResourceResponse response; |
650 response.setURL(url); | 650 response.setURL(url); |
651 response.setHTTPStatusCode(304); | 651 response.setHTTPStatusCode(304); |
652 imageResource->responseReceived(response, nullptr); | 652 imageResource->responseReceived(response, nullptr); |
653 | 653 |
654 EXPECT_FALSE(imageResource->errorOccurred()); | 654 EXPECT_FALSE(imageResource->errorOccurred()); |
655 ASSERT_TRUE(imageResource->hasImage()); | 655 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
656 EXPECT_FALSE(imageResource->getImage()->isNull()); | 656 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
657 EXPECT_EQ(1, client->imageChangedCount()); | 657 EXPECT_EQ(1, client->imageChangedCount()); |
658 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 658 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
659 EXPECT_TRUE(client->notifyFinishedCalled()); | 659 EXPECT_TRUE(client->notifyFinishedCalled()); |
660 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 660 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
661 EXPECT_EQ(200, imageResource->getImage()->width()); | 661 EXPECT_EQ(200, imageResource->getContent()->getImage()->width()); |
662 EXPECT_EQ(200, imageResource->getImage()->height()); | 662 EXPECT_EQ(200, imageResource->getContent()->getImage()->height()); |
663 } | 663 } |
664 | 664 |
665 TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) { | 665 TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) { |
666 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 666 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
667 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 667 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
668 Persistent<MockImageResourceClient> client = | 668 Persistent<MockImageResourceClient> client = |
669 new MockImageResourceClient(imageResource); | 669 new MockImageResourceClient(imageResource); |
670 | 670 |
671 receiveResponse(imageResource, url, "image/jpeg", | 671 receiveResponse(imageResource, url, "image/jpeg", |
672 reinterpret_cast<const char*>(kJpegImage), | 672 reinterpret_cast<const char*>(kJpegImage), |
673 sizeof(kJpegImage)); | 673 sizeof(kJpegImage)); |
674 | 674 |
675 EXPECT_FALSE(imageResource->errorOccurred()); | 675 EXPECT_FALSE(imageResource->errorOccurred()); |
676 ASSERT_TRUE(imageResource->hasImage()); | 676 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
677 EXPECT_FALSE(imageResource->getImage()->isNull()); | 677 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
678 EXPECT_EQ(2, client->imageChangedCount()); | 678 EXPECT_EQ(2, client->imageChangedCount()); |
679 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 679 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
680 EXPECT_TRUE(client->notifyFinishedCalled()); | 680 EXPECT_TRUE(client->notifyFinishedCalled()); |
681 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 681 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
682 EXPECT_EQ(1, imageResource->getImage()->width()); | 682 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
683 EXPECT_EQ(1, imageResource->getImage()->height()); | 683 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
684 | 684 |
685 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 685 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
686 receiveResponse(imageResource, url, "image/jpeg", | 686 receiveResponse(imageResource, url, "image/jpeg", |
687 reinterpret_cast<const char*>(kJpegImage2), | 687 reinterpret_cast<const char*>(kJpegImage2), |
688 sizeof(kJpegImage2)); | 688 sizeof(kJpegImage2)); |
689 | 689 |
690 EXPECT_FALSE(imageResource->errorOccurred()); | 690 EXPECT_FALSE(imageResource->errorOccurred()); |
691 ASSERT_TRUE(imageResource->hasImage()); | 691 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
692 EXPECT_FALSE(imageResource->getImage()->isNull()); | 692 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
693 EXPECT_EQ(4, client->imageChangedCount()); | 693 EXPECT_EQ(4, client->imageChangedCount()); |
694 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 694 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
695 EXPECT_TRUE(client->notifyFinishedCalled()); | 695 EXPECT_TRUE(client->notifyFinishedCalled()); |
696 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 696 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
697 EXPECT_EQ(50, imageResource->getImage()->width()); | 697 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
698 EXPECT_EQ(50, imageResource->getImage()->height()); | 698 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
699 } | 699 } |
700 | 700 |
701 TEST(ImageResourceTest, FailedRevalidationJpegToSvg) { | 701 TEST(ImageResourceTest, FailedRevalidationJpegToSvg) { |
702 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 702 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
703 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 703 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
704 Persistent<MockImageResourceClient> client = | 704 Persistent<MockImageResourceClient> client = |
705 new MockImageResourceClient(imageResource); | 705 new MockImageResourceClient(imageResource); |
706 | 706 |
707 receiveResponse(imageResource, url, "image/jpeg", | 707 receiveResponse(imageResource, url, "image/jpeg", |
708 reinterpret_cast<const char*>(kJpegImage), | 708 reinterpret_cast<const char*>(kJpegImage), |
709 sizeof(kJpegImage)); | 709 sizeof(kJpegImage)); |
710 | 710 |
711 EXPECT_FALSE(imageResource->errorOccurred()); | 711 EXPECT_FALSE(imageResource->errorOccurred()); |
712 ASSERT_TRUE(imageResource->hasImage()); | 712 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
713 EXPECT_FALSE(imageResource->getImage()->isNull()); | 713 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
714 EXPECT_EQ(2, client->imageChangedCount()); | 714 EXPECT_EQ(2, client->imageChangedCount()); |
715 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 715 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
716 EXPECT_TRUE(client->notifyFinishedCalled()); | 716 EXPECT_TRUE(client->notifyFinishedCalled()); |
717 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 717 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
718 EXPECT_EQ(1, imageResource->getImage()->width()); | 718 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
719 EXPECT_EQ(1, imageResource->getImage()->height()); | 719 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
720 | 720 |
721 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 721 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
722 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, | 722 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, |
723 strlen(kSvgImage)); | 723 strlen(kSvgImage)); |
724 | 724 |
725 EXPECT_FALSE(imageResource->errorOccurred()); | 725 EXPECT_FALSE(imageResource->errorOccurred()); |
726 ASSERT_TRUE(imageResource->hasImage()); | 726 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
727 EXPECT_FALSE(imageResource->getImage()->isNull()); | 727 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
728 EXPECT_EQ(3, client->imageChangedCount()); | 728 EXPECT_EQ(3, client->imageChangedCount()); |
729 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 729 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
730 EXPECT_TRUE(client->notifyFinishedCalled()); | 730 EXPECT_TRUE(client->notifyFinishedCalled()); |
731 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 731 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
732 EXPECT_EQ(200, imageResource->getImage()->width()); | 732 EXPECT_EQ(200, imageResource->getContent()->getImage()->width()); |
733 EXPECT_EQ(200, imageResource->getImage()->height()); | 733 EXPECT_EQ(200, imageResource->getContent()->getImage()->height()); |
734 } | 734 } |
735 | 735 |
736 TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) { | 736 TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) { |
737 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 737 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
738 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 738 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
739 Persistent<MockImageResourceClient> client = | 739 Persistent<MockImageResourceClient> client = |
740 new MockImageResourceClient(imageResource); | 740 new MockImageResourceClient(imageResource); |
741 | 741 |
742 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, | 742 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, |
743 strlen(kSvgImage)); | 743 strlen(kSvgImage)); |
744 | 744 |
745 EXPECT_FALSE(imageResource->errorOccurred()); | 745 EXPECT_FALSE(imageResource->errorOccurred()); |
746 ASSERT_TRUE(imageResource->hasImage()); | 746 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
747 EXPECT_FALSE(imageResource->getImage()->isNull()); | 747 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
748 EXPECT_EQ(1, client->imageChangedCount()); | 748 EXPECT_EQ(1, client->imageChangedCount()); |
749 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 749 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
750 EXPECT_TRUE(client->notifyFinishedCalled()); | 750 EXPECT_TRUE(client->notifyFinishedCalled()); |
751 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 751 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
752 EXPECT_EQ(200, imageResource->getImage()->width()); | 752 EXPECT_EQ(200, imageResource->getContent()->getImage()->width()); |
753 EXPECT_EQ(200, imageResource->getImage()->height()); | 753 EXPECT_EQ(200, imageResource->getContent()->getImage()->height()); |
754 | 754 |
755 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 755 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
756 receiveResponse(imageResource, url, "image/jpeg", | 756 receiveResponse(imageResource, url, "image/jpeg", |
757 reinterpret_cast<const char*>(kJpegImage), | 757 reinterpret_cast<const char*>(kJpegImage), |
758 sizeof(kJpegImage)); | 758 sizeof(kJpegImage)); |
759 | 759 |
760 EXPECT_FALSE(imageResource->errorOccurred()); | 760 EXPECT_FALSE(imageResource->errorOccurred()); |
761 ASSERT_TRUE(imageResource->hasImage()); | 761 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
762 EXPECT_FALSE(imageResource->getImage()->isNull()); | 762 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
763 EXPECT_EQ(3, client->imageChangedCount()); | 763 EXPECT_EQ(3, client->imageChangedCount()); |
764 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 764 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
765 EXPECT_TRUE(client->notifyFinishedCalled()); | 765 EXPECT_TRUE(client->notifyFinishedCalled()); |
766 EXPECT_TRUE(imageResource->getImage()->isBitmapImage()); | 766 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
767 EXPECT_EQ(1, imageResource->getImage()->width()); | 767 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
768 EXPECT_EQ(1, imageResource->getImage()->height()); | 768 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
769 } | 769 } |
770 | 770 |
771 TEST(ImageResourceTest, FailedRevalidationSvgToSvg) { | 771 TEST(ImageResourceTest, FailedRevalidationSvgToSvg) { |
772 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 772 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
773 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 773 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
774 Persistent<MockImageResourceClient> client = | 774 Persistent<MockImageResourceClient> client = |
775 new MockImageResourceClient(imageResource); | 775 new MockImageResourceClient(imageResource); |
776 | 776 |
777 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, | 777 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, |
778 strlen(kSvgImage)); | 778 strlen(kSvgImage)); |
779 | 779 |
780 EXPECT_FALSE(imageResource->errorOccurred()); | 780 EXPECT_FALSE(imageResource->errorOccurred()); |
781 ASSERT_TRUE(imageResource->hasImage()); | 781 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
782 EXPECT_FALSE(imageResource->getImage()->isNull()); | 782 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
783 EXPECT_EQ(1, client->imageChangedCount()); | 783 EXPECT_EQ(1, client->imageChangedCount()); |
784 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 784 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
785 EXPECT_TRUE(client->notifyFinishedCalled()); | 785 EXPECT_TRUE(client->notifyFinishedCalled()); |
786 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 786 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
787 EXPECT_EQ(200, imageResource->getImage()->width()); | 787 EXPECT_EQ(200, imageResource->getContent()->getImage()->width()); |
788 EXPECT_EQ(200, imageResource->getImage()->height()); | 788 EXPECT_EQ(200, imageResource->getContent()->getImage()->height()); |
789 | 789 |
790 imageResource->setRevalidatingRequest(ResourceRequest(url)); | 790 imageResource->setRevalidatingRequest(ResourceRequest(url)); |
791 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage2, | 791 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage2, |
792 strlen(kSvgImage2)); | 792 strlen(kSvgImage2)); |
793 | 793 |
794 EXPECT_FALSE(imageResource->errorOccurred()); | 794 EXPECT_FALSE(imageResource->errorOccurred()); |
795 ASSERT_TRUE(imageResource->hasImage()); | 795 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
796 EXPECT_FALSE(imageResource->getImage()->isNull()); | 796 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
797 EXPECT_EQ(2, client->imageChangedCount()); | 797 EXPECT_EQ(2, client->imageChangedCount()); |
798 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 798 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
799 EXPECT_TRUE(client->notifyFinishedCalled()); | 799 EXPECT_TRUE(client->notifyFinishedCalled()); |
800 EXPECT_FALSE(imageResource->getImage()->isBitmapImage()); | 800 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
801 EXPECT_EQ(300, imageResource->getImage()->width()); | 801 EXPECT_EQ(300, imageResource->getContent()->getImage()->width()); |
802 EXPECT_EQ(300, imageResource->getImage()->height()); | 802 EXPECT_EQ(300, imageResource->getContent()->getImage()->height()); |
803 } | 803 } |
804 | 804 |
805 // Tests for pruning. | 805 // Tests for pruning. |
806 | 806 |
807 TEST(ImageResourceTest, AddClientAfterPrune) { | 807 TEST(ImageResourceTest, AddClientAfterPrune) { |
808 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 808 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
809 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 809 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
810 | 810 |
811 // Adds a ResourceClient but not ImageResourceObserver. | 811 // Adds a ResourceClient but not ImageResourceObserver. |
812 Persistent<MockResourceClient> client1 = | 812 Persistent<MockResourceClient> client1 = |
813 new MockResourceClient(imageResource); | 813 new MockResourceClient(imageResource); |
814 | 814 |
815 receiveResponse(imageResource, url, "image/jpeg", | 815 receiveResponse(imageResource, url, "image/jpeg", |
816 reinterpret_cast<const char*>(kJpegImage), | 816 reinterpret_cast<const char*>(kJpegImage), |
817 sizeof(kJpegImage)); | 817 sizeof(kJpegImage)); |
818 | 818 |
819 EXPECT_FALSE(imageResource->errorOccurred()); | 819 EXPECT_FALSE(imageResource->errorOccurred()); |
820 ASSERT_TRUE(imageResource->hasImage()); | 820 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
821 EXPECT_FALSE(imageResource->getImage()->isNull()); | 821 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
822 EXPECT_EQ(1, imageResource->getImage()->width()); | 822 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
823 EXPECT_EQ(1, imageResource->getImage()->height()); | 823 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
824 EXPECT_TRUE(client1->notifyFinishedCalled()); | 824 EXPECT_TRUE(client1->notifyFinishedCalled()); |
825 | 825 |
826 client1->removeAsClient(); | 826 client1->removeAsClient(); |
827 | 827 |
828 EXPECT_FALSE(imageResource->isAlive()); | 828 EXPECT_FALSE(imageResource->isAlive()); |
829 | 829 |
830 imageResource->prune(); | 830 imageResource->prune(); |
831 | 831 |
832 EXPECT_TRUE(imageResource->hasImage()); | 832 EXPECT_TRUE(imageResource->getContent()->hasImage()); |
833 | 833 |
834 // Re-adds a ResourceClient but not ImageResourceObserver. | 834 // Re-adds a ResourceClient but not ImageResourceObserver. |
835 Persistent<MockResourceClient> client2 = | 835 Persistent<MockResourceClient> client2 = |
836 new MockResourceClient(imageResource); | 836 new MockResourceClient(imageResource); |
837 | 837 |
838 ASSERT_TRUE(imageResource->hasImage()); | 838 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
839 EXPECT_FALSE(imageResource->getImage()->isNull()); | 839 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
840 EXPECT_EQ(1, imageResource->getImage()->width()); | 840 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); |
841 EXPECT_EQ(1, imageResource->getImage()->height()); | 841 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); |
842 EXPECT_TRUE(client2->notifyFinishedCalled()); | 842 EXPECT_TRUE(client2->notifyFinishedCalled()); |
843 } | 843 } |
844 | 844 |
845 TEST(ImageResourceTest, CancelOnDecodeError) { | 845 TEST(ImageResourceTest, CancelOnDecodeError) { |
846 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 846 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
847 ScopedRegisteredURL scopedRegisteredURL(testURL); | 847 ScopedRegisteredURL scopedRegisteredURL(testURL); |
848 | 848 |
849 ResourceFetcher* fetcher = | 849 ResourceFetcher* fetcher = |
850 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 850 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
851 FetchRequest request(testURL, FetchInitiatorInfo()); | 851 FetchRequest request(testURL, FetchInitiatorInfo()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 885 |
886 EXPECT_EQ(Resource::Cached, image->getStatus()); | 886 EXPECT_EQ(Resource::Cached, image->getStatus()); |
887 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); | 887 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); |
888 EXPECT_FALSE(image->isPlaceholder()); | 888 EXPECT_FALSE(image->isPlaceholder()); |
889 EXPECT_LT(0, client->imageChangedCount()); | 889 EXPECT_LT(0, client->imageChangedCount()); |
890 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 890 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
891 EXPECT_TRUE(client->notifyFinishedCalled()); | 891 EXPECT_TRUE(client->notifyFinishedCalled()); |
892 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); | 892 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); |
893 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); | 893 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); |
894 | 894 |
895 ASSERT_TRUE(image->hasImage()); | 895 ASSERT_TRUE(image->getContent()->hasImage()); |
896 EXPECT_EQ(1, image->getImage()->width()); | 896 EXPECT_EQ(1, image->getContent()->getImage()->width()); |
897 EXPECT_EQ(1, image->getImage()->height()); | 897 EXPECT_EQ(1, image->getContent()->getImage()->height()); |
898 EXPECT_TRUE(image->getImage()->isBitmapImage()); | 898 EXPECT_TRUE(image->getContent()->getImage()->isBitmapImage()); |
899 } | 899 } |
900 | 900 |
901 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) { | 901 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) { |
902 KURL testURL(ParsedURLString, | 902 KURL testURL(ParsedURLString, |
903 "data:image/jpeg;base64," + | 903 "data:image/jpeg;base64," + |
904 base64Encode(reinterpret_cast<const char*>(kJpegImage), | 904 base64Encode(reinterpret_cast<const char*>(kJpegImage), |
905 sizeof(kJpegImage))); | 905 sizeof(kJpegImage))); |
906 FetchRequest request(testURL, FetchInitiatorInfo()); | 906 FetchRequest request(testURL, FetchInitiatorInfo()); |
907 request.setAllowImagePlaceholder(); | 907 request.setAllowImagePlaceholder(); |
908 ImageResource* image = ImageResource::fetch( | 908 ImageResource* image = ImageResource::fetch( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 EXPECT_TRUE(image->isPlaceholder()); | 984 EXPECT_TRUE(image->isPlaceholder()); |
985 EXPECT_LT(0, client->imageChangedCount()); | 985 EXPECT_LT(0, client->imageChangedCount()); |
986 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, | 986 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, |
987 client->encodedSizeOnLastImageChanged()); | 987 client->encodedSizeOnLastImageChanged()); |
988 EXPECT_TRUE(client->notifyFinishedCalled()); | 988 EXPECT_TRUE(client->notifyFinishedCalled()); |
989 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, | 989 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, |
990 client->encodedSizeOnNotifyFinished()); | 990 client->encodedSizeOnNotifyFinished()); |
991 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, | 991 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength, |
992 client->encodedSizeOnImageNotifyFinished()); | 992 client->encodedSizeOnImageNotifyFinished()); |
993 | 993 |
994 ASSERT_TRUE(image->hasImage()); | 994 ASSERT_TRUE(image->getContent()->hasImage()); |
995 EXPECT_EQ(1, image->getImage()->width()); | 995 EXPECT_EQ(1, image->getContent()->getImage()->width()); |
996 EXPECT_EQ(1, image->getImage()->height()); | 996 EXPECT_EQ(1, image->getContent()->getImage()->height()); |
997 EXPECT_FALSE(image->getImage()->isBitmapImage()); | 997 EXPECT_FALSE(image->getContent()->getImage()->isBitmapImage()); |
998 EXPECT_FALSE(image->getImage()->isSVGImage()); | 998 EXPECT_FALSE(image->getContent()->getImage()->isSVGImage()); |
999 } | 999 } |
1000 | 1000 |
1001 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { | 1001 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { |
1002 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1002 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
1003 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1003 ScopedRegisteredURL scopedRegisteredURL(testURL); |
1004 | 1004 |
1005 FetchRequest request(testURL, FetchInitiatorInfo()); | 1005 FetchRequest request(testURL, FetchInitiatorInfo()); |
1006 request.setAllowImagePlaceholder(); | 1006 request.setAllowImagePlaceholder(); |
1007 ImageResource* image = ImageResource::fetch( | 1007 ImageResource* image = ImageResource::fetch( |
1008 request, | 1008 request, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 EXPECT_EQ(Resource::Cached, image->getStatus()); | 1042 EXPECT_EQ(Resource::Cached, image->getStatus()); |
1043 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); | 1043 EXPECT_EQ(sizeof(kJpegImage), image->encodedSize()); |
1044 EXPECT_FALSE(image->isPlaceholder()); | 1044 EXPECT_FALSE(image->isPlaceholder()); |
1045 EXPECT_LT(0, client->imageChangedCount()); | 1045 EXPECT_LT(0, client->imageChangedCount()); |
1046 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); | 1046 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged()); |
1047 EXPECT_TRUE(client->notifyFinishedCalled()); | 1047 EXPECT_TRUE(client->notifyFinishedCalled()); |
1048 EXPECT_EQ(1, client->imageNotifyFinishedCount()); | 1048 EXPECT_EQ(1, client->imageNotifyFinishedCount()); |
1049 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); | 1049 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished()); |
1050 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); | 1050 EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished()); |
1051 | 1051 |
1052 ASSERT_TRUE(image->hasImage()); | 1052 ASSERT_TRUE(image->getContent()->hasImage()); |
1053 EXPECT_EQ(1, image->getImage()->width()); | 1053 EXPECT_EQ(1, image->getContent()->getImage()->width()); |
1054 EXPECT_EQ(1, image->getImage()->height()); | 1054 EXPECT_EQ(1, image->getContent()->getImage()->height()); |
1055 EXPECT_TRUE(image->getImage()->isBitmapImage()); | 1055 EXPECT_TRUE(image->getContent()->getImage()->isBitmapImage()); |
1056 } | 1056 } |
1057 | 1057 |
1058 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { | 1058 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { |
1059 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1059 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
1060 ScopedRegisteredURL scopedRegisteredURL(testURL); | 1060 ScopedRegisteredURL scopedRegisteredURL(testURL); |
1061 | 1061 |
1062 ResourceFetcher* fetcher = | 1062 ResourceFetcher* fetcher = |
1063 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); | 1063 ResourceFetcher::create(ImageResourceTestMockFetchContext::create()); |
1064 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); | 1064 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); |
1065 placeholderRequest.setAllowImagePlaceholder(); | 1065 placeholderRequest.setAllowImagePlaceholder(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1147 |
1148 // This is number is sufficiently large amount of bytes necessary for the | 1148 // This is number is sufficiently large amount of bytes necessary for the |
1149 // image to be created (since the size is known). This was determined by | 1149 // image to be created (since the size is known). This was determined by |
1150 // appending one byte at a time (with flushes) until the image was decoded. | 1150 // appending one byte at a time (with flushes) until the image was decoded. |
1151 size_t meaningfulImageSize = 280; | 1151 size_t meaningfulImageSize = 280; |
1152 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2), | 1152 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2), |
1153 meaningfulImageSize); | 1153 meaningfulImageSize); |
1154 size_t bytesSent = meaningfulImageSize; | 1154 size_t bytesSent = meaningfulImageSize; |
1155 | 1155 |
1156 EXPECT_FALSE(cachedImage->errorOccurred()); | 1156 EXPECT_FALSE(cachedImage->errorOccurred()); |
1157 EXPECT_TRUE(cachedImage->hasImage()); | 1157 EXPECT_TRUE(cachedImage->getContent()->hasImage()); |
1158 EXPECT_EQ(1, client->imageChangedCount()); | 1158 EXPECT_EQ(1, client->imageChangedCount()); |
1159 | 1159 |
1160 platform.runForPeriodSeconds(1.); | 1160 platform.runForPeriodSeconds(1.); |
1161 platform.advanceClockSeconds(1.); | 1161 platform.advanceClockSeconds(1.); |
1162 | 1162 |
1163 // Sanity check that we created an image after appending |meaningfulImageSize| | 1163 // Sanity check that we created an image after appending |meaningfulImageSize| |
1164 // bytes just once. | 1164 // bytes just once. |
1165 EXPECT_FALSE(cachedImage->errorOccurred()); | 1165 EXPECT_FALSE(cachedImage->errorOccurred()); |
1166 ASSERT_TRUE(cachedImage->hasImage()); | 1166 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
1167 EXPECT_EQ(1, client->imageChangedCount()); | 1167 EXPECT_EQ(1, client->imageChangedCount()); |
1168 | 1168 |
1169 for (int flushCount = 1; flushCount <= 3; ++flushCount) { | 1169 for (int flushCount = 1; flushCount <= 3; ++flushCount) { |
1170 // For each of the iteration that appends data, we don't expect | 1170 // For each of the iteration that appends data, we don't expect |
1171 // |imageChangeCount()| to change, since the time is adjusted by 0.2001 | 1171 // |imageChangeCount()| to change, since the time is adjusted by 0.2001 |
1172 // seconds (it's greater than 0.2 to avoid double precision problems). | 1172 // seconds (it's greater than 0.2 to avoid double precision problems). |
1173 // After 5 appends, we breach the flush interval and the flush count | 1173 // After 5 appends, we breach the flush interval and the flush count |
1174 // increases. | 1174 // increases. |
1175 for (int i = 0; i < 5; ++i) { | 1175 for (int i = 0; i < 5; ++i) { |
1176 SCOPED_TRACE(i); | 1176 SCOPED_TRACE(i); |
1177 cachedImage->appendData( | 1177 cachedImage->appendData( |
1178 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, 1); | 1178 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, 1); |
1179 | 1179 |
1180 EXPECT_FALSE(cachedImage->errorOccurred()); | 1180 EXPECT_FALSE(cachedImage->errorOccurred()); |
1181 ASSERT_TRUE(cachedImage->hasImage()); | 1181 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
1182 EXPECT_EQ(flushCount, client->imageChangedCount()); | 1182 EXPECT_EQ(flushCount, client->imageChangedCount()); |
1183 | 1183 |
1184 ++bytesSent; | 1184 ++bytesSent; |
1185 platform.runForPeriodSeconds(0.2001); | 1185 platform.runForPeriodSeconds(0.2001); |
1186 } | 1186 } |
1187 } | 1187 } |
1188 | 1188 |
1189 // Increasing time by a large number only causes one extra flush. | 1189 // Increasing time by a large number only causes one extra flush. |
1190 platform.runForPeriodSeconds(10.); | 1190 platform.runForPeriodSeconds(10.); |
1191 platform.advanceClockSeconds(10.); | 1191 platform.advanceClockSeconds(10.); |
1192 EXPECT_FALSE(cachedImage->errorOccurred()); | 1192 EXPECT_FALSE(cachedImage->errorOccurred()); |
1193 ASSERT_TRUE(cachedImage->hasImage()); | 1193 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
1194 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 1194 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
1195 EXPECT_EQ(4, client->imageChangedCount()); | 1195 EXPECT_EQ(4, client->imageChangedCount()); |
1196 | 1196 |
1197 // Append the rest of the data and finish (which causes another flush). | 1197 // Append the rest of the data and finish (which causes another flush). |
1198 cachedImage->appendData( | 1198 cachedImage->appendData( |
1199 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, | 1199 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, |
1200 sizeof(kJpegImage2) - bytesSent); | 1200 sizeof(kJpegImage2) - bytesSent); |
1201 cachedImage->finish(); | 1201 cachedImage->finish(); |
1202 | 1202 |
1203 EXPECT_FALSE(cachedImage->errorOccurred()); | 1203 EXPECT_FALSE(cachedImage->errorOccurred()); |
1204 ASSERT_TRUE(cachedImage->hasImage()); | 1204 ASSERT_TRUE(cachedImage->getContent()->hasImage()); |
1205 EXPECT_FALSE(cachedImage->getImage()->isNull()); | 1205 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); |
1206 EXPECT_EQ(5, client->imageChangedCount()); | 1206 EXPECT_EQ(5, client->imageChangedCount()); |
1207 EXPECT_TRUE(client->notifyFinishedCalled()); | 1207 EXPECT_TRUE(client->notifyFinishedCalled()); |
1208 EXPECT_TRUE(cachedImage->getImage()->isBitmapImage()); | 1208 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); |
1209 EXPECT_EQ(50, cachedImage->getImage()->width()); | 1209 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); |
1210 EXPECT_EQ(50, cachedImage->getImage()->height()); | 1210 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); |
1211 | 1211 |
1212 WTF::setTimeFunctionsForTesting(nullptr); | 1212 WTF::setTimeFunctionsForTesting(nullptr); |
1213 } | 1213 } |
1214 | 1214 |
1215 } // namespace | 1215 } // namespace |
1216 } // namespace blink | 1216 } // namespace blink |
OLD | NEW |