+class ExternalPopupMenuWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
+public:
+ virtual WebExternalPopupMenu* createExternalPopupMenu(const WebPopupMenuInfo&, WebExternalPopupMenuClient*) override
+ {
+ return &m_mockWebExternalPopupMenu;
+ }
+ WebRect shownBounds() const
+ {
+ return m_mockWebExternalPopupMenu.shownBounds();
+ }
+private:
+ class MockWebExternalPopupMenu : public WebExternalPopupMenu {
+ virtual void show(const WebRect& bounds) override
+ {
+ m_shownBounds = bounds;
+ }
+ virtual void close() override { }
+
+ public:
+ WebRect shownBounds() const
+ {
+ return m_shownBounds;
+ }
+
+ private:
+ WebRect m_shownBounds;
+ };
+ WebRect m_shownBounds;
+ MockWebExternalPopupMenu m_mockWebExternalPopupMenu;
+};
+
+class ExternalPopupMenuTest : public testing::Test {
+public:
+ ExternalPopupMenuTest() : m_baseURL("http://www.test.com") { }
+
+protected:
+ virtual void SetUp() override
+ {
+ m_helper.initialize(false, &m_webFrameClient, &m_webViewClient, &configureSettings);
+ webView()->setUseExternalPopupMenus(true);
+ }
+ virtual void TearDown() override
+ {
+ Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
+ }
+
+ void registerMockedURLLoad(const std::string& fileName)
+ {
+ URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(m_baseURL + fileName), WebString::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromUTF8("text/html"));
+ }
+
+ void loadFrame(const std::string& fileName)
+ {
+ FrameTestHelpers::loadFrame(mainFrame(), m_baseURL + fileName);
+ }
+
+ WebViewImpl* webView() const { return m_helper.webViewImpl(); }
+ const ExternalPopupMenuWebFrameClient& client() const { return m_webFrameClient; }
+ WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFrameImpl(); }
+
+private:
+ static void configureSettings(WebSettings* settings)
+ {
+ settings->setPinchVirtualViewportEnabled(true);
+ }
+
+ std::string m_baseURL;
+ FrameTestHelpers::TestWebViewClient m_webViewClient;
+ ExternalPopupMenuWebFrameClient m_webFrameClient;
+ FrameTestHelpers::WebViewHelper m_helper;
+};
+
+TEST_F(ExternalPopupMenuTest, PopupAccountsForPinchViewportOffset)
+{
+ registerMockedURLLoad("select_mid_screen.html");
+ loadFrame("select_mid_screen.html");
+
+ webView()->resize(WebSize(100, 100));
+ webView()->layout();
+
+ HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select"));
+ RenderMenuList* menuList = toRenderMenuList(select->renderer());
+ ASSERT_TRUE(menuList);
+
+ PinchViewport& pinchViewport = webView()->page()->frameHost().pinchViewport();
+
+ IntRect rectInDocument = menuList->absoluteBoundingBoxRect();
+
+ webView()->setPageScaleFactor(2);
+ IntPoint scrollDelta(20, 30);
+ pinchViewport.move(scrollDelta);
+
+ menuList->showPopup();
+
+ EXPECT_EQ(rectInDocument.x() - scrollDelta.x(), client().shownBounds().x);
+ EXPECT_EQ(rectInDocument.y() - scrollDelta.y(), client().shownBounds().y);
+}
+
+TEST_F(ExternalPopupMenuTest, DidAcceptIndex)
+{
+ registerMockedURLLoad("select.html");
+ loadFrame("select.html");
+
+ HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select"));
+ RenderMenuList* menuList = toRenderMenuList(select->renderer());
+ ASSERT_TRUE(menuList);
+
+ menuList->showPopup();
+ ASSERT_TRUE(menuList->popupIsVisible());
+
+ WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuList->popup());
+ client->didAcceptIndex(2);
+ EXPECT_FALSE(menuList->popupIsVisible());
+ ASSERT_STREQ("2", menuList->text().utf8().data());
+ EXPECT_EQ(2, select->selectedIndex());
+}
+
+TEST_F(ExternalPopupMenuTest, DidAcceptIndices)
+{
+ registerMockedURLLoad("select.html");
+ loadFrame("select.html");
+
+ HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select"));
+ RenderMenuList* menuList = toRenderMenuList(select->renderer());
+ ASSERT_TRUE(menuList);
+
+ menuList->showPopup();
+ ASSERT_TRUE(menuList->popupIsVisible());
+
+ WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuList->popup());
+ int indices[] = { 2 };
+ WebVector<int> indicesVector(indices, 1);
+ client->didAcceptIndices(indicesVector);
+ EXPECT_FALSE(menuList->popupIsVisible());
+ EXPECT_STREQ("2", menuList->text().utf8().data());
+ EXPECT_EQ(2, select->selectedIndex());
+}
+
+TEST_F(ExternalPopupMenuTest, DidAcceptIndicesClearSelect)
+{
+ registerMockedURLLoad("select.html");
+ loadFrame("select.html");
+
+ HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->document()->getElementById("select"));
+ RenderMenuList* menuList = toRenderMenuList(select->renderer());
+ ASSERT_TRUE(menuList);
+
+ menuList->showPopup();
+ ASSERT_TRUE(menuList->popupIsVisible());
+
+ WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuList->popup());
+ WebVector<int> indices;
+ client->didAcceptIndices(indices);
+ EXPECT_FALSE(menuList->popupIsVisible());
+ EXPECT_EQ(-1, select->selectedIndex());
+}
+