String serializeFile(const String& url, const String& fileName) { KURL parsedURL(ParsedURLString, url); URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, "pageserialization/", "text/html"); FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); WebVector<WebURL> links(&parsedURL, 1); WebVector<WebString> localPaths(&"local", 1); SimpleWebPageSerializerClient serializerClient; WebPageSerializer::serialize(mainFrameImpl(), &serializerClient, links, localPaths, ""); return serializerClient.toString(); }
TEST_F(WebPageSerializerTest, fromUrlWithMinusMinus) { WebURL topFrameURL = toKURL("http://www.test.com?--x--"); registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("text_only_page.html")); loadURLInTopFrame(topFrameURL); SimpleWebPageSerializerClient serializerClient; WebVector<WebURL> links(&topFrameURL, 1); WebVector<WebString> localPaths(&"local", 1); WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &serializerClient, links, localPaths, ""); EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", serializerClient.toString().substr(1, 60)); }
TEST_F(WebPageSerializerTest, EncodingAndNormalization) { WebURL topFrameURL = toKURL("http://www.test.com"); registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("encoding_normalization.html")); loadURLInTopFrame(topFrameURL); SimpleWebPageSerializerClient serializerClient; WebVector<WebURL> links(&topFrameURL, 1); WebVector<WebString> localPaths(&"local", 1); WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &serializerClient, links, localPaths, ""); const char* expectedHTML = "<!DOCTYPE html>\n" "<!-- saved from url=(0020)http://www.test.com/ -->\n" "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-KR\"><meta charset=\"euc-kr\">\n" "<title>Ensure NFC normalization is not performed by page serializer</title>\n" "</head><body>\n" "\xe4\xc5\xd1\xe2\n" "\n</body></html>"; EXPECT_EQ(expectedHTML, serializerClient.toString()); }
TEST_F(WebPageSerializerTest, URLAttributeValues) { WebURL topFrameURL = toKURL("http://www.test.com"); registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("url_attribute_values.html")); registerMockedImageURL("javascript:\""); loadURLInTopFrame(topFrameURL); SimpleWebPageSerializerClient serializerClient; WebVector<WebURL> links(&topFrameURL, 1); WebVector<WebString> localPaths(&"local", 1); WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &serializerClient, links, localPaths, ""); const char* expectedHTML = "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta charset=\"utf8\">\n" "</head><body><img src=\"javascript:"\">\n" "<a href=\"http://www.test.com/local#"\">local</a>\n" "<a href=\"http://www.example.com/#"><script>alert(0)</script>\">external</a>\n" "</body></html>"; EXPECT_EQ(expectedHTML, serializerClient.toString()); }