| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // the new image (of width |imageWidth|). | 237 // the new image (of width |imageWidth|). |
| 238 EXPECT_EQ(kImageWidth, observer->ImageWidthOnImageNotifyFinished()); | 238 EXPECT_EQ(kImageWidth, observer->ImageWidthOnImageNotifyFinished()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Checks |content| receives the correct image. | 241 // Checks |content| receives the correct image. |
| 242 EXPECT_TRUE(content->HasImage()); | 242 EXPECT_TRUE(content->HasImage()); |
| 243 EXPECT_FALSE(content->GetImage()->IsNull()); | 243 EXPECT_FALSE(content->GetImage()->IsNull()); |
| 244 EXPECT_EQ(kImageWidth, content->GetImage()->width()); | 244 EXPECT_EQ(kImageWidth, content->GetImage()->width()); |
| 245 EXPECT_EQ(kImageHeight, content->GetImage()->height()); | 245 EXPECT_EQ(kImageHeight, content->GetImage()->height()); |
| 246 EXPECT_TRUE(content->GetImage()->IsBitmapImage()); | 246 EXPECT_TRUE(content->GetImage()->IsBitmapImage()); |
| 247 EXPECT_FALSE(content->GetImage()->PaintImageForCurrentFrame().is_multipart()); |
| 247 } | 248 } |
| 248 | 249 |
| 249 AtomicString BuildContentRange(size_t range_length, size_t total_length) { | 250 AtomicString BuildContentRange(size_t range_length, size_t total_length) { |
| 250 return AtomicString(String("bytes 0-" + String::Number(range_length - 1) + | 251 return AtomicString(String("bytes 0-" + String::Number(range_length - 1) + |
| 251 "/" + String::Number(total_length))); | 252 "/" + String::Number(total_length))); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void TestThatIsPlaceholderRequestAndServeResponse( | 255 void TestThatIsPlaceholderRequestAndServeResponse( |
| 255 const KURL& url, | 256 const KURL& url, |
| 256 ImageResource* image_resource, | 257 ImageResource* image_resource, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // This part finishes. The image is created, callbacks are sent, and the data | 412 // This part finishes. The image is created, callbacks are sent, and the data |
| 412 // buffer is cleared. | 413 // buffer is cleared. |
| 413 image_resource->Loader()->DidFinishLoading(0.0, 0, 0, 0); | 414 image_resource->Loader()->DidFinishLoading(0.0, 0, 0, 0); |
| 414 EXPECT_TRUE(image_resource->ResourceBuffer()); | 415 EXPECT_TRUE(image_resource->ResourceBuffer()); |
| 415 EXPECT_FALSE(image_resource->ErrorOccurred()); | 416 EXPECT_FALSE(image_resource->ErrorOccurred()); |
| 416 ASSERT_TRUE(image_resource->GetContent()->HasImage()); | 417 ASSERT_TRUE(image_resource->GetContent()->HasImage()); |
| 417 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull()); | 418 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull()); |
| 418 EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width()); | 419 EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width()); |
| 419 EXPECT_EQ(kJpegImageHeight, | 420 EXPECT_EQ(kJpegImageHeight, |
| 420 image_resource->GetContent()->GetImage()->height()); | 421 image_resource->GetContent()->GetImage()->height()); |
| 422 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsSVGImage()); |
| 423 EXPECT_TRUE(image_resource->GetContent() |
| 424 ->GetImage() |
| 425 ->PaintImageForCurrentFrame() |
| 426 .is_multipart()); |
| 427 |
| 421 EXPECT_EQ(1, observer->ImageChangedCount()); | 428 EXPECT_EQ(1, observer->ImageChangedCount()); |
| 422 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); | 429 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); |
| 423 EXPECT_EQ(1, observer2->ImageChangedCount()); | 430 EXPECT_EQ(1, observer2->ImageChangedCount()); |
| 424 EXPECT_TRUE(observer2->ImageNotifyFinishedCalled()); | 431 EXPECT_TRUE(observer2->ImageNotifyFinishedCalled()); |
| 425 } | 432 } |
| 426 | 433 |
| 434 TEST(ImageResourceTest, BitmapMultipartImage) { |
| 435 ResourceFetcher* fetcher = CreateFetcher(); |
| 436 KURL test_url(kParsedURLString, kTestURL); |
| 437 ScopedMockedURLLoad scoped_mocked_url_load(test_url, GetTestFilePath()); |
| 438 ImageResource* image_resource = |
| 439 ImageResource::Create(ResourceRequest(test_url)); |
| 440 image_resource->SetIdentifier(CreateUniqueIdentifier()); |
| 441 fetcher->StartLoad(image_resource); |
| 442 |
| 443 ResourceResponse multipart_response(KURL(), "multipart/x-mixed-replace", 0, |
| 444 g_null_atom); |
| 445 multipart_response.SetMultipartBoundary("boundary", strlen("boundary")); |
| 446 image_resource->Loader()->DidReceiveResponse( |
| 447 WrappedResourceResponse(multipart_response), nullptr); |
| 448 EXPECT_FALSE(image_resource->GetContent()->HasImage()); |
| 449 |
| 450 const char kBoundary[] = "--boundary\n"; |
| 451 const char kContentType[] = "Content-Type: image/jpeg\n\n"; |
| 452 image_resource->AppendData(kBoundary, strlen(kBoundary)); |
| 453 image_resource->AppendData(kContentType, strlen(kContentType)); |
| 454 image_resource->AppendData(reinterpret_cast<const char*>(kJpegImage), |
| 455 sizeof(kJpegImage)); |
| 456 image_resource->AppendData(kBoundary, strlen(kBoundary)); |
| 457 image_resource->Loader()->DidFinishLoading(0.0, 0, 0, 0); |
| 458 EXPECT_TRUE(image_resource->GetContent()->HasImage()); |
| 459 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage()); |
| 460 EXPECT_TRUE(image_resource->GetContent() |
| 461 ->GetImage() |
| 462 ->PaintImageForCurrentFrame() |
| 463 .is_multipart()); |
| 464 } |
| 465 |
| 427 TEST(ImageResourceTest, CancelOnRemoveObserver) { | 466 TEST(ImageResourceTest, CancelOnRemoveObserver) { |
| 428 KURL test_url(kParsedURLString, kTestURL); | 467 KURL test_url(kParsedURLString, kTestURL); |
| 429 ScopedMockedURLLoad scoped_mocked_url_load(test_url, GetTestFilePath()); | 468 ScopedMockedURLLoad scoped_mocked_url_load(test_url, GetTestFilePath()); |
| 430 | 469 |
| 431 ResourceFetcher* fetcher = CreateFetcher(); | 470 ResourceFetcher* fetcher = CreateFetcher(); |
| 432 | 471 |
| 433 // Emulate starting a real load. | 472 // Emulate starting a real load. |
| 434 ImageResource* image_resource = | 473 ImageResource* image_resource = |
| 435 ImageResource::Create(ResourceRequest(test_url)); | 474 ImageResource::Create(ResourceRequest(test_url)); |
| 436 image_resource->SetIdentifier(CreateUniqueIdentifier()); | 475 image_resource->SetIdentifier(CreateUniqueIdentifier()); |
| (...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); | 1713 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); |
| 1675 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage()); | 1714 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage()); |
| 1676 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width()); | 1715 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width()); |
| 1677 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height()); | 1716 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height()); |
| 1678 | 1717 |
| 1679 WTF::SetTimeFunctionsForTesting(nullptr); | 1718 WTF::SetTimeFunctionsForTesting(nullptr); |
| 1680 } | 1719 } |
| 1681 | 1720 |
| 1682 } // namespace | 1721 } // namespace |
| 1683 } // namespace blink | 1722 } // namespace blink |
| OLD | NEW |