TEST_F(ExternalPopupMenuTest, PopupAccountsForVisualViewportOffset) { registerMockedURLLoad("select_mid_screen.html"); loadFrame("select_mid_screen.html"); webView()->resize(WebSize(100, 100)); webView()->updateAllLifecyclePhases(); HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select")); LayoutMenuList* menuList = toLayoutMenuList(select->layoutObject()); ASSERT_TRUE(menuList); VisualViewport& visualViewport = webView()->page()->frameHost().visualViewport(); IntRect rectInDocument = menuList->absoluteBoundingBoxRect(); webView()->setPageScaleFactor(2); IntPoint scrollDelta(20, 30); visualViewport.move(scrollDelta); select->showPopup(); EXPECT_EQ(rectInDocument.x() - scrollDelta.x(), client().shownBounds().x); EXPECT_EQ(rectInDocument.y() - scrollDelta.y(), client().shownBounds().y); }
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(ExternalPopupMenuTest, DidAcceptIndicesClearSelect) { registerMockedURLLoad("select.html"); loadFrame("select.html"); HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select")); LayoutMenuList* menuList = toLayoutMenuList(select->layoutObject()); ASSERT_TRUE(menuList); select->showPopup(); ASSERT_TRUE(select->popupIsVisible()); WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(select->popup()); WebVector<int> indices; client->didAcceptIndices(indices); EXPECT_FALSE(select->popupIsVisible()); EXPECT_EQ(-1, select->selectedIndex()); }
TEST_F(ExternalPopupMenuTest, DidAcceptIndex) { registerMockedURLLoad("select.html"); loadFrame("select.html"); HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select")); LayoutMenuList* menuList = toLayoutMenuList(select->layoutObject()); ASSERT_TRUE(menuList); select->showPopup(); ASSERT_TRUE(select->popupIsVisible()); WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(select->popup()); client->didAcceptIndex(2); EXPECT_FALSE(select->popupIsVisible()); ASSERT_STREQ("2", menuList->text().utf8().data()); EXPECT_EQ(2, select->selectedIndex()); }
// 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()); }
void registerURL(const char* url, const char* file, const char* mimeType) { registerMockedURLLoad(KURL(m_baseUrl, url), WebString::fromUTF8(file), m_folder, WebString::fromUTF8(mimeType)); }
void registerMockedURLLoad(const WebURL& fullURL, const WebString& fileName, const WebString& mimeType) { registerMockedURLLoad(fullURL, fileName, WebString::fromUTF8(""), mimeType); }
void registerMockedURLFromBaseURL(const WebString& baseURL, const WebString& fileName, const WebString& mimeType) { // fullURL = baseURL + fileName. std::string fullString = std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); registerMockedURLLoad(toKURL(fullString.c_str()), fileName, WebString::fromUTF8(""), mimeType); }