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

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

Issue 2613853002: Phase III Step 2: Call imageNotifyFinished() and image load event after SVG loading completes (Closed)
Patch Set: Reflect comments Created 3 years, 7 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
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
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[] =
yhirano 2017/05/09 08:33:57 constexpr
hiroshige 2017/05/10 22:45:49 Done.
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* image_resource, 173 void ReceiveResponse(ImageResource* image_resource,
165 const KURL& url, 174 const KURL& url,
166 const AtomicString& mime_type, 175 const AtomicString& mime_type,
167 const char* data, 176 const char* data,
168 size_t data_size) { 177 size_t data_size) {
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(mime_type); 181 response.SetMimeType(mime_type);
173 image_resource->SetStatus(ResourceStatus::kPending); 182 image_resource->SetStatus(ResourceStatus::kPending);
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 strlen(kSvgImage)); 775 strlen(kSvgImage));
767 776
768 EXPECT_FALSE(image_resource->ErrorOccurred()); 777 EXPECT_FALSE(image_resource->ErrorOccurred());
769 ASSERT_TRUE(image_resource->GetContent()->HasImage()); 778 ASSERT_TRUE(image_resource->GetContent()->HasImage());
770 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull()); 779 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
771 EXPECT_EQ(1, observer->ImageChangedCount()); 780 EXPECT_EQ(1, observer->ImageChangedCount());
772 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); 781 EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
773 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage()); 782 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
774 } 783 }
775 784
785 TEST(ImageResourceTest, SVGImageWithSubresource) {
786 KURL url(kParsedURLString, "http://127.0.0.1:8000/foo");
787 ImageResource* image_resource = ImageResource::Create(ResourceRequest(url));
788 std::unique_ptr<MockImageResourceObserver> observer =
789 MockImageResourceObserver::Create(image_resource->GetContent());
790
791 ReceiveResponse(image_resource, url, "image/svg+xml",
792 kSvgImageWithSubresource, strlen(kSvgImageWithSubresource));
793
794 EXPECT_FALSE(image_resource->ErrorOccurred());
795 ASSERT_TRUE(image_resource->GetContent()->HasImage());
796 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
797 EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
798
799 // At this point, image is (mostly) available but the loading is not yet
800 // finished because of SVG's subresources, and thus ImageChanged() or
801 // ImageNotifyFinished() are not called.
802 EXPECT_EQ(ResourceStatus::kPending,
803 image_resource->GetContent()->GetContentStatus());
804 EXPECT_EQ(1, observer->ImageChangedCount());
805 EXPECT_FALSE(observer->ImageNotifyFinishedCalled());
806 EXPECT_EQ(198, image_resource->GetContent()->GetImage()->width());
807 EXPECT_EQ(100, image_resource->GetContent()->GetImage()->height());
808
809 // A new client added here shouldn't notified of finish.
810 std::unique_ptr<MockImageResourceObserver> observer2 =
811 MockImageResourceObserver::Create(image_resource->GetContent());
812 EXPECT_EQ(1, observer2->ImageChangedCount());
813 EXPECT_FALSE(observer2->ImageNotifyFinishedCalled());
814
815 // After asynchronous tasks are executed, the loading of SVG document is
816 // completed and ImageNotifyFinished() is called.
817 testing::RunPendingTasks();
818 EXPECT_EQ(ResourceStatus::kCached,
819 image_resource->GetContent()->GetContentStatus());
820 EXPECT_EQ(2, observer->ImageChangedCount());
821 EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
822 EXPECT_EQ(2, observer2->ImageChangedCount());
823 EXPECT_TRUE(observer2->ImageNotifyFinishedCalled());
824 EXPECT_EQ(198, image_resource->GetContent()->GetImage()->width());
825 EXPECT_EQ(100, image_resource->GetContent()->GetImage()->height());
826
827 GetMemoryCache()->EvictResources();
828 }
829
776 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) { 830 TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
777 KURL url(kParsedURLString, "http://127.0.0.1:8000/foo"); 831 KURL url(kParsedURLString, "http://127.0.0.1:8000/foo");
778 ImageResource* image_resource = ImageResource::Create(ResourceRequest(url)); 832 ImageResource* image_resource = ImageResource::Create(ResourceRequest(url));
779 std::unique_ptr<MockImageResourceObserver> observer = 833 std::unique_ptr<MockImageResourceObserver> observer =
780 MockImageResourceObserver::Create(image_resource->GetContent()); 834 MockImageResourceObserver::Create(image_resource->GetContent());
781 835
782 ReceiveResponse(image_resource, url, "image/jpeg", 836 ReceiveResponse(image_resource, url, "image/jpeg",
783 reinterpret_cast<const char*>(kJpegImage), 837 reinterpret_cast<const char*>(kJpegImage),
784 sizeof(kJpegImage)); 838 sizeof(kJpegImage));
785 839
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 EXPECT_TRUE(observer->ImageNotifyFinishedCalled()); 1658 EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
1605 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage()); 1659 EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
1606 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width()); 1660 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width());
1607 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height()); 1661 EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height());
1608 1662
1609 WTF::SetTimeFunctionsForTesting(nullptr); 1663 WTF::SetTimeFunctionsForTesting(nullptr);
1610 } 1664 }
1611 1665
1612 } // namespace 1666 } // namespace
1613 } // namespace blink 1667 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698