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

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, 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 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 7b1dc30199cfdc35d4c7c127b25bfdc122c7984f..ac3aa3b01b6905f15b526de33163f9dc9f352e9b 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");
}
+const 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* imageResource,
const KURL& url,
const AtomicString& mimeType,
@@ -708,6 +717,45 @@ TEST(ImageResourceTest, SVGImage) {
EXPECT_FALSE(imageResource->getContent()->getImage()->isBitmapImage());
}
+TEST(ImageResourceTest, SVGImageWithSubresource) {
+ KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
+ ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
+
+ receiveResponse(imageResource, url, "image/svg+xml", kSvgImageWithSubresource,
+ strlen(kSvgImageWithSubresource));
+
+ EXPECT_FALSE(imageResource->errorOccurred());
+ ASSERT_TRUE(imageResource->getContent()->hasImage());
+ EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
+ EXPECT_FALSE(imageResource->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(1, observer->imageChangedCount());
+ EXPECT_FALSE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(198, imageResource->getContent()->getImage()->width());
+ EXPECT_EQ(100, imageResource->getContent()->getImage()->height());
+
+ // A new client added here shouldn't notified of finish.
+ std::unique_ptr<MockImageResourceObserver> observer2 =
+ MockImageResourceObserver::create(imageResource->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(2, observer->imageChangedCount());
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(2, observer2->imageChangedCount());
+ EXPECT_TRUE(observer2->imageNotifyFinishedCalled());
+ EXPECT_EQ(198, imageResource->getContent()->getImage()->width());
+ EXPECT_EQ(100, imageResource->getContent()->getImage()->height());
+}
+
TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));

Powered by Google App Engine
This is Rietveld 408576698