Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698