| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" | 154 "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" |
| 155 "<rect x=\"0\" y=\"0\" width=\"200px\" height=\"200px\" fill=\"green\"/>" | 155 "<rect x=\"0\" y=\"0\" width=\"200px\" height=\"200px\" fill=\"green\"/>" |
| 156 "</svg>"; | 156 "</svg>"; |
| 157 | 157 |
| 158 constexpr char kTestURL[] = "http://www.test.com/cancelTest.html"; | 158 constexpr char kTestURL[] = "http://www.test.com/cancelTest.html"; |
| 159 | 159 |
| 160 String GetTestFilePath() { | 160 String GetTestFilePath() { |
| 161 return testing::webTestDataPath("cancelTest.html"); | 161 return testing::webTestDataPath("cancelTest.html"); |
| 162 } | 162 } |
| 163 | 163 |
| 164 const char kSvgImageWithSubresource[] = |
| 165 "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"198\" height=\"100\">" |
| 166 "<style>" |
| 167 " <![CDATA[@font-face{font-family:\"test\"; " |
| 168 " src:url('data:font/ttf;base64,invalidFontData');}]]>" |
| 169 "</style>" |
| 170 "<text x=\"50\" y=\"50\" font-family=\"test\" font-size=\"16\">Fox</text>" |
| 171 "</svg>"; |
| 172 |
| 164 void receiveResponse(ImageResource* imageResource, | 173 void receiveResponse(ImageResource* imageResource, |
| 165 const KURL& url, | 174 const KURL& url, |
| 166 const AtomicString& mimeType, | 175 const AtomicString& mimeType, |
| 167 const char* data, | 176 const char* data, |
| 168 size_t dataSize) { | 177 size_t dataSize) { |
| 169 ResourceResponse response; | 178 ResourceResponse response; |
| 170 response.setURL(url); | 179 response.setURL(url); |
| 171 response.setHTTPStatusCode(200); | 180 response.setHTTPStatusCode(200); |
| 172 response.setMimeType(mimeType); | 181 response.setMimeType(mimeType); |
| 173 imageResource->responseReceived(response, nullptr); | 182 imageResource->responseReceived(response, nullptr); |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 strlen(kSvgImage)); | 710 strlen(kSvgImage)); |
| 702 | 711 |
| 703 EXPECT_FALSE(imageResource->errorOccurred()); | 712 EXPECT_FALSE(imageResource->errorOccurred()); |
| 704 ASSERT_TRUE(imageResource->getContent()->hasImage()); | 713 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 705 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); | 714 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 706 EXPECT_EQ(1, observer->imageChangedCount()); | 715 EXPECT_EQ(1, observer->imageChangedCount()); |
| 707 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 716 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 708 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); | 717 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 709 } | 718 } |
| 710 | 719 |
| 720 TEST(ImageResourceTest, SVGImageWithSubresource) { |
| 721 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
| 722 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
| 723 std::unique_ptr<MockImageResourceObserver> observer = |
| 724 MockImageResourceObserver::create(imageResource->getContent()); |
| 725 |
| 726 receiveResponse(imageResource, url, "image/svg+xml", kSvgImageWithSubresource, |
| 727 strlen(kSvgImageWithSubresource)); |
| 728 |
| 729 EXPECT_FALSE(imageResource->errorOccurred()); |
| 730 ASSERT_TRUE(imageResource->getContent()->hasImage()); |
| 731 EXPECT_FALSE(imageResource->getContent()->getImage()->isNull()); |
| 732 EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 733 |
| 734 // At this point, image is (mostly) available but the loading is not yet |
| 735 // finished because of SVG's subresources, and thus imageChanged() or |
| 736 // imageNotifyFinished() are not called. |
| 737 EXPECT_EQ(1, observer->imageChangedCount()); |
| 738 EXPECT_FALSE(observer->imageNotifyFinishedCalled()); |
| 739 EXPECT_EQ(198, imageResource->getContent()->getImage()->width()); |
| 740 EXPECT_EQ(100, imageResource->getContent()->getImage()->height()); |
| 741 |
| 742 // A new client added here shouldn't notified of finish. |
| 743 std::unique_ptr<MockImageResourceObserver> observer2 = |
| 744 MockImageResourceObserver::create(imageResource->getContent()); |
| 745 EXPECT_EQ(1, observer2->imageChangedCount()); |
| 746 EXPECT_FALSE(observer2->imageNotifyFinishedCalled()); |
| 747 |
| 748 // After asynchronous tasks are executed, the loading of SVG document is |
| 749 // completed and imageNotifyFinished() is called. |
| 750 testing::runPendingTasks(); |
| 751 EXPECT_EQ(2, observer->imageChangedCount()); |
| 752 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 753 EXPECT_EQ(2, observer2->imageChangedCount()); |
| 754 EXPECT_TRUE(observer2->imageNotifyFinishedCalled()); |
| 755 EXPECT_EQ(198, imageResource->getContent()->getImage()->width()); |
| 756 EXPECT_EQ(100, imageResource->getContent()->getImage()->height()); |
| 757 } |
| 758 |
| 711 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) { | 759 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) { |
| 712 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); | 760 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo"); |
| 713 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); | 761 ImageResource* imageResource = ImageResource::create(ResourceRequest(url)); |
| 714 std::unique_ptr<MockImageResourceObserver> observer = | 762 std::unique_ptr<MockImageResourceObserver> observer = |
| 715 MockImageResourceObserver::create(imageResource->getContent()); | 763 MockImageResourceObserver::create(imageResource->getContent()); |
| 716 | 764 |
| 717 receiveResponse(imageResource, url, "image/jpeg", | 765 receiveResponse(imageResource, url, "image/jpeg", |
| 718 reinterpret_cast<const char*>(kJpegImage), | 766 reinterpret_cast<const char*>(kJpegImage), |
| 719 sizeof(kJpegImage)); | 767 sizeof(kJpegImage)); |
| 720 | 768 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1601 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1554 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1602 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1555 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1603 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1556 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1604 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1557 | 1605 |
| 1558 WTF::setTimeFunctionsForTesting(nullptr); | 1606 WTF::setTimeFunctionsForTesting(nullptr); |
| 1559 } | 1607 } |
| 1560 | 1608 |
| 1561 } // namespace | 1609 } // namespace |
| 1562 } // namespace blink | 1610 } // namespace blink |
| OLD | NEW |