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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "WebFrameImpl.h" | 44 #include "WebFrameImpl.h" |
45 #include "WebHitTestResult.h" | 45 #include "WebHitTestResult.h" |
46 #include "WebInputEvent.h" | 46 #include "WebInputEvent.h" |
47 #include "WebSettings.h" | 47 #include "WebSettings.h" |
48 #include "WebSettingsImpl.h" | 48 #include "WebSettingsImpl.h" |
49 #include "WebViewClient.h" | 49 #include "WebViewClient.h" |
50 #include "WebViewImpl.h" | 50 #include "WebViewImpl.h" |
51 #include "WebWidget.h" | 51 #include "WebWidget.h" |
52 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
53 #include "core/dom/Element.h" | 53 #include "core/dom/Element.h" |
54 #include "core/dom/EventHandlerRegistry.h" | |
54 #include "core/html/HTMLDocument.h" | 55 #include "core/html/HTMLDocument.h" |
55 #include "core/html/HTMLIFrameElement.h" | 56 #include "core/html/HTMLIFrameElement.h" |
56 #include "core/html/HTMLInputElement.h" | 57 #include "core/html/HTMLInputElement.h" |
57 #include "core/loader/FrameLoadRequest.h" | 58 #include "core/loader/FrameLoadRequest.h" |
58 #include "core/frame/FrameView.h" | 59 #include "core/frame/FrameView.h" |
59 #include "core/page/Chrome.h" | 60 #include "core/page/Chrome.h" |
60 #include "core/frame/Settings.h" | 61 #include "core/frame/Settings.h" |
61 #include "platform/KeyboardCodes.h" | 62 #include "platform/KeyboardCodes.h" |
62 #include "platform/graphics/Color.h" | 63 #include "platform/graphics/Color.h" |
63 #include "public/platform/Platform.h" | 64 #include "public/platform/Platform.h" |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 int value = m_hasTouchEventHandlerCount[state]; | 1536 int value = m_hasTouchEventHandlerCount[state]; |
1536 m_hasTouchEventHandlerCount[state] = 0; | 1537 m_hasTouchEventHandlerCount[state] = 0; |
1537 return value; | 1538 return value; |
1538 } | 1539 } |
1539 | 1540 |
1540 private: | 1541 private: |
1541 int m_hasTouchEventHandlerCount[2]; | 1542 int m_hasTouchEventHandlerCount[2]; |
1542 }; | 1543 }; |
1543 | 1544 |
1544 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco rdingly for various | 1545 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called acco rdingly for various |
1545 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho se calls are made | 1546 // calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that tho se calls are made |
Rick Byers
2014/03/27 16:43:31
update comment please
Sami
2014/04/02 19:58:05
Done.
| |
1546 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm l. | 1547 // correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.htm l. |
1547 TEST_F(WebViewTest, HasTouchEventHandlers) | 1548 TEST_F(WebViewTest, HasTouchEventHandlers) |
1548 { | 1549 { |
1549 TouchEventHandlerWebViewClient client; | 1550 TouchEventHandlerWebViewClient client; |
1550 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1551 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
1551 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers .html"); | 1552 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers .html"); |
1552 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); | 1553 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); |
1554 const AtomicString& touchstart = WebCore::EventTypeNames::touchstart; | |
1553 | 1555 |
1554 // The page is initialized with at least one no-handlers call. | 1556 // The page is initialized with at least one no-handlers call. |
1555 // In practice we get two such calls because WebViewHelper::initializeAndLoa d first | 1557 // In practice we get two such calls because WebViewHelper::initializeAndLoa d first |
1556 // initializes and empty frame, and then loads a document into it, so there are two | 1558 // initializes and empty frame, and then loads a document into it, so there are two |
1557 // FrameLoader::commitProvisionalLoad calls. | 1559 // FrameLoader::commitProvisionalLoad calls. |
1558 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1560 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
1559 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1561 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1560 | 1562 |
1561 // Adding the first document handler results in a has-handlers call. | 1563 // Adding the first document handler results in a has-handlers call. |
1562 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen t(); | 1564 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen t(); |
1563 document->didAddTouchEventHandler(document); | 1565 WebCore::EventHandlerRegistry* registry = WebCore::EventHandlerRegistry::fro m(*document); |
1566 registry->didAddEventHandler(*document, touchstart); | |
1564 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1567 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1565 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1568 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1566 | 1569 |
1567 // Adding another handler has no effect. | 1570 // Adding another handler has no effect. |
1568 document->didAddTouchEventHandler(document); | 1571 registry->didAddEventHandler(*document, touchstart); |
1569 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1572 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1570 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1573 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1571 | 1574 |
1572 // Removing the duplicate handler has no effect. | 1575 // Removing the duplicate handler has no effect. |
1573 document->didRemoveTouchEventHandler(document); | 1576 registry->didRemoveEventHandler(*document, touchstart); |
1574 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1577 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1575 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1578 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1576 | 1579 |
1577 // Removing the final handler results in a no-handlers call. | 1580 // Removing the final handler results in a no-handlers call. |
1578 document->didRemoveTouchEventHandler(document); | 1581 registry->didRemoveEventHandler(*document, touchstart); |
1579 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1582 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1580 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1583 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1581 | 1584 |
1582 // Adding a handler on a div results in a has-handlers call. | 1585 // Adding a handler on a div results in a has-handlers call. |
1583 WebCore::Element* parentDiv = document->getElementById("parentdiv"); | 1586 WebCore::Element* parentDiv = document->getElementById("parentdiv"); |
1584 ASSERT(parentDiv); | 1587 ASSERT(parentDiv); |
1585 document->didAddTouchEventHandler(parentDiv); | 1588 registry->didAddEventHandler(*parentDiv, touchstart); |
1586 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1589 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1587 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1590 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1588 | 1591 |
1589 // Adding a duplicate handler on the div, clearing all document handlers | 1592 // Adding a duplicate handler on the div, clearing all document handlers |
1590 // (of which there are none) and removing the extra handler on the div | 1593 // (of which there are none) and removing the extra handler on the div |
1591 // all have no effect. | 1594 // all have no effect. |
1592 document->didAddTouchEventHandler(parentDiv); | 1595 registry->didAddEventHandler(*parentDiv, touchstart); |
1593 document->didClearTouchEventHandlers(document); | 1596 registry->didRemoveAllEventHandlers(*document); |
1594 document->didRemoveTouchEventHandler(parentDiv); | 1597 registry->didRemoveEventHandler(*parentDiv, touchstart); |
1595 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1598 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1596 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1599 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1597 | 1600 |
1598 // Removing the final handler on the div results in a no-handlers call. | 1601 // Removing the final handler on the div results in a no-handlers call. |
1599 document->didRemoveTouchEventHandler(parentDiv); | 1602 registry->didRemoveEventHandler(*parentDiv, touchstart); |
1600 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1603 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1601 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1604 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1602 | 1605 |
1603 // Adding two handlers then clearing them in a single call results in a | 1606 // Adding two handlers then clearing them in a single call results in a |
1604 // has-handlers then no-handlers call. | 1607 // has-handlers then no-handlers call. |
1605 document->didAddTouchEventHandler(parentDiv); | 1608 registry->didAddEventHandler(*parentDiv, touchstart); |
1606 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1609 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1607 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1610 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1608 document->didAddTouchEventHandler(parentDiv); | 1611 registry->didAddEventHandler(*parentDiv, touchstart); |
1609 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1612 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1610 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1613 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1611 document->didClearTouchEventHandlers(parentDiv); | 1614 registry->didRemoveAllEventHandlers(*parentDiv); |
1612 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1615 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1613 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1616 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1617 } | |
1618 | |
1619 TEST_F(WebViewTest, HasTouchEventHandlersInChildDocument) | |
1620 { | |
1621 TouchEventHandlerWebViewClient client; | |
1622 std::string url = m_baseURL + "has_touch_event_handlers.html"; | |
1623 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers .html"); | |
1624 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); | |
1625 const AtomicString& touchstart = WebCore::EventTypeNames::touchstart; | |
1626 | |
1627 // The page is initialized with at least one no-handlers call. | |
1628 // In practice we get two such calls because WebViewHelper::initializeAndLoa d first | |
1629 // initializes and empty frame, and then loads a document into it, so there are two | |
1630 // FrameLoader::commitProvisionalLoad calls. | |
1631 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | |
1632 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | |
1614 | 1633 |
1615 // Adding a handler inside of a child iframe results in a has-handlers call. | 1634 // Adding a handler inside of a child iframe results in a has-handlers call. |
1635 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen t(); | |
1636 WebCore::EventHandlerRegistry* registry = WebCore::EventHandlerRegistry::fro m(*document); | |
1616 WebCore::Element* childFrame = document->getElementById("childframe"); | 1637 WebCore::Element* childFrame = document->getElementById("childframe"); |
1617 ASSERT(childFrame); | 1638 ASSERT(childFrame); |
1618 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD ocument(); | 1639 WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentD ocument(); |
1640 WebCore::EventHandlerRegistry* childRegistry = WebCore::EventHandlerRegistry ::from(*childDocument); | |
1619 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); | 1641 WebCore::Element* childDiv = childDocument->getElementById("childdiv"); |
1620 ASSERT(childDiv); | 1642 ASSERT(childDiv); |
1621 childDocument->didAddTouchEventHandler(childDiv); | 1643 childRegistry->didAddEventHandler(*childDiv, touchstart); |
1622 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1644 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1623 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1645 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1624 | 1646 |
1625 // Adding and clearing handlers in the parent doc or elsewhere in the child doc | 1647 // Adding and clearing handlers in the parent doc or elsewhere in the child doc |
1626 // has no impact. | 1648 // has no impact. |
1627 document->didAddTouchEventHandler(document); | 1649 registry->didAddEventHandler(*document, touchstart); |
1628 document->didAddTouchEventHandler(childFrame); | 1650 registry->didAddEventHandler(*childFrame, touchstart); |
1629 childDocument->didAddTouchEventHandler(childDocument); | 1651 childRegistry->didAddEventHandler(*childDocument, touchstart); |
1630 document->didClearTouchEventHandlers(document); | 1652 registry->didRemoveAllEventHandlers(*document); |
1631 document->didClearTouchEventHandlers(childFrame); | 1653 registry->didRemoveAllEventHandlers(*childFrame); |
1632 childDocument->didClearTouchEventHandlers(childDocument); | 1654 childRegistry->didRemoveAllEventHandlers(*childDocument); |
1633 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1655 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1634 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1656 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1635 | 1657 |
1636 // Removing the final handler inside the child frame results in a no-handler s call. | 1658 // Removing the final handler inside the child frame results in a no-handler s call. |
1637 childDocument->didRemoveTouchEventHandler(childDiv); | 1659 childRegistry->didRemoveAllEventHandlers(*childDiv); |
1638 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1660 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1639 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1661 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1640 | 1662 |
1641 // Adding a handler inside the child frame results in a has-handlers call. | 1663 // Adding a handler inside the child frame results in a has-handlers call. |
1642 childDocument->didAddTouchEventHandler(childDocument); | 1664 childRegistry->didAddEventHandler(*childDocument, touchstart); |
1643 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1665 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1644 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1666 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1645 | 1667 |
1646 // Adding a handler in the parent document and removing the one in the frame | 1668 // Adding a handler in the parent document and removing the one in the frame |
1647 // has no effect. | 1669 // has no effect. |
1648 document->didAddTouchEventHandler(childFrame); | 1670 registry->didAddEventHandler(*childFrame, touchstart); |
1649 childDocument->didRemoveTouchEventHandler(childDocument); | 1671 childRegistry->didRemoveEventHandler(*childDocument, touchstart); |
1650 childDocument->didClearTouchEventHandlers(childDocument); | 1672 childRegistry->didRemoveAllEventHandlers(*childDocument); |
1651 document->didClearTouchEventHandlers(document); | 1673 registry->didRemoveAllEventHandlers(*document); |
1652 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1674 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1653 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1675 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1654 | 1676 |
1655 // Now removing the handler in the parent document results in a no-handlers call. | 1677 // Now removing the handler in the parent document results in a no-handlers call. |
1656 document->didRemoveTouchEventHandler(childFrame); | 1678 registry->didRemoveEventHandler(*childFrame, touchstart); |
1657 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1679 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1658 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1680 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1659 } | 1681 } |
1660 | 1682 |
1661 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor ) | 1683 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor ) |
1662 { | 1684 { |
1663 WebCore::Element* element = document->getElementById("root"); | 1685 WebCore::Element* element = document->getElementById("root"); |
1664 if (!element) | 1686 if (!element) |
1665 element = document->getElementById("target"); | 1687 element = document->getElementById("target"); |
1666 if (element->hasTagName(WebCore::HTMLNames::iframeTag)) | 1688 if (element->hasTagName(WebCore::HTMLNames::iframeTag)) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1740 testSelectionRootBounds("select_range_iframe_textarea_overflow.html", 1.0f); | 1762 testSelectionRootBounds("select_range_iframe_textarea_overflow.html", 1.0f); |
1741 | 1763 |
1742 // Basic page with scale factor. | 1764 // Basic page with scale factor. |
1743 testSelectionRootBounds("select_range_basic.html", 0.0f); | 1765 testSelectionRootBounds("select_range_basic.html", 0.0f); |
1744 testSelectionRootBounds("select_range_basic.html", 0.1f); | 1766 testSelectionRootBounds("select_range_basic.html", 0.1f); |
1745 testSelectionRootBounds("select_range_basic.html", 1.5f); | 1767 testSelectionRootBounds("select_range_basic.html", 1.5f); |
1746 testSelectionRootBounds("select_range_basic.html", 2.0f); | 1768 testSelectionRootBounds("select_range_basic.html", 2.0f); |
1747 } | 1769 } |
1748 | 1770 |
1749 } // namespace | 1771 } // namespace |
OLD | NEW |