Index: Source/web/tests/WebViewTest.cpp |
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp |
index 97ce3a6d1bcde3cb51f8606388097346416e07c7..5eb03066941c14579afad766ab479c5d96049b84 100644 |
--- a/Source/web/tests/WebViewTest.cpp |
+++ b/Source/web/tests/WebViewTest.cpp |
@@ -51,6 +51,7 @@ |
#include "WebWidget.h" |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
+#include "core/dom/EventHandlerRegistry.h" |
#include "core/html/HTMLDocument.h" |
#include "core/html/HTMLIFrameElement.h" |
#include "core/html/HTMLInputElement.h" |
@@ -1550,6 +1551,7 @@ TEST_F(WebViewTest, HasTouchEventHandlers) |
std::string url = m_baseURL + "has_touch_event_handlers.html"; |
URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers.html"); |
WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client); |
+ const AtomicString& touchstart = WebCore::EventTypeNames::touchstart; |
// The page is initialized with at least one no-handlers call. |
// In practice we get two such calls because WebViewHelper::initializeAndLoad first |
@@ -1560,100 +1562,120 @@ TEST_F(WebViewTest, HasTouchEventHandlers) |
// Adding the first document handler results in a has-handlers call. |
WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
- document->didAddTouchEventHandler(document); |
+ WebCore::EventHandlerRegistry* registry = WebCore::EventHandlerRegistry::from(*document); |
+ registry->didAddEventHandler(*document, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding another handler has no effect. |
- document->didAddTouchEventHandler(document); |
+ registry->didAddEventHandler(*document, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Removing the duplicate handler has no effect. |
- document->didRemoveTouchEventHandler(document); |
+ registry->didRemoveEventHandler(*document, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Removing the final handler results in a no-handlers call. |
- document->didRemoveTouchEventHandler(document); |
+ registry->didRemoveEventHandler(*document, touchstart); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding a handler on a div results in a has-handlers call. |
WebCore::Element* parentDiv = document->getElementById("parentdiv"); |
ASSERT(parentDiv); |
- document->didAddTouchEventHandler(parentDiv); |
+ registry->didAddEventHandler(*parentDiv, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding a duplicate handler on the div, clearing all document handlers |
// (of which there are none) and removing the extra handler on the div |
// all have no effect. |
- document->didAddTouchEventHandler(parentDiv); |
- document->didClearTouchEventHandlers(document); |
- document->didRemoveTouchEventHandler(parentDiv); |
+ registry->didAddEventHandler(*parentDiv, touchstart); |
+ registry->didRemoveAllEventHandlers(*document); |
+ registry->didRemoveEventHandler(*parentDiv, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Removing the final handler on the div results in a no-handlers call. |
- document->didRemoveTouchEventHandler(parentDiv); |
+ registry->didRemoveEventHandler(*parentDiv, touchstart); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding two handlers then clearing them in a single call results in a |
// has-handlers then no-handlers call. |
- document->didAddTouchEventHandler(parentDiv); |
+ registry->didAddEventHandler(*parentDiv, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
- document->didAddTouchEventHandler(parentDiv); |
+ registry->didAddEventHandler(*parentDiv, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
- document->didClearTouchEventHandlers(parentDiv); |
+ registry->didRemoveAllEventHandlers(*parentDiv); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
+} |
+ |
+TEST_F(WebViewTest, HasTouchEventHandlersInChildDocument) |
+{ |
+ TouchEventHandlerWebViewClient client; |
+ std::string url = m_baseURL + "has_touch_event_handlers.html"; |
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers.html"); |
+ WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client); |
+ const AtomicString& touchstart = WebCore::EventTypeNames::touchstart; |
+ |
+ // The page is initialized with at least one no-handlers call. |
+ // In practice we get two such calls because WebViewHelper::initializeAndLoad first |
+ // initializes and empty frame, and then loads a document into it, so there are two |
+ // FrameLoader::commitProvisionalLoad calls. |
+ EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
+ EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding a handler inside of a child iframe results in a has-handlers call. |
+ WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
+ WebCore::EventHandlerRegistry* registry = WebCore::EventHandlerRegistry::from(*document); |
WebCore::Element* childFrame = document->getElementById("childframe"); |
ASSERT(childFrame); |
WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDocument(); |
+ WebCore::EventHandlerRegistry* childRegistry = WebCore::EventHandlerRegistry::from(*childDocument); |
WebCore::Element* childDiv = childDocument->getElementById("childdiv"); |
ASSERT(childDiv); |
- childDocument->didAddTouchEventHandler(childDiv); |
+ childRegistry->didAddEventHandler(*childDiv, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding and clearing handlers in the parent doc or elsewhere in the child doc |
// has no impact. |
- document->didAddTouchEventHandler(document); |
- document->didAddTouchEventHandler(childFrame); |
- childDocument->didAddTouchEventHandler(childDocument); |
- document->didClearTouchEventHandlers(document); |
- document->didClearTouchEventHandlers(childFrame); |
- childDocument->didClearTouchEventHandlers(childDocument); |
+ registry->didAddEventHandler(*document, touchstart); |
+ registry->didAddEventHandler(*childFrame, touchstart); |
+ childRegistry->didAddEventHandler(*childDocument, touchstart); |
+ registry->didRemoveAllEventHandlers(*document); |
+ registry->didRemoveAllEventHandlers(*childFrame); |
+ childRegistry->didRemoveAllEventHandlers(*childDocument); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Removing the final handler inside the child frame results in a no-handlers call. |
- childDocument->didRemoveTouchEventHandler(childDiv); |
+ childRegistry->didRemoveAllEventHandlers(*childDiv); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding a handler inside the child frame results in a has-handlers call. |
- childDocument->didAddTouchEventHandler(childDocument); |
+ childRegistry->didAddEventHandler(*childDocument, touchstart); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Adding a handler in the parent document and removing the one in the frame |
// has no effect. |
- document->didAddTouchEventHandler(childFrame); |
- childDocument->didRemoveTouchEventHandler(childDocument); |
- childDocument->didClearTouchEventHandlers(childDocument); |
- document->didClearTouchEventHandlers(document); |
+ registry->didAddEventHandler(*childFrame, touchstart); |
+ childRegistry->didRemoveEventHandler(*childDocument, touchstart); |
+ childRegistry->didRemoveAllEventHandlers(*childDocument); |
+ registry->didRemoveAllEventHandlers(*document); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
// Now removing the handler in the parent document results in a no-handlers call. |
- document->didRemoveTouchEventHandler(childFrame); |
+ registry->didRemoveEventHandler(*childFrame, touchstart); |
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
} |