| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "public/web/WebView.h" | 32 #include "public/web/WebView.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
| 36 #include "core/frame/EventHandlerRegistry.h" |
| 36 #include "core/frame/FrameView.h" | 37 #include "core/frame/FrameView.h" |
| 37 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 38 #include "core/frame/Settings.h" | 39 #include "core/frame/Settings.h" |
| 39 #include "core/html/HTMLDocument.h" | 40 #include "core/html/HTMLDocument.h" |
| 40 #include "core/html/HTMLIFrameElement.h" | 41 #include "core/html/HTMLIFrameElement.h" |
| 41 #include "core/html/HTMLInputElement.h" | 42 #include "core/html/HTMLInputElement.h" |
| 42 #include "core/html/HTMLTextAreaElement.h" | 43 #include "core/html/HTMLTextAreaElement.h" |
| 43 #include "core/loader/FrameLoadRequest.h" | 44 #include "core/loader/FrameLoadRequest.h" |
| 44 #include "core/page/Chrome.h" | 45 #include "core/page/Chrome.h" |
| 45 #include "core/page/Page.h" | 46 #include "core/page/Page.h" |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1625 { | 1626 { |
| 1626 int value = m_hasTouchEventHandlerCount[state]; | 1627 int value = m_hasTouchEventHandlerCount[state]; |
| 1627 m_hasTouchEventHandlerCount[state] = 0; | 1628 m_hasTouchEventHandlerCount[state] = 0; |
| 1628 return value; | 1629 return value; |
| 1629 } | 1630 } |
| 1630 | 1631 |
| 1631 private: | 1632 private: |
| 1632 int m_hasTouchEventHandlerCount[2]; | 1633 int m_hasTouchEventHandlerCount[2]; |
| 1633 }; | 1634 }; |
| 1634 | 1635 |
| 1635 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco
rdingly for various | 1636 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called |
| 1636 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho
se calls are made | 1637 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| |
| 1637 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm
l. | 1638 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made |
| 1639 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. |
| 1638 TEST_F(WebViewTest, HasTouchEventHandlers) | 1640 TEST_F(WebViewTest, HasTouchEventHandlers) |
| 1639 { | 1641 { |
| 1640 TouchEventHandlerWebViewClient client; | 1642 TouchEventHandlerWebViewClient client; |
| 1641 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1643 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
| 1642 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); | 1644 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); |
| 1643 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1645 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1646 const WebCore::EventHandlerRegistry::EventHandlerClass touchEvent = WebCore:
:EventHandlerRegistry::TouchEvent; |
| 1644 | 1647 |
| 1645 // The page is initialized with at least one no-handlers call. | 1648 // The page is initialized with at least one no-handlers call. |
| 1646 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first | 1649 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first |
| 1647 // initializes and empty frame, and then loads a document into it, so there
are two | 1650 // initializes and empty frame, and then loads a document into it, so there
are two |
| 1648 // FrameLoader::commitProvisionalLoad calls. | 1651 // FrameLoader::commitProvisionalLoad calls. |
| 1649 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1652 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
| 1650 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1653 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1651 | 1654 |
| 1652 // Adding the first document handler results in a has-handlers call. | 1655 // Adding the first document handler results in a has-handlers call. |
| 1653 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); | 1656 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); |
| 1654 document->didAddTouchEventHandler(document); | 1657 WebCore::EventHandlerRegistry* registry = &document->frameHost()->eventHandl
erRegistry(); |
| 1658 registry->didAddEventHandler(*document, touchEvent); |
| 1655 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1659 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1656 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1660 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1657 | 1661 |
| 1658 // Adding another handler has no effect. | 1662 // Adding another handler has no effect. |
| 1659 document->didAddTouchEventHandler(document); | 1663 registry->didAddEventHandler(*document, touchEvent); |
| 1660 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1664 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1661 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1665 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1662 | 1666 |
| 1663 // Removing the duplicate handler has no effect. | 1667 // Removing the duplicate handler has no effect. |
| 1664 document->didRemoveTouchEventHandler(document); | 1668 registry->didRemoveEventHandler(*document, touchEvent); |
| 1665 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1669 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1666 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1670 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1667 | 1671 |
| 1668 // Removing the final handler results in a no-handlers call. | 1672 // Removing the final handler results in a no-handlers call. |
| 1669 document->didRemoveTouchEventHandler(document); | 1673 registry->didRemoveEventHandler(*document, touchEvent); |
| 1670 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1674 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1671 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1675 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1672 | 1676 |
| 1673 // Adding a handler on a div results in a has-handlers call. | 1677 // Adding a handler on a div results in a has-handlers call. |
| 1674 WebCore::Element* parentDiv = document->getElementById("parentdiv"); | 1678 WebCore::Element* parentDiv = document->getElementById("parentdiv"); |
| 1675 ASSERT(parentDiv); | 1679 ASSERT(parentDiv); |
| 1676 document->didAddTouchEventHandler(parentDiv); | 1680 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1677 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1681 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1678 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1682 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1679 | 1683 |
| 1680 // Adding a duplicate handler on the div, clearing all document handlers | 1684 // Adding a duplicate handler on the div, clearing all document handlers |
| 1681 // (of which there are none) and removing the extra handler on the div | 1685 // (of which there are none) and removing the extra handler on the div |
| 1682 // all have no effect. | 1686 // all have no effect. |
| 1683 document->didAddTouchEventHandler(parentDiv); | 1687 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1684 document->didClearTouchEventHandlers(document); | 1688 registry->didRemoveAllEventHandlers(*document); |
| 1685 document->didRemoveTouchEventHandler(parentDiv); | 1689 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
| 1686 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1690 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1687 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1691 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1688 | 1692 |
| 1689 // Removing the final handler on the div results in a no-handlers call. | 1693 // Removing the final handler on the div results in a no-handlers call. |
| 1690 document->didRemoveTouchEventHandler(parentDiv); | 1694 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
| 1691 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1695 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1692 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1696 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1693 | 1697 |
| 1694 // Adding two handlers then clearing them in a single call results in a | 1698 // Adding two handlers then clearing them in a single call results in a |
| 1695 // has-handlers then no-handlers call. | 1699 // has-handlers then no-handlers call. |
| 1696 document->didAddTouchEventHandler(parentDiv); | 1700 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1697 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1701 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1698 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1702 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1699 document->didAddTouchEventHandler(parentDiv); | 1703 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1700 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1704 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1701 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1705 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1702 document->didClearTouchEventHandlers(parentDiv); | 1706 registry->didRemoveAllEventHandlers(*parentDiv); |
| 1703 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1707 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1704 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1708 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1705 | 1709 |
| 1706 // Adding a handler inside of a child iframe results in a has-handlers call. | 1710 // Adding a handler inside of a child iframe results in a has-handlers call. |
| 1707 WebCore::Element* childFrame = document->getElementById("childframe"); | 1711 WebCore::Element* childFrame = document->getElementById("childframe"); |
| 1708 ASSERT(childFrame); | 1712 ASSERT(childFrame); |
| 1709 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); | 1713 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); |
| 1710 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); | 1714 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); |
| 1711 ASSERT(childDiv); | 1715 ASSERT(childDiv); |
| 1712 childDocument->didAddTouchEventHandler(childDiv); | 1716 registry->didAddEventHandler(*childDiv, touchEvent); |
| 1713 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1717 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1714 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1718 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1715 | 1719 |
| 1716 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc | 1720 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc |
| 1717 // has no impact. | 1721 // has no impact. |
| 1718 document->didAddTouchEventHandler(document); | 1722 registry->didAddEventHandler(*document, touchEvent); |
| 1719 document->didAddTouchEventHandler(childFrame); | 1723 registry->didAddEventHandler(*childFrame, touchEvent); |
| 1720 childDocument->didAddTouchEventHandler(childDocument); | 1724 registry->didAddEventHandler(*childDocument, touchEvent); |
| 1721 document->didClearTouchEventHandlers(document); | 1725 registry->didRemoveAllEventHandlers(*document); |
| 1722 document->didClearTouchEventHandlers(childFrame); | 1726 registry->didRemoveAllEventHandlers(*childFrame); |
| 1723 childDocument->didClearTouchEventHandlers(childDocument); | 1727 registry->didRemoveAllEventHandlers(*childDocument); |
| 1724 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1728 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1725 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1729 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1726 | 1730 |
| 1727 // Removing the final handler inside the child frame results in a no-handler
s call. | 1731 // Removing the final handler inside the child frame results in a no-handler
s call. |
| 1728 childDocument->didRemoveTouchEventHandler(childDiv); | 1732 registry->didRemoveAllEventHandlers(*childDiv); |
| 1729 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1733 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1730 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1734 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1731 | 1735 |
| 1732 // Adding a handler inside the child frame results in a has-handlers call. | 1736 // Adding a handler inside the child frame results in a has-handlers call. |
| 1733 childDocument->didAddTouchEventHandler(childDocument); | 1737 registry->didAddEventHandler(*childDocument, touchEvent); |
| 1734 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1738 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1735 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1739 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1736 | 1740 |
| 1737 // Adding a handler in the parent document and removing the one in the frame | 1741 // Adding a handler in the parent document and removing the one in the frame |
| 1738 // has no effect. | 1742 // has no effect. |
| 1739 document->didAddTouchEventHandler(childFrame); | 1743 registry->didAddEventHandler(*childFrame, touchEvent); |
| 1740 childDocument->didRemoveTouchEventHandler(childDocument); | 1744 registry->didRemoveEventHandler(*childDocument, touchEvent); |
| 1741 childDocument->didClearTouchEventHandlers(childDocument); | 1745 registry->didRemoveAllEventHandlers(*childDocument); |
| 1742 document->didClearTouchEventHandlers(document); | 1746 registry->didRemoveAllEventHandlers(*document); |
| 1743 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1747 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1744 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1748 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1745 | 1749 |
| 1746 // Now removing the handler in the parent document results in a no-handlers
call. | 1750 // Now removing the handler in the parent document results in a no-handlers
call. |
| 1747 document->didRemoveTouchEventHandler(childFrame); | 1751 registry->didRemoveEventHandler(*childFrame, touchEvent); |
| 1748 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1752 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1749 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1753 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1750 | 1754 |
| 1751 // Free the webView before the TouchEventHandlerWebViewClient gets freed. | 1755 // Free the webView before the TouchEventHandlerWebViewClient gets freed. |
| 1752 m_webViewHelper.reset(); | 1756 m_webViewHelper.reset(); |
| 1753 } | 1757 } |
| 1754 | 1758 |
| 1755 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) | 1759 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) |
| 1756 { | 1760 { |
| 1757 WebCore::Element* element = document->getElementById("root"); | 1761 WebCore::Element* element = document->getElementById("root"); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 | 2034 |
| 2031 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2035 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2032 | 2036 |
| 2033 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2037 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
| 2034 | 2038 |
| 2035 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2039 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2036 webView->setAutofillClient(0); | 2040 webView->setAutofillClient(0); |
| 2037 } | 2041 } |
| 2038 | 2042 |
| 2039 } // namespace | 2043 } // namespace |
| OLD | NEW |