| 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" | |
| 37 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
| 38 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
| 40 #include "core/html/HTMLDocument.h" | 39 #include "core/html/HTMLDocument.h" |
| 41 #include "core/html/HTMLIFrameElement.h" | 40 #include "core/html/HTMLIFrameElement.h" |
| 42 #include "core/html/HTMLInputElement.h" | 41 #include "core/html/HTMLInputElement.h" |
| 43 #include "core/html/HTMLTextAreaElement.h" | 42 #include "core/html/HTMLTextAreaElement.h" |
| 44 #include "core/loader/FrameLoadRequest.h" | 43 #include "core/loader/FrameLoadRequest.h" |
| 45 #include "core/page/Chrome.h" | 44 #include "core/page/Chrome.h" |
| 46 #include "core/page/Page.h" | 45 #include "core/page/Page.h" |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 { | 1671 { |
| 1673 int value = m_hasTouchEventHandlerCount[state]; | 1672 int value = m_hasTouchEventHandlerCount[state]; |
| 1674 m_hasTouchEventHandlerCount[state] = 0; | 1673 m_hasTouchEventHandlerCount[state] = 0; |
| 1675 return value; | 1674 return value; |
| 1676 } | 1675 } |
| 1677 | 1676 |
| 1678 private: | 1677 private: |
| 1679 int m_hasTouchEventHandlerCount[2]; | 1678 int m_hasTouchEventHandlerCount[2]; |
| 1680 }; | 1679 }; |
| 1681 | 1680 |
| 1682 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called | 1681 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco
rdingly for various |
| 1683 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| | 1682 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho
se calls are made |
| 1684 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made | 1683 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm
l. |
| 1685 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. | |
| 1686 TEST_F(WebViewTest, HasTouchEventHandlers) | 1684 TEST_F(WebViewTest, HasTouchEventHandlers) |
| 1687 { | 1685 { |
| 1688 TouchEventHandlerWebViewClient client; | 1686 TouchEventHandlerWebViewClient client; |
| 1689 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1687 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
| 1690 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); | 1688 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); |
| 1691 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1689 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1692 const WebCore::EventHandlerRegistry::EventHandlerClass touchEvent = WebCore:
:EventHandlerRegistry::TouchEvent; | |
| 1693 | 1690 |
| 1694 // The page is initialized with at least one no-handlers call. | 1691 // The page is initialized with at least one no-handlers call. |
| 1695 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first | 1692 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first |
| 1696 // initializes and empty frame, and then loads a document into it, so there
are two | 1693 // initializes and empty frame, and then loads a document into it, so there
are two |
| 1697 // FrameLoader::commitProvisionalLoad calls. | 1694 // FrameLoader::commitProvisionalLoad calls. |
| 1698 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1695 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
| 1699 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1696 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1700 | 1697 |
| 1701 // Adding the first document handler results in a has-handlers call. | 1698 // Adding the first document handler results in a has-handlers call. |
| 1702 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); | 1699 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); |
| 1703 WebCore::EventHandlerRegistry* registry = &document->frameHost()->eventHandl
erRegistry(); | 1700 document->didAddTouchEventHandler(document); |
| 1704 registry->didAddEventHandler(*document, touchEvent); | |
| 1705 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1701 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1706 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1702 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1707 | 1703 |
| 1708 // Adding another handler has no effect. | 1704 // Adding another handler has no effect. |
| 1709 registry->didAddEventHandler(*document, touchEvent); | 1705 document->didAddTouchEventHandler(document); |
| 1710 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1706 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1711 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1707 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1712 | 1708 |
| 1713 // Removing the duplicate handler has no effect. | 1709 // Removing the duplicate handler has no effect. |
| 1714 registry->didRemoveEventHandler(*document, touchEvent); | 1710 document->didRemoveTouchEventHandler(document); |
| 1715 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1711 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1716 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1712 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1717 | 1713 |
| 1718 // Removing the final handler results in a no-handlers call. | 1714 // Removing the final handler results in a no-handlers call. |
| 1719 registry->didRemoveEventHandler(*document, touchEvent); | 1715 document->didRemoveTouchEventHandler(document); |
| 1720 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1716 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1721 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1717 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1722 | 1718 |
| 1723 // Adding a handler on a div results in a has-handlers call. | 1719 // Adding a handler on a div results in a has-handlers call. |
| 1724 WebCore::Element* parentDiv = document->getElementById("parentdiv"); | 1720 WebCore::Element* parentDiv = document->getElementById("parentdiv"); |
| 1725 ASSERT(parentDiv); | 1721 ASSERT(parentDiv); |
| 1726 registry->didAddEventHandler(*parentDiv, touchEvent); | 1722 document->didAddTouchEventHandler(parentDiv); |
| 1727 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1723 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1728 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1724 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1729 | 1725 |
| 1730 // Adding a duplicate handler on the div, clearing all document handlers | 1726 // Adding a duplicate handler on the div, clearing all document handlers |
| 1731 // (of which there are none) and removing the extra handler on the div | 1727 // (of which there are none) and removing the extra handler on the div |
| 1732 // all have no effect. | 1728 // all have no effect. |
| 1733 registry->didAddEventHandler(*parentDiv, touchEvent); | 1729 document->didAddTouchEventHandler(parentDiv); |
| 1734 registry->didRemoveAllEventHandlers(*document); | 1730 document->didClearTouchEventHandlers(document); |
| 1735 registry->didRemoveEventHandler(*parentDiv, touchEvent); | 1731 document->didRemoveTouchEventHandler(parentDiv); |
| 1736 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1732 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1737 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1733 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1738 | 1734 |
| 1739 // Removing the final handler on the div results in a no-handlers call. | 1735 // Removing the final handler on the div results in a no-handlers call. |
| 1740 registry->didRemoveEventHandler(*parentDiv, touchEvent); | 1736 document->didRemoveTouchEventHandler(parentDiv); |
| 1741 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1737 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1742 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1738 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1743 | 1739 |
| 1744 // Adding two handlers then clearing them in a single call results in a | 1740 // Adding two handlers then clearing them in a single call results in a |
| 1745 // has-handlers then no-handlers call. | 1741 // has-handlers then no-handlers call. |
| 1746 registry->didAddEventHandler(*parentDiv, touchEvent); | 1742 document->didAddTouchEventHandler(parentDiv); |
| 1747 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1743 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1748 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1744 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1749 registry->didAddEventHandler(*parentDiv, touchEvent); | 1745 document->didAddTouchEventHandler(parentDiv); |
| 1750 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1746 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1751 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1747 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1752 registry->didRemoveAllEventHandlers(*parentDiv); | 1748 document->didClearTouchEventHandlers(parentDiv); |
| 1753 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1749 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1754 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1750 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1755 | 1751 |
| 1756 // Adding a handler inside of a child iframe results in a has-handlers call. | 1752 // Adding a handler inside of a child iframe results in a has-handlers call. |
| 1757 WebCore::Element* childFrame = document->getElementById("childframe"); | 1753 WebCore::Element* childFrame = document->getElementById("childframe"); |
| 1758 ASSERT(childFrame); | 1754 ASSERT(childFrame); |
| 1759 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); | 1755 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); |
| 1760 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); | 1756 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); |
| 1761 ASSERT(childDiv); | 1757 ASSERT(childDiv); |
| 1762 registry->didAddEventHandler(*childDiv, touchEvent); | 1758 childDocument->didAddTouchEventHandler(childDiv); |
| 1763 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1759 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1764 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1760 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1765 | 1761 |
| 1766 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc | 1762 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc |
| 1767 // has no impact. | 1763 // has no impact. |
| 1768 registry->didAddEventHandler(*document, touchEvent); | 1764 document->didAddTouchEventHandler(document); |
| 1769 registry->didAddEventHandler(*childFrame, touchEvent); | 1765 document->didAddTouchEventHandler(childFrame); |
| 1770 registry->didAddEventHandler(*childDocument, touchEvent); | 1766 childDocument->didAddTouchEventHandler(childDocument); |
| 1771 registry->didRemoveAllEventHandlers(*document); | 1767 document->didClearTouchEventHandlers(document); |
| 1772 registry->didRemoveAllEventHandlers(*childFrame); | 1768 document->didClearTouchEventHandlers(childFrame); |
| 1773 registry->didRemoveAllEventHandlers(*childDocument); | 1769 childDocument->didClearTouchEventHandlers(childDocument); |
| 1774 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1770 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1775 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1771 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1776 | 1772 |
| 1777 // Removing the final handler inside the child frame results in a no-handler
s call. | 1773 // Removing the final handler inside the child frame results in a no-handler
s call. |
| 1778 registry->didRemoveAllEventHandlers(*childDiv); | 1774 childDocument->didRemoveTouchEventHandler(childDiv); |
| 1779 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1775 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1780 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1776 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1781 | 1777 |
| 1782 // Adding a handler inside the child frame results in a has-handlers call. | 1778 // Adding a handler inside the child frame results in a has-handlers call. |
| 1783 registry->didAddEventHandler(*childDocument, touchEvent); | 1779 childDocument->didAddTouchEventHandler(childDocument); |
| 1784 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1780 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1785 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1781 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1786 | 1782 |
| 1787 // Adding a handler in the parent document and removing the one in the frame | 1783 // Adding a handler in the parent document and removing the one in the frame |
| 1788 // has no effect. | 1784 // has no effect. |
| 1789 registry->didAddEventHandler(*childFrame, touchEvent); | 1785 document->didAddTouchEventHandler(childFrame); |
| 1790 registry->didRemoveEventHandler(*childDocument, touchEvent); | 1786 childDocument->didRemoveTouchEventHandler(childDocument); |
| 1791 registry->didRemoveAllEventHandlers(*childDocument); | 1787 childDocument->didClearTouchEventHandlers(childDocument); |
| 1792 registry->didRemoveAllEventHandlers(*document); | 1788 document->didClearTouchEventHandlers(document); |
| 1793 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1789 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1794 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1790 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1795 | 1791 |
| 1796 // Now removing the handler in the parent document results in a no-handlers
call. | 1792 // Now removing the handler in the parent document results in a no-handlers
call. |
| 1797 registry->didRemoveEventHandler(*childFrame, touchEvent); | 1793 document->didRemoveTouchEventHandler(childFrame); |
| 1798 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1794 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1799 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1795 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1800 | 1796 |
| 1801 // Free the webView before the TouchEventHandlerWebViewClient gets freed. | 1797 // Free the webView before the TouchEventHandlerWebViewClient gets freed. |
| 1802 m_webViewHelper.reset(); | 1798 m_webViewHelper.reset(); |
| 1803 } | 1799 } |
| 1804 | 1800 |
| 1805 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) | 1801 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) |
| 1806 { | 1802 { |
| 1807 WebCore::Element* element = document->getElementById("root"); | 1803 WebCore::Element* element = document->getElementById("root"); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 | 2076 |
| 2081 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2077 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2082 | 2078 |
| 2083 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2079 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
| 2084 | 2080 |
| 2085 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2081 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2086 webView->setAutofillClient(0); | 2082 webView->setAutofillClient(0); |
| 2087 } | 2083 } |
| 2088 | 2084 |
| 2089 } // namespace | 2085 } // namespace |
| OLD | NEW |