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

Unified 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: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
index 065b2d2ddcf80928dfa8c7e92efa8c124da9b00e..824365b7e217d2a1ee4ef69b2a2d286c96fa1129 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -161,6 +161,15 @@ String GetTestFilePath() {
return testing::WebTestDataPath("cancelTest.html");
}
+constexpr char kSvgImageWithSubresource[] =
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"198\" height=\"100\">"
+ "<style>"
+ " <![CDATA[@font-face{font-family:\"test\"; "
+ " src:url('data:font/ttf;base64,invalidFontData');}]]>"
+ "</style>"
+ "<text x=\"50\" y=\"50\" font-family=\"test\" font-size=\"16\">Fox</text>"
+ "</svg>";
+
void ReceiveResponse(ImageResource* image_resource,
const KURL& url,
const AtomicString& mime_type,
@@ -773,6 +782,51 @@ TEST(ImageResourceTest, SVGImage) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
}
+TEST(ImageResourceTest, SVGImageWithSubresource) {
+ KURL url(kParsedURLString, "http://127.0.0.1:8000/foo");
+ ImageResource* image_resource = ImageResource::Create(ResourceRequest(url));
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::Create(image_resource->GetContent());
+
+ ReceiveResponse(image_resource, url, "image/svg+xml",
+ kSvgImageWithSubresource, strlen(kSvgImageWithSubresource));
+
+ EXPECT_FALSE(image_resource->ErrorOccurred());
+ ASSERT_TRUE(image_resource->GetContent()->HasImage());
+ EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
+ EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
+
+ // At this point, image is (mostly) available but the loading is not yet
+ // finished because of SVG's subresources, and thus ImageChanged() or
+ // ImageNotifyFinished() are not called.
+ EXPECT_EQ(ResourceStatus::kPending,
+ image_resource->GetContent()->GetContentStatus());
+ EXPECT_EQ(1, observer->ImageChangedCount());
+ EXPECT_FALSE(observer->ImageNotifyFinishedCalled());
+ EXPECT_EQ(198, image_resource->GetContent()->GetImage()->width());
+ EXPECT_EQ(100, image_resource->GetContent()->GetImage()->height());
+
+ // A new client added here shouldn't notified of finish.
+ std::unique_ptr<MockImageResourceObserver> observer2 =
+ MockImageResourceObserver::Create(image_resource->GetContent());
+ EXPECT_EQ(1, observer2->ImageChangedCount());
+ EXPECT_FALSE(observer2->ImageNotifyFinishedCalled());
+
+ // After asynchronous tasks are executed, the loading of SVG document is
+ // completed and ImageNotifyFinished() is called.
+ testing::RunPendingTasks();
+ EXPECT_EQ(ResourceStatus::kCached,
+ image_resource->GetContent()->GetContentStatus());
+ EXPECT_EQ(2, observer->ImageChangedCount());
+ EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
+ EXPECT_EQ(2, observer2->ImageChangedCount());
+ EXPECT_TRUE(observer2->ImageNotifyFinishedCalled());
+ EXPECT_EQ(198, image_resource->GetContent()->GetImage()->width());
+ EXPECT_EQ(100, image_resource->GetContent()->GetImage()->height());
+
+ GetMemoryCache()->EvictResources();
+}
+
TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
KURL url(kParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* image_resource = ImageResource::Create(ResourceRequest(url));

Powered by Google App Engine
This is Rietveld 408576698