[SavePage] Do not save images with errors

In this page,while saving the page if images with load error/decode error are saved,
while rendering the mhtml page the broken images are shown in place of those images.

BUG=346254
R=abarth@chromium.org

Review URL: https://codereview.chromium.org/177243005

git-svn-id: svn://svn.chromium.org/blink/trunk@169616 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d428227a
...@@ -314,7 +314,7 @@ void PageSerializer::addImageToResources(ImageResource* image, RenderObject* ima ...@@ -314,7 +314,7 @@ void PageSerializer::addImageToResources(ImageResource* image, RenderObject* ima
if (!shouldAddURL(url)) if (!shouldAddURL(url))
return; return;
if (!image || image->image() == Image::nullImage()) if (!image || image->image() == Image::nullImage() || image->errorOccurred())
return; return;
RefPtr<SharedBuffer> data = imageRenderer ? image->imageForRenderer(imageRenderer)->data() : 0; RefPtr<SharedBuffer> data = imageRenderer ? image->imageForRenderer(imageRenderer)->data() : 0;
......
...@@ -367,6 +367,30 @@ TEST_F(WebPageNewSerializeTest, SVGImageDontCrash) ...@@ -367,6 +367,30 @@ TEST_F(WebPageNewSerializeTest, SVGImageDontCrash)
EXPECT_GT(mhtml.length(), 50U); EXPECT_GT(mhtml.length(), 50U);
} }
TEST_F(WebPageNewSerializeTest, DontIncludeErrorImage)
{
WebURL pageUrl = toKURL("http://www.test.com");
WebURL imageUrl = toKURL("http://www.test.com/error_image.png");
registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_img_error.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
registerMockedURLLoad(imageUrl, WebString::fromUTF8("error_image.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
loadURLInTopFrame(pageUrl);
WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
ASSERT_FALSE(mhtmlData.isEmpty());
// Sniff the MHTML data to make sure image content is excluded.
LineReader lineReader(std::string(mhtmlData.data()));
std::string line;
while (lineReader.getNextLine(&line)) {
if (line.find("image/") != std::string::npos)
FAIL() << "Error Image was not excluded " << line;
}
}
TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash) TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash)
{ {
WebURL pageUrl = toKURL("http://www.test.com"); WebURL pageUrl = toKURL("http://www.test.com");
......
<html>
<head>
<title>
Save Page issue
</title>
</head>
<body style="background-image:url('error_image.png');">
<p>
Test for save page image error issue.
</p>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment