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/rendering/RenderLayer.h" | 46 #include "core/rendering/RenderLayer.h" |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 { | 1592 { |
1592 int value = m_hasTouchEventHandlerCount[state]; | 1593 int value = m_hasTouchEventHandlerCount[state]; |
1593 m_hasTouchEventHandlerCount[state] = 0; | 1594 m_hasTouchEventHandlerCount[state] = 0; |
1594 return value; | 1595 return value; |
1595 } | 1596 } |
1596 | 1597 |
1597 private: | 1598 private: |
1598 int m_hasTouchEventHandlerCount[2]; | 1599 int m_hasTouchEventHandlerCount[2]; |
1599 }; | 1600 }; |
1600 | 1601 |
1601 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco
rdingly for various | 1602 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called |
1602 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho
se calls are made | 1603 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| |
1603 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm
l. | 1604 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made |
| 1605 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. |
1604 TEST_F(WebViewTest, HasTouchEventHandlers) | 1606 TEST_F(WebViewTest, HasTouchEventHandlers) |
1605 { | 1607 { |
1606 TouchEventHandlerWebViewClient client; | 1608 TouchEventHandlerWebViewClient client; |
1607 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1609 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
1608 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); | 1610 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); |
1609 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1611 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1612 const WebCore::EventHandlerRegistry::EventHandlerClass touchEvent = WebCore:
:EventHandlerRegistry::TouchEvent; |
1610 | 1613 |
1611 // The page is initialized with at least one no-handlers call. | 1614 // The page is initialized with at least one no-handlers call. |
1612 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first | 1615 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first |
1613 // initializes and empty frame, and then loads a document into it, so there
are two | 1616 // initializes and empty frame, and then loads a document into it, so there
are two |
1614 // FrameLoader::commitProvisionalLoad calls. | 1617 // FrameLoader::commitProvisionalLoad calls. |
1615 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1618 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
1616 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1619 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1617 | 1620 |
1618 // Adding the first document handler results in a has-handlers call. | 1621 // Adding the first document handler results in a has-handlers call. |
1619 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); | 1622 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); |
1620 document->didAddTouchEventHandler(document); | 1623 WebCore::EventHandlerRegistry* registry = &document->frameHost()->eventHandl
erRegistry(); |
| 1624 registry->didAddEventHandler(*document, touchEvent); |
1621 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1625 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1622 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1626 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1623 | 1627 |
1624 // Adding another handler has no effect. | 1628 // Adding another handler has no effect. |
1625 document->didAddTouchEventHandler(document); | 1629 registry->didAddEventHandler(*document, touchEvent); |
1626 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1630 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1627 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1631 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1628 | 1632 |
1629 // Removing the duplicate handler has no effect. | 1633 // Removing the duplicate handler has no effect. |
1630 document->didRemoveTouchEventHandler(document); | 1634 registry->didRemoveEventHandler(*document, touchEvent); |
1631 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1635 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1632 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1636 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1633 | 1637 |
1634 // Removing the final handler results in a no-handlers call. | 1638 // Removing the final handler results in a no-handlers call. |
1635 document->didRemoveTouchEventHandler(document); | 1639 registry->didRemoveEventHandler(*document, touchEvent); |
1636 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1640 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1637 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1641 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1638 | 1642 |
1639 // Adding a handler on a div results in a has-handlers call. | 1643 // Adding a handler on a div results in a has-handlers call. |
1640 WebCore::Element* parentDiv = document->getElementById("parentdiv"); | 1644 WebCore::Element* parentDiv = document->getElementById("parentdiv"); |
1641 ASSERT(parentDiv); | 1645 ASSERT(parentDiv); |
1642 document->didAddTouchEventHandler(parentDiv); | 1646 registry->didAddEventHandler(*parentDiv, touchEvent); |
1643 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1647 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1644 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1648 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1645 | 1649 |
1646 // Adding a duplicate handler on the div, clearing all document handlers | 1650 // Adding a duplicate handler on the div, clearing all document handlers |
1647 // (of which there are none) and removing the extra handler on the div | 1651 // (of which there are none) and removing the extra handler on the div |
1648 // all have no effect. | 1652 // all have no effect. |
1649 document->didAddTouchEventHandler(parentDiv); | 1653 registry->didAddEventHandler(*parentDiv, touchEvent); |
1650 document->didClearTouchEventHandlers(document); | 1654 registry->didRemoveAllEventHandlers(*document); |
1651 document->didRemoveTouchEventHandler(parentDiv); | 1655 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
1652 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1656 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1653 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1657 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1654 | 1658 |
1655 // Removing the final handler on the div results in a no-handlers call. | 1659 // Removing the final handler on the div results in a no-handlers call. |
1656 document->didRemoveTouchEventHandler(parentDiv); | 1660 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
1657 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1661 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1658 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1662 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1659 | 1663 |
1660 // Adding two handlers then clearing them in a single call results in a | 1664 // Adding two handlers then clearing them in a single call results in a |
1661 // has-handlers then no-handlers call. | 1665 // has-handlers then no-handlers call. |
1662 document->didAddTouchEventHandler(parentDiv); | 1666 registry->didAddEventHandler(*parentDiv, touchEvent); |
1663 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1667 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1664 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1668 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1665 document->didAddTouchEventHandler(parentDiv); | 1669 registry->didAddEventHandler(*parentDiv, touchEvent); |
1666 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1670 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1667 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1671 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1668 document->didClearTouchEventHandlers(parentDiv); | 1672 registry->didRemoveAllEventHandlers(*parentDiv); |
1669 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1673 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1670 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1674 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1671 | 1675 |
1672 // Adding a handler inside of a child iframe results in a has-handlers call. | 1676 // Adding a handler inside of a child iframe results in a has-handlers call. |
1673 WebCore::Element* childFrame = document->getElementById("childframe"); | 1677 WebCore::Element* childFrame = document->getElementById("childframe"); |
1674 ASSERT(childFrame); | 1678 ASSERT(childFrame); |
1675 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); | 1679 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD
ocument(); |
1676 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); | 1680 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); |
1677 ASSERT(childDiv); | 1681 ASSERT(childDiv); |
1678 childDocument->didAddTouchEventHandler(childDiv); | 1682 registry->didAddEventHandler(*childDiv, touchEvent); |
1679 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1683 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1680 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1684 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1681 | 1685 |
1682 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc | 1686 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc |
1683 // has no impact. | 1687 // has no impact. |
1684 document->didAddTouchEventHandler(document); | 1688 registry->didAddEventHandler(*document, touchEvent); |
1685 document->didAddTouchEventHandler(childFrame); | 1689 registry->didAddEventHandler(*childFrame, touchEvent); |
1686 childDocument->didAddTouchEventHandler(childDocument); | 1690 registry->didAddEventHandler(*childDocument, touchEvent); |
1687 document->didClearTouchEventHandlers(document); | 1691 registry->didRemoveAllEventHandlers(*document); |
1688 document->didClearTouchEventHandlers(childFrame); | 1692 registry->didRemoveAllEventHandlers(*childFrame); |
1689 childDocument->didClearTouchEventHandlers(childDocument); | 1693 registry->didRemoveAllEventHandlers(*childDocument); |
1690 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1694 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1691 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1695 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1692 | 1696 |
1693 // Removing the final handler inside the child frame results in a no-handler
s call. | 1697 // Removing the final handler inside the child frame results in a no-handler
s call. |
1694 childDocument->didRemoveTouchEventHandler(childDiv); | 1698 registry->didRemoveAllEventHandlers(*childDiv); |
1695 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1699 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1696 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1700 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1697 | 1701 |
1698 // Adding a handler inside the child frame results in a has-handlers call. | 1702 // Adding a handler inside the child frame results in a has-handlers call. |
1699 childDocument->didAddTouchEventHandler(childDocument); | 1703 registry->didAddEventHandler(*childDocument, touchEvent); |
1700 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1704 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1701 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1705 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1702 | 1706 |
1703 // Adding a handler in the parent document and removing the one in the frame | 1707 // Adding a handler in the parent document and removing the one in the frame |
1704 // has no effect. | 1708 // has no effect. |
1705 document->didAddTouchEventHandler(childFrame); | 1709 registry->didAddEventHandler(*childFrame, touchEvent); |
1706 childDocument->didRemoveTouchEventHandler(childDocument); | 1710 registry->didRemoveEventHandler(*childDocument, touchEvent); |
1707 childDocument->didClearTouchEventHandlers(childDocument); | 1711 registry->didRemoveAllEventHandlers(*childDocument); |
1708 document->didClearTouchEventHandlers(document); | 1712 registry->didRemoveAllEventHandlers(*document); |
1709 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1713 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1710 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1714 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1711 | 1715 |
1712 // Now removing the handler in the parent document results in a no-handlers
call. | 1716 // Now removing the handler in the parent document results in a no-handlers
call. |
1713 document->didRemoveTouchEventHandler(childFrame); | 1717 registry->didRemoveEventHandler(*childFrame, touchEvent); |
1714 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1718 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1715 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1719 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1716 | 1720 |
1717 // Free the webView before the TouchEventHandlerWebViewClient gets freed. | 1721 // Free the webView before the TouchEventHandlerWebViewClient gets freed. |
1718 m_webViewHelper.reset(); | 1722 m_webViewHelper.reset(); |
1719 } | 1723 } |
1720 | 1724 |
1721 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) | 1725 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) |
1722 { | 1726 { |
1723 WebCore::Element* element = document->getElementById("root"); | 1727 WebCore::Element* element = document->getElementById("root"); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 | 2000 |
1997 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2001 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
1998 | 2002 |
1999 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2003 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
2000 | 2004 |
2001 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2005 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
2002 webView->setAutofillClient(0); | 2006 webView->setAutofillClient(0); |
2003 } | 2007 } |
2004 | 2008 |
2005 } // namespace | 2009 } // namespace |
OLD | NEW |