| 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 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 { | 1697 { |
| 1698 int value = m_hasTouchEventHandlerCount[state]; | 1698 int value = m_hasTouchEventHandlerCount[state]; |
| 1699 m_hasTouchEventHandlerCount[state] = 0; | 1699 m_hasTouchEventHandlerCount[state] = 0; |
| 1700 return value; | 1700 return value; |
| 1701 } | 1701 } |
| 1702 | 1702 |
| 1703 private: | 1703 private: |
| 1704 int m_hasTouchEventHandlerCount[2]; | 1704 int m_hasTouchEventHandlerCount[2]; |
| 1705 }; | 1705 }; |
| 1706 | 1706 |
| 1707 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco
rdingly for various | 1707 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called |
| 1708 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho
se calls are made | 1708 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| |
| 1709 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm
l. | 1709 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made |
| 1710 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. |
| 1710 TEST_F(WebViewTest, HasTouchEventHandlers) | 1711 TEST_F(WebViewTest, HasTouchEventHandlers) |
| 1711 { | 1712 { |
| 1712 TouchEventHandlerWebViewClient client; | 1713 TouchEventHandlerWebViewClient client; |
| 1713 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1714 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
| 1714 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); | 1715 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); |
| 1715 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1716 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1717 const blink::EventHandlerRegistry::EventHandlerClass touchEvent = blink::Eve
ntHandlerRegistry::TouchEvent; |
| 1716 | 1718 |
| 1717 // The page is initialized with at least one no-handlers call. | 1719 // The page is initialized with at least one no-handlers call. |
| 1718 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first | 1720 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first |
| 1719 // initializes and empty frame, and then loads a document into it, so there
are two | 1721 // initializes and empty frame, and then loads a document into it, so there
are two |
| 1720 // FrameLoader::commitProvisionalLoad calls. | 1722 // FrameLoader::commitProvisionalLoad calls. |
| 1721 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1723 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
| 1722 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1724 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1723 | 1725 |
| 1724 // Adding the first document handler results in a has-handlers call. | 1726 // Adding the first document handler results in a has-handlers call. |
| 1725 blink::Document* document = webViewImpl->mainFrameImpl()->frame()->document(
); | 1727 blink::Document* document = webViewImpl->mainFrameImpl()->frame()->document(
); |
| 1726 document->didAddTouchEventHandler(document); | 1728 blink::EventHandlerRegistry* registry = &document->frameHost()->eventHandler
Registry(); |
| 1729 registry->didAddEventHandler(*document, touchEvent); |
| 1727 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1730 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1728 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1731 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1729 | 1732 |
| 1730 // Adding another handler has no effect. | 1733 // Adding another handler has no effect. |
| 1731 document->didAddTouchEventHandler(document); | 1734 registry->didAddEventHandler(*document, touchEvent); |
| 1732 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1735 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1733 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1736 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1734 | 1737 |
| 1735 // Removing the duplicate handler has no effect. | 1738 // Removing the duplicate handler has no effect. |
| 1736 document->didRemoveTouchEventHandler(document); | 1739 registry->didRemoveEventHandler(*document, touchEvent); |
| 1737 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1740 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1738 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1741 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1739 | 1742 |
| 1740 // Removing the final handler results in a no-handlers call. | 1743 // Removing the final handler results in a no-handlers call. |
| 1741 document->didRemoveTouchEventHandler(document); | 1744 registry->didRemoveEventHandler(*document, touchEvent); |
| 1742 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1745 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1743 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1746 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1744 | 1747 |
| 1745 // Adding a handler on a div results in a has-handlers call. | 1748 // Adding a handler on a div results in a has-handlers call. |
| 1746 blink::Element* parentDiv = document->getElementById("parentdiv"); | 1749 blink::Element* parentDiv = document->getElementById("parentdiv"); |
| 1747 ASSERT(parentDiv); | 1750 ASSERT(parentDiv); |
| 1748 document->didAddTouchEventHandler(parentDiv); | 1751 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1749 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1752 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1750 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1753 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1751 | 1754 |
| 1752 // Adding a duplicate handler on the div, clearing all document handlers | 1755 // Adding a duplicate handler on the div, clearing all document handlers |
| 1753 // (of which there are none) and removing the extra handler on the div | 1756 // (of which there are none) and removing the extra handler on the div |
| 1754 // all have no effect. | 1757 // all have no effect. |
| 1755 document->didAddTouchEventHandler(parentDiv); | 1758 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1756 document->didClearTouchEventHandlers(document); | 1759 registry->didRemoveAllEventHandlers(*document); |
| 1757 document->didRemoveTouchEventHandler(parentDiv); | 1760 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
| 1758 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1761 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1759 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1762 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1760 | 1763 |
| 1761 // Removing the final handler on the div results in a no-handlers call. | 1764 // Removing the final handler on the div results in a no-handlers call. |
| 1762 document->didRemoveTouchEventHandler(parentDiv); | 1765 registry->didRemoveEventHandler(*parentDiv, touchEvent); |
| 1763 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1766 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1764 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1767 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1765 | 1768 |
| 1766 // Adding two handlers then clearing them in a single call results in a | 1769 // Adding two handlers then clearing them in a single call results in a |
| 1767 // has-handlers then no-handlers call. | 1770 // has-handlers then no-handlers call. |
| 1768 document->didAddTouchEventHandler(parentDiv); | 1771 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1769 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1772 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1770 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1773 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1771 document->didAddTouchEventHandler(parentDiv); | 1774 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1772 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1775 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1773 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1776 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1774 document->didClearTouchEventHandlers(parentDiv); | 1777 registry->didRemoveAllEventHandlers(*parentDiv); |
| 1775 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1778 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1776 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1779 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1777 | 1780 |
| 1778 // Adding a handler inside of a child iframe results in a has-handlers call. | 1781 // Adding a handler inside of a child iframe results in a has-handlers call. |
| 1779 blink::Element* childFrame = document->getElementById("childframe"); | 1782 blink::Element* childFrame = document->getElementById("childframe"); |
| 1780 ASSERT(childFrame); | 1783 ASSERT(childFrame); |
| 1781 blink::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDoc
ument(); | 1784 blink::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDoc
ument(); |
| 1782 blink::Element* childDiv = childDocument->getElementById("childdiv"); | 1785 blink::Element* childDiv = childDocument->getElementById("childdiv"); |
| 1783 ASSERT(childDiv); | 1786 ASSERT(childDiv); |
| 1784 childDocument->didAddTouchEventHandler(childDiv); | 1787 registry->didAddEventHandler(*childDiv, touchEvent); |
| 1785 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1788 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1786 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1789 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1787 | 1790 |
| 1788 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc | 1791 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc |
| 1789 // has no impact. | 1792 // has no impact. |
| 1790 document->didAddTouchEventHandler(document); | 1793 registry->didAddEventHandler(*document, touchEvent); |
| 1791 document->didAddTouchEventHandler(childFrame); | 1794 registry->didAddEventHandler(*childFrame, touchEvent); |
| 1792 childDocument->didAddTouchEventHandler(childDocument); | 1795 registry->didAddEventHandler(*childDocument, touchEvent); |
| 1793 document->didClearTouchEventHandlers(document); | 1796 registry->didRemoveAllEventHandlers(*document); |
| 1794 document->didClearTouchEventHandlers(childFrame); | 1797 registry->didRemoveAllEventHandlers(*childFrame); |
| 1795 childDocument->didClearTouchEventHandlers(childDocument); | 1798 registry->didRemoveAllEventHandlers(*childDocument); |
| 1796 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1799 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1797 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1800 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1798 | 1801 |
| 1799 // Removing the final handler inside the child frame results in a no-handler
s call. | 1802 // Removing the final handler inside the child frame results in a no-handler
s call. |
| 1800 childDocument->didRemoveTouchEventHandler(childDiv); | 1803 registry->didRemoveAllEventHandlers(*childDiv); |
| 1801 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1804 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1802 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1805 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1803 | 1806 |
| 1804 // Adding a handler inside the child frame results in a has-handlers call. | 1807 // Adding a handler inside the child frame results in a has-handlers call. |
| 1805 childDocument->didAddTouchEventHandler(childDocument); | 1808 registry->didAddEventHandler(*childDocument, touchEvent); |
| 1806 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1809 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1807 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1810 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1808 | 1811 |
| 1809 // Adding a handler in the parent document and removing the one in the frame | 1812 // Adding a handler in the parent document and removing the one in the frame |
| 1810 // has no effect. | 1813 // has no effect. |
| 1811 document->didAddTouchEventHandler(childFrame); | 1814 registry->didAddEventHandler(*childFrame, touchEvent); |
| 1812 childDocument->didRemoveTouchEventHandler(childDocument); | 1815 registry->didRemoveEventHandler(*childDocument, touchEvent); |
| 1813 childDocument->didClearTouchEventHandlers(childDocument); | 1816 registry->didRemoveAllEventHandlers(*childDocument); |
| 1814 document->didClearTouchEventHandlers(document); | 1817 registry->didRemoveAllEventHandlers(*document); |
| 1815 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1818 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1816 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1819 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1817 | 1820 |
| 1818 // Now removing the handler in the parent document results in a no-handlers
call. | 1821 // Now removing the handler in the parent document results in a no-handlers
call. |
| 1819 document->didRemoveTouchEventHandler(childFrame); | 1822 registry->didRemoveEventHandler(*childFrame, touchEvent); |
| 1820 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1823 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1821 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1824 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1822 | 1825 |
| 1823 // Free the webView before the TouchEventHandlerWebViewClient gets freed. | 1826 // Free the webView before the TouchEventHandlerWebViewClient gets freed. |
| 1824 m_webViewHelper.reset(); | 1827 m_webViewHelper.reset(); |
| 1825 } | 1828 } |
| 1826 | 1829 |
| 1827 // This test checks that deleting nodes which have only non-JS-registered touch | 1830 // This test checks that deleting nodes which have only non-JS-registered touch |
| 1828 // handlers also removes them from the event handler registry. Note that this | 1831 // handlers also removes them from the event handler registry. Note that this |
| 1829 // is different from detaching and re-attaching the same node, which is covered | 1832 // is different from detaching and re-attaching the same node, which is covered |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 | 2134 |
| 2132 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2135 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2133 | 2136 |
| 2134 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2137 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
| 2135 | 2138 |
| 2136 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2139 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2137 webView->setAutofillClient(0); | 2140 webView->setAutofillClient(0); |
| 2138 } | 2141 } |
| 2139 | 2142 |
| 2140 } // namespace | 2143 } // namespace |
| OLD | NEW |