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

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

Issue 2728643004: ImageResourceTest: merge successful placeholder/non-placeholder loading (Closed)
Patch Set: Rebase. Created 3 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x14, 0x10, 0x01, 0x00, 86 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x14, 0x10, 0x01, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x01, 0x01, 0x00, 0x00, 0x00, 88 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x01, 0x01, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 90 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
92 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 92 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f,
93 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9}; 93 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9};
94 94
95 constexpr int kJpegImageWidth = 1; 95 constexpr int kJpegImageWidth = 1;
96 constexpr int kJpegImageHeight = 1;
96 97
97 constexpr size_t kJpegImageSubrangeWithDimensionsLength = 98 constexpr size_t kJpegImageSubrangeWithDimensionsLength =
98 sizeof(kJpegImage) - 1; 99 sizeof(kJpegImage) - 1;
99 constexpr size_t kJpegImageSubrangeWithoutDimensionsLength = 3; 100 constexpr size_t kJpegImageSubrangeWithoutDimensionsLength = 3;
100 101
101 // Ensure that the image decoder can determine the dimensions of kJpegImage from 102 // Ensure that the image decoder can determine the dimensions of kJpegImage from
102 // just the first kJpegImageSubrangeWithDimensionsLength bytes. If this test 103 // just the first kJpegImageSubrangeWithDimensionsLength bytes. If this test
103 // fails, then the test data here probably needs to be updated. 104 // fails, then the test data here probably needs to be updated.
104 TEST(ImageResourceTest, DimensionsDecodableFromPartialTestImage) { 105 TEST(ImageResourceTest, DimensionsDecodableFromPartialTestImage) {
105 RefPtr<Image> image = BitmapImage::create(); 106 RefPtr<Image> image = BitmapImage::create();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(imageWidth, content->getImage()->width()); 231 EXPECT_EQ(imageWidth, content->getImage()->width());
231 EXPECT_EQ(imageHeight, content->getImage()->height()); 232 EXPECT_EQ(imageHeight, content->getImage()->height());
232 EXPECT_TRUE(content->getImage()->isBitmapImage()); 233 EXPECT_TRUE(content->getImage()->isBitmapImage());
233 } 234 }
234 235
235 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) { 236 AtomicString buildContentRange(size_t rangeLength, size_t totalLength) {
236 return AtomicString(String("bytes 0-" + String::number(rangeLength - 1) + 237 return AtomicString(String("bytes 0-" + String::number(rangeLength - 1) +
237 "/" + String::number(totalLength))); 238 "/" + String::number(totalLength)));
238 } 239 }
239 240
241 void testThatIsPlaceholderRequestAndServeResponse(
242 const KURL& url,
243 ImageResource* imageResource,
244 MockImageResourceObserver* observer) {
245 // Checks that |imageResource| is requesting for placeholder.
246 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
247 EXPECT_EQ("bytes=0-2047",
248 imageResource->resourceRequest().httpHeaderField("range"));
249 EXPECT_EQ(0, observer->imageChangedCount());
250
251 // Serves partial response that is sufficient for creating a placeholder.
252 ResourceResponse response(url, "image/jpeg",
253 kJpegImageSubrangeWithDimensionsLength, nullAtom);
254 response.setHTTPStatusCode(206);
255 response.setHTTPHeaderField(
256 "content-range", buildContentRange(kJpegImageSubrangeWithDimensionsLength,
257 sizeof(kJpegImage)));
258 imageResource->loader()->didReceiveResponse(
259 WrappedResourceResponse(response));
260 imageResource->loader()->didReceiveData(
261 reinterpret_cast<const char*>(kJpegImage),
262 kJpegImageSubrangeWithDimensionsLength);
263 imageResource->loader()->didFinishLoading(
264 0.0, kJpegImageSubrangeWithDimensionsLength,
265 kJpegImageSubrangeWithDimensionsLength);
266
267 // Checks that |imageResource| is successfully loaded, showing a placeholder.
268 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
269 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
270 imageResource->encodedSize());
271
272 EXPECT_LT(0, observer->imageChangedCount());
273 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
274 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
275 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
276 ASSERT_TRUE(imageResource->getContent()->hasImage());
277 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
278 EXPECT_EQ(kJpegImageHeight,
279 imageResource->getContent()->getImage()->height());
280
281 // A placeholder image.
282 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
283 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
284 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage());
285 }
286
287 void testThatIsNotPlaceholderRequestAndServeResponse(
288 const KURL& url,
289 ImageResource* imageResource,
290 MockImageResourceObserver* observer) {
291 // Checks that |imageResource| is NOT requesting for placeholder.
292 EXPECT_FALSE(imageResource->shouldShowPlaceholder());
293 EXPECT_EQ(nullAtom,
294 imageResource->resourceRequest().httpHeaderField("range"));
295 EXPECT_EQ(0, observer->imageChangedCount());
296
297 // Serves full response.
298 imageResource->loader()->didReceiveResponse(WrappedResourceResponse(
299 ResourceResponse(url, "image/jpeg", sizeof(kJpegImage), nullAtom)));
300 imageResource->loader()->didReceiveData(
301 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
302 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage),
303 sizeof(kJpegImage));
304
305 // Checks that |imageResource| is successfully loaded.
306 // showing a non-placeholder image.
sclittle 2017/03/07 22:01:26 nit: could you fix this comment?
hiroshige 2017/03/07 22:53:15 Fixed a little bit. Is this what you meant?
sclittle 2017/03/07 22:55:01 Yep, thanks!
307 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
308 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize());
309
310 EXPECT_LT(0, observer->imageChangedCount());
311 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
312 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
313 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
314 ASSERT_TRUE(imageResource->getContent()->hasImage());
315 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
316 EXPECT_EQ(kJpegImageHeight,
317 imageResource->getContent()->getImage()->height());
318
319 // A non-placeholder bitmap image.
320 EXPECT_FALSE(imageResource->shouldShowPlaceholder());
321 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
322 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage());
323 }
324
240 ResourceFetcher* createFetcher() { 325 ResourceFetcher* createFetcher() {
241 return ResourceFetcher::create( 326 return ResourceFetcher::create(
242 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource)); 327 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
243 } 328 }
244 329
245 TEST(ImageResourceTest, MultipartImage) { 330 TEST(ImageResourceTest, MultipartImage) {
246 ResourceFetcher* fetcher = createFetcher(); 331 ResourceFetcher* fetcher = createFetcher();
247 KURL testURL(ParsedURLString, kTestURL); 332 KURL testURL(ParsedURLString, kTestURL);
248 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 333 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
249 334
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ASSERT_TRUE(imageResource->resourceBuffer()); 392 ASSERT_TRUE(imageResource->resourceBuffer());
308 EXPECT_EQ(strlen(secondPart) - 1, imageResource->resourceBuffer()->size()); 393 EXPECT_EQ(strlen(secondPart) - 1, imageResource->resourceBuffer()->size());
309 394
310 // This part finishes. The image is created, callbacks are sent, and the data 395 // This part finishes. The image is created, callbacks are sent, and the data
311 // buffer is cleared. 396 // buffer is cleared.
312 imageResource->loader()->didFinishLoading(0.0, 0, 0); 397 imageResource->loader()->didFinishLoading(0.0, 0, 0);
313 EXPECT_TRUE(imageResource->resourceBuffer()); 398 EXPECT_TRUE(imageResource->resourceBuffer());
314 EXPECT_FALSE(imageResource->errorOccurred()); 399 EXPECT_FALSE(imageResource->errorOccurred());
315 ASSERT_TRUE(imageResource->getContent()->hasImage()); 400 ASSERT_TRUE(imageResource->getContent()->hasImage());
316 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 401 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
317 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 402 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
318 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 403 EXPECT_EQ(kJpegImageHeight,
404 imageResource->getContent()->getImage()->height());
319 EXPECT_EQ(1, observer->imageChangedCount()); 405 EXPECT_EQ(1, observer->imageChangedCount());
320 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 406 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
321 EXPECT_EQ(1, observer2->imageChangedCount()); 407 EXPECT_EQ(1, observer2->imageChangedCount());
322 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); 408 EXPECT_TRUE(observer2->imageNotifyFinishedCalled());
323 } 409 }
324 410
325 TEST(ImageResourceTest, CancelOnRemoveObserver) { 411 TEST(ImageResourceTest, CancelOnRemoveObserver) {
326 KURL testURL(ParsedURLString, kTestURL); 412 KURL testURL(ParsedURLString, kTestURL);
327 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 413 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
328 414
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 imageResource->finish(); 527 imageResource->finish();
442 EXPECT_FALSE(imageResource->errorOccurred()); 528 EXPECT_FALSE(imageResource->errorOccurred());
443 ASSERT_TRUE(imageResource->getContent()->hasImage()); 529 ASSERT_TRUE(imageResource->getContent()->hasImage());
444 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 530 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
445 EXPECT_EQ(2, observer->imageChangedCount()); 531 EXPECT_EQ(2, observer->imageChangedCount());
446 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); 532 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
447 // The observer should have been notified that the image load completed. 533 // The observer should have been notified that the image load completed.
448 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 534 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
449 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); 535 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
450 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 536 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
451 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 537 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
452 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 538 EXPECT_EQ(kJpegImageHeight,
539 imageResource->getContent()->getImage()->height());
453 540
454 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading. 541 // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading.
455 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, 542 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher,
456 Resource::kReloadAlways); 543 Resource::kReloadAlways);
457 544
458 EXPECT_EQ(3, observer->imageChangedCount()); 545 EXPECT_EQ(3, observer->imageChangedCount());
459 testThatReloadIsStartedThenServeReload( 546 testThatReloadIsStartedThenServeReload(
460 testURL, imageResource, imageResource->getContent(), observer.get(), 547 testURL, imageResource, imageResource->getContent(), observer.get(),
461 WebCachePolicy::BypassingCache); 548 WebCachePolicy::BypassingCache);
462 } 549 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 imageResource->loader()->didReceiveData( 613 imageResource->loader()->didReceiveData(
527 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage)); 614 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
528 615
529 EXPECT_FALSE(imageResource->errorOccurred()); 616 EXPECT_FALSE(imageResource->errorOccurred());
530 ASSERT_TRUE(imageResource->getContent()->hasImage()); 617 ASSERT_TRUE(imageResource->getContent()->hasImage());
531 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 618 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
532 EXPECT_EQ(1, observer->imageChangedCount()); 619 EXPECT_EQ(1, observer->imageChangedCount());
533 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); 620 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
534 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); 621 EXPECT_FALSE(observer->imageNotifyFinishedCalled());
535 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 622 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
536 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 623 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
537 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 624 EXPECT_EQ(kJpegImageHeight,
625 imageResource->getContent()->getImage()->height());
538 626
539 // Call reloadIfLoFiOrPlaceholderImage() while the image is still loading. 627 // Call reloadIfLoFiOrPlaceholderImage() while the image is still loading.
540 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, 628 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher,
541 Resource::kReloadAlways); 629 Resource::kReloadAlways);
542 630
543 EXPECT_EQ(2, observer->imageChangedCount()); 631 EXPECT_EQ(2, observer->imageChangedCount());
544 EXPECT_EQ(0, observer->imageWidthOnLastImageChanged()); 632 EXPECT_EQ(0, observer->imageWidthOnLastImageChanged());
545 // The observer should not have been notified of completion yet, since the 633 // The observer should not have been notified of completion yet, since the
546 // image is still loading. 634 // image is still loading.
547 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); 635 EXPECT_FALSE(observer->imageNotifyFinishedCalled());
548 636
549 testThatReloadIsStartedThenServeReload( 637 testThatReloadIsStartedThenServeReload(
550 testURL, imageResource, imageResource->getContent(), observer.get(), 638 testURL, imageResource, imageResource->getContent(), observer.get(),
551 WebCachePolicy::BypassingCache); 639 WebCachePolicy::BypassingCache);
552 } 640 }
553 641
554 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) { 642 TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
555 KURL testURL(ParsedURLString, kTestURL); 643 KURL testURL(ParsedURLString, kTestURL);
556 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 644 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
557 645
558 ResourceFetcher* fetcher = createFetcher(); 646 ResourceFetcher* fetcher = createFetcher();
559 FetchRequest request(testURL, FetchInitiatorInfo()); 647 FetchRequest request(testURL, FetchInitiatorInfo());
560 request.setAllowImagePlaceholder(); 648 request.setAllowImagePlaceholder();
561 ImageResource* imageResource = ImageResource::fetch(request, fetcher); 649 ImageResource* imageResource = ImageResource::fetch(request, fetcher);
562 EXPECT_EQ(FetchRequest::AllowPlaceholder, 650 EXPECT_EQ(FetchRequest::AllowPlaceholder,
563 request.placeholderImageRequestType()); 651 request.placeholderImageRequestType());
564 EXPECT_EQ("bytes=0-2047",
565 imageResource->resourceRequest().httpHeaderField("range"));
566 std::unique_ptr<MockImageResourceObserver> observer = 652 std::unique_ptr<MockImageResourceObserver> observer =
567 MockImageResourceObserver::create(imageResource->getContent()); 653 MockImageResourceObserver::create(imageResource->getContent());
568 654
569 ResourceResponse response(testURL, "image/jpeg", 655 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource,
570 kJpegImageSubrangeWithDimensionsLength, nullAtom); 656 observer.get());
571 response.setHTTPStatusCode(206);
572 response.setHTTPHeaderField(
573 "content-range", buildContentRange(kJpegImageSubrangeWithDimensionsLength,
574 sizeof(kJpegImage)));
575 imageResource->loader()->didReceiveResponse(
576 WrappedResourceResponse(response));
577 imageResource->loader()->didReceiveData(
578 reinterpret_cast<const char*>(kJpegImage),
579 kJpegImageSubrangeWithDimensionsLength);
580 imageResource->loader()->didFinishLoading(
581 0.0, kJpegImageSubrangeWithDimensionsLength,
582 kJpegImageSubrangeWithDimensionsLength);
583
584 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
585 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
586 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
587 657
588 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher, 658 imageResource->reloadIfLoFiOrPlaceholderImage(fetcher,
589 Resource::kReloadAlways); 659 Resource::kReloadAlways);
590 660
591 testThatReloadIsStartedThenServeReload( 661 testThatReloadIsStartedThenServeReload(
592 testURL, imageResource, imageResource->getContent(), observer.get(), 662 testURL, imageResource, imageResource->getContent(), observer.get(),
593 WebCachePolicy::BypassingCache); 663 WebCachePolicy::BypassingCache);
594 } 664 }
595 665
596 TEST(ImageResourceTest, SVGImage) { 666 TEST(ImageResourceTest, SVGImage) {
(...skipping 22 matching lines...) Expand all
619 receiveResponse(imageResource, url, "image/jpeg", 689 receiveResponse(imageResource, url, "image/jpeg",
620 reinterpret_cast<const char*>(kJpegImage), 690 reinterpret_cast<const char*>(kJpegImage),
621 sizeof(kJpegImage)); 691 sizeof(kJpegImage));
622 692
623 EXPECT_FALSE(imageResource->errorOccurred()); 693 EXPECT_FALSE(imageResource->errorOccurred());
624 ASSERT_TRUE(imageResource->getContent()->hasImage()); 694 ASSERT_TRUE(imageResource->getContent()->hasImage());
625 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 695 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
626 EXPECT_EQ(2, observer->imageChangedCount()); 696 EXPECT_EQ(2, observer->imageChangedCount());
627 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 697 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
628 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 698 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
629 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 699 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
630 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 700 EXPECT_EQ(kJpegImageHeight,
701 imageResource->getContent()->getImage()->height());
631 702
632 imageResource->setRevalidatingRequest(ResourceRequest(url)); 703 imageResource->setRevalidatingRequest(ResourceRequest(url));
633 ResourceResponse response; 704 ResourceResponse response;
634 response.setURL(url); 705 response.setURL(url);
635 response.setHTTPStatusCode(304); 706 response.setHTTPStatusCode(304);
636 707
637 imageResource->responseReceived(response, nullptr); 708 imageResource->responseReceived(response, nullptr);
638 709
639 EXPECT_FALSE(imageResource->errorOccurred()); 710 EXPECT_FALSE(imageResource->errorOccurred());
640 ASSERT_TRUE(imageResource->getContent()->hasImage()); 711 ASSERT_TRUE(imageResource->getContent()->hasImage());
641 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 712 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
642 EXPECT_EQ(2, observer->imageChangedCount()); 713 EXPECT_EQ(2, observer->imageChangedCount());
643 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 714 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
644 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 715 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
645 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 716 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
646 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 717 EXPECT_EQ(kJpegImageHeight,
718 imageResource->getContent()->getImage()->height());
647 } 719 }
648 720
649 TEST(ImageResourceTest, SuccessfulRevalidationSvg) { 721 TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
650 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); 722 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
651 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); 723 ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
652 std::unique_ptr<MockImageResourceObserver> observer = 724 std::unique_ptr<MockImageResourceObserver> observer =
653 MockImageResourceObserver::create(imageResource->getContent()); 725 MockImageResourceObserver::create(imageResource->getContent());
654 726
655 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, 727 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
656 strlen(kSvgImage)); 728 strlen(kSvgImage));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 receiveResponse(imageResource, url, "image/jpeg", 761 receiveResponse(imageResource, url, "image/jpeg",
690 reinterpret_cast<const char*>(kJpegImage), 762 reinterpret_cast<const char*>(kJpegImage),
691 sizeof(kJpegImage)); 763 sizeof(kJpegImage));
692 764
693 EXPECT_FALSE(imageResource->errorOccurred()); 765 EXPECT_FALSE(imageResource->errorOccurred());
694 ASSERT_TRUE(imageResource->getContent()->hasImage()); 766 ASSERT_TRUE(imageResource->getContent()->hasImage());
695 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 767 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
696 EXPECT_EQ(2, observer->imageChangedCount()); 768 EXPECT_EQ(2, observer->imageChangedCount());
697 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 769 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
698 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 770 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
699 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 771 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
700 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 772 EXPECT_EQ(kJpegImageHeight,
773 imageResource->getContent()->getImage()->height());
701 774
702 imageResource->setRevalidatingRequest(ResourceRequest(url)); 775 imageResource->setRevalidatingRequest(ResourceRequest(url));
703 receiveResponse(imageResource, url, "image/jpeg", 776 receiveResponse(imageResource, url, "image/jpeg",
704 reinterpret_cast<const char*>(kJpegImage2), 777 reinterpret_cast<const char*>(kJpegImage2),
705 sizeof(kJpegImage2)); 778 sizeof(kJpegImage2));
706 779
707 EXPECT_FALSE(imageResource->errorOccurred()); 780 EXPECT_FALSE(imageResource->errorOccurred());
708 ASSERT_TRUE(imageResource->getContent()->hasImage()); 781 ASSERT_TRUE(imageResource->getContent()->hasImage());
709 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 782 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
710 EXPECT_EQ(4, observer->imageChangedCount()); 783 EXPECT_EQ(4, observer->imageChangedCount());
(...skipping 12 matching lines...) Expand all
723 receiveResponse(imageResource, url, "image/jpeg", 796 receiveResponse(imageResource, url, "image/jpeg",
724 reinterpret_cast<const char*>(kJpegImage), 797 reinterpret_cast<const char*>(kJpegImage),
725 sizeof(kJpegImage)); 798 sizeof(kJpegImage));
726 799
727 EXPECT_FALSE(imageResource->errorOccurred()); 800 EXPECT_FALSE(imageResource->errorOccurred());
728 ASSERT_TRUE(imageResource->getContent()->hasImage()); 801 ASSERT_TRUE(imageResource->getContent()->hasImage());
729 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 802 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
730 EXPECT_EQ(2, observer->imageChangedCount()); 803 EXPECT_EQ(2, observer->imageChangedCount());
731 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 804 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
732 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 805 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
733 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 806 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
734 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 807 EXPECT_EQ(kJpegImageHeight,
808 imageResource->getContent()->getImage()->height());
735 809
736 imageResource->setRevalidatingRequest(ResourceRequest(url)); 810 imageResource->setRevalidatingRequest(ResourceRequest(url));
737 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, 811 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
738 strlen(kSvgImage)); 812 strlen(kSvgImage));
739 813
740 EXPECT_FALSE(imageResource->errorOccurred()); 814 EXPECT_FALSE(imageResource->errorOccurred());
741 ASSERT_TRUE(imageResource->getContent()->hasImage()); 815 ASSERT_TRUE(imageResource->getContent()->hasImage());
742 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 816 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
743 EXPECT_EQ(3, observer->imageChangedCount()); 817 EXPECT_EQ(3, observer->imageChangedCount());
744 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 818 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
(...skipping 24 matching lines...) Expand all
769 receiveResponse(imageResource, url, "image/jpeg", 843 receiveResponse(imageResource, url, "image/jpeg",
770 reinterpret_cast<const char*>(kJpegImage), 844 reinterpret_cast<const char*>(kJpegImage),
771 sizeof(kJpegImage)); 845 sizeof(kJpegImage));
772 846
773 EXPECT_FALSE(imageResource->errorOccurred()); 847 EXPECT_FALSE(imageResource->errorOccurred());
774 ASSERT_TRUE(imageResource->getContent()->hasImage()); 848 ASSERT_TRUE(imageResource->getContent()->hasImage());
775 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 849 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
776 EXPECT_EQ(3, observer->imageChangedCount()); 850 EXPECT_EQ(3, observer->imageChangedCount());
777 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 851 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
778 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 852 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
779 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 853 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
780 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 854 EXPECT_EQ(kJpegImageHeight,
855 imageResource->getContent()->getImage()->height());
781 } 856 }
782 857
783 TEST(ImageResourceTest, FailedRevalidationSvgToSvg) { 858 TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
784 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); 859 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
785 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); 860 ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
786 std::unique_ptr<MockImageResourceObserver> observer = 861 std::unique_ptr<MockImageResourceObserver> observer =
787 MockImageResourceObserver::create(imageResource->getContent()); 862 MockImageResourceObserver::create(imageResource->getContent());
788 863
789 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage, 864 receiveResponse(imageResource, url, "image/svg+xml", kSvgImage,
790 strlen(kSvgImage)); 865 strlen(kSvgImage));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 Persistent<MockResourceClient> client1 = 897 Persistent<MockResourceClient> client1 =
823 new MockResourceClient(imageResource); 898 new MockResourceClient(imageResource);
824 899
825 receiveResponse(imageResource, url, "image/jpeg", 900 receiveResponse(imageResource, url, "image/jpeg",
826 reinterpret_cast<const char*>(kJpegImage), 901 reinterpret_cast<const char*>(kJpegImage),
827 sizeof(kJpegImage)); 902 sizeof(kJpegImage));
828 903
829 EXPECT_FALSE(imageResource->errorOccurred()); 904 EXPECT_FALSE(imageResource->errorOccurred());
830 ASSERT_TRUE(imageResource->getContent()->hasImage()); 905 ASSERT_TRUE(imageResource->getContent()->hasImage());
831 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 906 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
832 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 907 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
833 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 908 EXPECT_EQ(kJpegImageHeight,
909 imageResource->getContent()->getImage()->height());
834 EXPECT_TRUE(client1->notifyFinishedCalled()); 910 EXPECT_TRUE(client1->notifyFinishedCalled());
835 911
836 client1->removeAsClient(); 912 client1->removeAsClient();
837 913
838 EXPECT_FALSE(imageResource->isAlive()); 914 EXPECT_FALSE(imageResource->isAlive());
839 915
840 imageResource->prune(); 916 imageResource->prune();
841 917
842 EXPECT_TRUE(imageResource->getContent()->hasImage()); 918 EXPECT_TRUE(imageResource->getContent()->hasImage());
843 919
844 // Re-adds a ResourceClient but not ImageResourceObserver. 920 // Re-adds a ResourceClient but not ImageResourceObserver.
845 Persistent<MockResourceClient> client2 = 921 Persistent<MockResourceClient> client2 =
846 new MockResourceClient(imageResource); 922 new MockResourceClient(imageResource);
847 923
848 ASSERT_TRUE(imageResource->getContent()->hasImage()); 924 ASSERT_TRUE(imageResource->getContent()->hasImage());
849 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); 925 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
850 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 926 EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
851 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 927 EXPECT_EQ(kJpegImageHeight,
928 imageResource->getContent()->getImage()->height());
852 EXPECT_TRUE(client2->notifyFinishedCalled()); 929 EXPECT_TRUE(client2->notifyFinishedCalled());
853 } 930 }
854 931
855 TEST(ImageResourceTest, CancelOnDecodeError) { 932 TEST(ImageResourceTest, CancelOnDecodeError) {
856 KURL testURL(ParsedURLString, kTestURL); 933 KURL testURL(ParsedURLString, kTestURL);
857 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 934 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
858 935
859 ResourceFetcher* fetcher = createFetcher(); 936 ResourceFetcher* fetcher = createFetcher();
860 FetchRequest request(testURL, FetchInitiatorInfo()); 937 FetchRequest request(testURL, FetchInitiatorInfo());
861 ImageResource* imageResource = ImageResource::fetch(request, fetcher); 938 ImageResource* imageResource = ImageResource::fetch(request, fetcher);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 } 1031 }
955 1032
956 TEST(ImageResourceTest, FetchDisallowPlaceholder) { 1033 TEST(ImageResourceTest, FetchDisallowPlaceholder) {
957 KURL testURL(ParsedURLString, kTestURL); 1034 KURL testURL(ParsedURLString, kTestURL);
958 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 1035 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
959 1036
960 FetchRequest request(testURL, FetchInitiatorInfo()); 1037 FetchRequest request(testURL, FetchInitiatorInfo());
961 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); 1038 ImageResource* imageResource = ImageResource::fetch(request, createFetcher());
962 EXPECT_EQ(FetchRequest::DisallowPlaceholder, 1039 EXPECT_EQ(FetchRequest::DisallowPlaceholder,
963 request.placeholderImageRequestType()); 1040 request.placeholderImageRequestType());
964 EXPECT_EQ(nullAtom,
965 imageResource->resourceRequest().httpHeaderField("range"));
966 EXPECT_FALSE(imageResource->shouldShowPlaceholder());
967 std::unique_ptr<MockImageResourceObserver> observer = 1041 std::unique_ptr<MockImageResourceObserver> observer =
968 MockImageResourceObserver::create(imageResource->getContent()); 1042 MockImageResourceObserver::create(imageResource->getContent());
969 1043
970 imageResource->loader()->didReceiveResponse(WrappedResourceResponse( 1044 testThatIsNotPlaceholderRequestAndServeResponse(testURL, imageResource,
971 ResourceResponse(testURL, "image/jpeg", sizeof(kJpegImage), nullAtom))); 1045 observer.get());
972 imageResource->loader()->didReceiveData(
973 reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
974 imageResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage),
975 sizeof(kJpegImage));
976
977 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
978 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize());
979 EXPECT_FALSE(imageResource->shouldShowPlaceholder());
980 EXPECT_LT(0, observer->imageChangedCount());
981 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
982 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
983 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
984
985 ASSERT_TRUE(imageResource->getContent()->hasImage());
986 EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
987 EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
988 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
989 } 1046 }
990 1047
991 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) { 1048 TEST(ImageResourceTest, FetchAllowPlaceholderDataURL) {
992 KURL testURL(ParsedURLString, 1049 KURL testURL(ParsedURLString,
993 "data:image/jpeg;base64," + 1050 "data:image/jpeg;base64," +
994 base64Encode(reinterpret_cast<const char*>(kJpegImage), 1051 base64Encode(reinterpret_cast<const char*>(kJpegImage),
995 sizeof(kJpegImage))); 1052 sizeof(kJpegImage)));
996 FetchRequest request(testURL, FetchInitiatorInfo()); 1053 FetchRequest request(testURL, FetchInitiatorInfo());
997 request.setAllowImagePlaceholder(); 1054 request.setAllowImagePlaceholder();
998 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); 1055 ImageResource* imageResource = ImageResource::fetch(request, createFetcher());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1096
1040 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) { 1097 TEST(ImageResourceTest, FetchAllowPlaceholderSuccessful) {
1041 KURL testURL(ParsedURLString, kTestURL); 1098 KURL testURL(ParsedURLString, kTestURL);
1042 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 1099 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
1043 1100
1044 FetchRequest request(testURL, FetchInitiatorInfo()); 1101 FetchRequest request(testURL, FetchInitiatorInfo());
1045 request.setAllowImagePlaceholder(); 1102 request.setAllowImagePlaceholder();
1046 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); 1103 ImageResource* imageResource = ImageResource::fetch(request, createFetcher());
1047 EXPECT_EQ(FetchRequest::AllowPlaceholder, 1104 EXPECT_EQ(FetchRequest::AllowPlaceholder,
1048 request.placeholderImageRequestType()); 1105 request.placeholderImageRequestType());
1049 EXPECT_EQ("bytes=0-2047",
1050 imageResource->resourceRequest().httpHeaderField("range"));
1051 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
1052 std::unique_ptr<MockImageResourceObserver> observer = 1106 std::unique_ptr<MockImageResourceObserver> observer =
1053 MockImageResourceObserver::create(imageResource->getContent()); 1107 MockImageResourceObserver::create(imageResource->getContent());
1054 1108
1055 ResourceResponse response(testURL, "image/jpeg", 1109 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource,
1056 kJpegImageSubrangeWithDimensionsLength, nullAtom); 1110 observer.get());
1057 response.setHTTPStatusCode(206);
1058 response.setHTTPHeaderField(
1059 "content-range", buildContentRange(kJpegImageSubrangeWithDimensionsLength,
1060 sizeof(kJpegImage)));
1061 imageResource->loader()->didReceiveResponse(
1062 WrappedResourceResponse(response));
1063 imageResource->loader()->didReceiveData(
1064 reinterpret_cast<const char*>(kJpegImage),
1065 kJpegImageSubrangeWithDimensionsLength);
1066 imageResource->loader()->didFinishLoading(
1067 0.0, kJpegImageSubrangeWithDimensionsLength,
1068 kJpegImageSubrangeWithDimensionsLength);
1069
1070 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
1071 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
1072 imageResource->encodedSize());
1073 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
1074 EXPECT_LT(0, observer->imageChangedCount());
1075 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
1076 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1077 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
1078
1079 ASSERT_TRUE(imageResource->getContent()->hasImage());
1080 EXPECT_EQ(1, imageResource->getContent()->getImage()->width());
1081 EXPECT_EQ(1, imageResource->getContent()->getImage()->height());
1082 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
1083 EXPECT_FALSE(imageResource->getContent()->getImage()->isSVGImage());
1084 } 1111 }
1085 1112
1086 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) { 1113 TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
1087 KURL testURL(ParsedURLString, kTestURL); 1114 KURL testURL(ParsedURLString, kTestURL);
1088 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 1115 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
1089 1116
1090 FetchRequest request(testURL, FetchInitiatorInfo()); 1117 FetchRequest request(testURL, FetchInitiatorInfo());
1091 request.setAllowImagePlaceholder(); 1118 request.setAllowImagePlaceholder();
1092 ImageResource* imageResource = ImageResource::fetch(request, createFetcher()); 1119 ImageResource* imageResource = ImageResource::fetch(request, createFetcher());
1093 EXPECT_EQ(FetchRequest::AllowPlaceholder, 1120 EXPECT_EQ(FetchRequest::AllowPlaceholder,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 testThatReloadIsStartedThenServeReload( 1194 testThatReloadIsStartedThenServeReload(
1168 testURL, imageResource, imageResource->getContent(), observer.get(), 1195 testURL, imageResource, imageResource->getContent(), observer.get(),
1169 WebCachePolicy::BypassingCache); 1196 WebCachePolicy::BypassingCache);
1170 } 1197 }
1171 1198
1172 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) { 1199 TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
1173 KURL testURL(ParsedURLString, kTestURL); 1200 KURL testURL(ParsedURLString, kTestURL);
1174 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 1201 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
1175 1202
1176 ResourceFetcher* fetcher = createFetcher(); 1203 ResourceFetcher* fetcher = createFetcher();
1204
1177 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); 1205 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo());
1178 placeholderRequest.setAllowImagePlaceholder(); 1206 placeholderRequest.setAllowImagePlaceholder();
1179 ImageResource* imageResource = 1207 ImageResource* imageResource =
1180 ImageResource::fetch(placeholderRequest, fetcher); 1208 ImageResource::fetch(placeholderRequest, fetcher);
1181 std::unique_ptr<MockImageResourceObserver> observer = 1209 std::unique_ptr<MockImageResourceObserver> observer =
1182 MockImageResourceObserver::create(imageResource->getContent()); 1210 MockImageResourceObserver::create(imageResource->getContent());
1183 1211
1184 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); 1212 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
1185 ImageResource* secondImageResource = 1213 ImageResource* secondImageResource =
1186 ImageResource::fetch(nonPlaceholderRequest, fetcher); 1214 ImageResource::fetch(nonPlaceholderRequest, fetcher);
(...skipping 12 matching lines...) Expand all
1199 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath()); 1227 ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
1200 1228
1201 ResourceFetcher* fetcher = createFetcher(); 1229 ResourceFetcher* fetcher = createFetcher();
1202 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo()); 1230 FetchRequest placeholderRequest(testURL, FetchInitiatorInfo());
1203 placeholderRequest.setAllowImagePlaceholder(); 1231 placeholderRequest.setAllowImagePlaceholder();
1204 ImageResource* imageResource = 1232 ImageResource* imageResource =
1205 ImageResource::fetch(placeholderRequest, fetcher); 1233 ImageResource::fetch(placeholderRequest, fetcher);
1206 std::unique_ptr<MockImageResourceObserver> observer = 1234 std::unique_ptr<MockImageResourceObserver> observer =
1207 MockImageResourceObserver::create(imageResource->getContent()); 1235 MockImageResourceObserver::create(imageResource->getContent());
1208 1236
1209 ResourceResponse response(testURL, "image/jpeg", 1237 testThatIsPlaceholderRequestAndServeResponse(testURL, imageResource,
1210 kJpegImageSubrangeWithDimensionsLength, nullAtom); 1238 observer.get());
1211 response.setHTTPStatusCode(206);
1212 response.setHTTPHeaderField(
1213 "content-range", buildContentRange(kJpegImageSubrangeWithDimensionsLength,
1214 sizeof(kJpegImage)));
1215 imageResource->loader()->didReceiveResponse(
1216 WrappedResourceResponse(response));
1217 imageResource->loader()->didReceiveData(
1218 reinterpret_cast<const char*>(kJpegImage),
1219 kJpegImageSubrangeWithDimensionsLength);
1220 imageResource->loader()->didFinishLoading(
1221 0.0, kJpegImageSubrangeWithDimensionsLength,
1222 kJpegImageSubrangeWithDimensionsLength);
1223
1224 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
1225 EXPECT_EQ(kJpegImageSubrangeWithDimensionsLength,
1226 imageResource->encodedSize());
1227 EXPECT_TRUE(imageResource->shouldShowPlaceholder());
1228 EXPECT_LT(0, observer->imageChangedCount());
1229 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1230 1239
1231 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo()); 1240 FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
1232 ImageResource* secondImageResource = 1241 ImageResource* secondImageResource =
1233 ImageResource::fetch(nonPlaceholderRequest, fetcher); 1242 ImageResource::fetch(nonPlaceholderRequest, fetcher);
1234 EXPECT_EQ(imageResource, secondImageResource); 1243 EXPECT_EQ(imageResource, secondImageResource);
1235 1244
1236 testThatReloadIsStartedThenServeReload( 1245 testThatReloadIsStartedThenServeReload(
1237 testURL, imageResource, imageResource->getContent(), observer.get(), 1246 testURL, imageResource, imageResource->getContent(), observer.get(),
1238 WebCachePolicy::UseProtocolCachePolicy); 1247 WebCachePolicy::UseProtocolCachePolicy);
1239 } 1248 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 1286
1278 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus()); 1287 EXPECT_EQ(ResourceStatus::Cached, imageResource->getStatus());
1279 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize()); 1288 EXPECT_EQ(sizeof(kJpegImage), imageResource->encodedSize());
1280 EXPECT_FALSE(imageResource->shouldShowPlaceholder()); 1289 EXPECT_FALSE(imageResource->shouldShowPlaceholder());
1281 EXPECT_LT(0, observer->imageChangedCount()); 1290 EXPECT_LT(0, observer->imageChangedCount());
1282 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged()); 1291 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
1283 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 1292 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1284 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished()); 1293 EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
1285 1294
1286 ASSERT_TRUE(imageResource->getContent()->hasImage()); 1295 ASSERT_TRUE(imageResource->getContent()->hasImage());
1287 EXPECT_EQ(1, imageResource->getContent()->getImage()->width()); 1296 EXPECT_EQ(kJpegImageWidth,
1288 EXPECT_EQ(1, imageResource->getContent()->getImage()->height()); 1297 imageResource->getContent()->getImage()->width());
1298 EXPECT_EQ(kJpegImageHeight,
1299 imageResource->getContent()->getImage()->height());
1289 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 1300 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
1290 } 1301 }
1291 } 1302 }
1292 1303
1293 TEST(ImageResourceTest, 1304 TEST(ImageResourceTest,
1294 FetchAllowPlaceholderFullResponseDecodeFailureNoReload) { 1305 FetchAllowPlaceholderFullResponseDecodeFailureNoReload) {
1295 static const char kBadImageData[] = "bad image data"; 1306 static const char kBadImageData[] = "bad image data";
1296 1307
1297 const struct { 1308 const struct {
1298 int statusCode; 1309 int statusCode;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); 1464 EXPECT_TRUE(observer->imageNotifyFinishedCalled());
1454 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); 1465 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
1455 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); 1466 EXPECT_EQ(50, imageResource->getContent()->getImage()->width());
1456 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); 1467 EXPECT_EQ(50, imageResource->getContent()->getImage()->height());
1457 1468
1458 WTF::setTimeFunctionsForTesting(nullptr); 1469 WTF::setTimeFunctionsForTesting(nullptr);
1459 } 1470 }
1460 1471
1461 } // namespace 1472 } // namespace
1462 } // namespace blink 1473 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698