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)); }
// Checks that the domain is set to the actual MHTML file, not the URL it was // generated from. TEST_F(MHTMLTest, CheckDomain) { const char kFileURL[] = "file:///simple_test.mht"; // Register the mocked frame and load it. WebURL url = toKURL(kFileURL); registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht")); loadURLInTopFrame(url); ASSERT_TRUE(page()); LocalFrame* frame = toLocalFrame(page()->mainFrame()); ASSERT_TRUE(frame); Document* document = frame->document(); ASSERT_TRUE(document); EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); SecurityOrigin* origin = document->securityOrigin(); EXPECT_STRNE("localhost", origin->domain().ascii().data()); }
TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL) { // Load a page with some data urls. WebURL topFrameURL = toKURL(m_baseURL); registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_morphing_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); loadURLInTopFrame(topFrameURL); WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView()); ASSERT_FALSE(mhtmlData.isEmpty()); // Read the MHTML data line and check that the string data:image is found // exactly two times. size_t nbDataURLs = 0; LineReader lineReader(std::string(mhtmlData.data())); std::string line; while (lineReader.getNextLine(&line)) { if (line.find("data:text") != std::string::npos) nbDataURLs++; } EXPECT_EQ(2u, nbDataURLs); }
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()); }