Source/web/tests/WebViewTest.cpp
// This test verifies that WebWidgetClient::hasTouchEventHandlers is called accordingly for various
// calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that those calls are made
// correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.html.
This test verifies that WebWidgetClient::hasTouchEventHandlers is called accordingly for various
calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that those calls are made
correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.html.
This test verifies that WebWidgetClient :: hasTouchEventHandlers is called accordingly for various calls to Document :: did { Add|Remove|Clear } TouchEventHandler . Verifying that those calls are made correctly is the job of LayoutTests / fast / events / touch / touch - handler - count . html .
TEST_F(WebViewTest, HasTouchEventHandlers)
{
    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);
    EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document();
    document->didAddTouchEventHandler(document);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(document);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didRemoveTouchEventHandler(document);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didRemoveTouchEventHandler(document);
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    WebCore::Element* parentDiv = document->getElementById("parentdiv");
    ASSERT(parentDiv);
    document->didAddTouchEventHandler(parentDiv);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(parentDiv);
    document->didClearTouchEventHandlers(document);
    document->didRemoveTouchEventHandler(parentDiv);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didRemoveTouchEventHandler(parentDiv);
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(parentDiv);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(parentDiv);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didClearTouchEventHandlers(parentDiv);
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    WebCore::Element* childFrame = document->getElementById("childframe");
    ASSERT(childFrame);
    WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDocument();
    WebCore::Element* childDiv = childDocument->getElementById("childdiv");
    ASSERT(childDiv);
    childDocument->didAddTouchEventHandler(childDiv);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(document);
    document->didAddTouchEventHandler(childFrame);
    childDocument->didAddTouchEventHandler(childDocument);
    document->didClearTouchEventHandlers(document);
    document->didClearTouchEventHandlers(childFrame);
    childDocument->didClearTouchEventHandlers(childDocument);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    childDocument->didRemoveTouchEventHandler(childDiv);
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    childDocument->didAddTouchEventHandler(childDocument);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didAddTouchEventHandler(childFrame);
    childDocument->didRemoveTouchEventHandler(childDocument);
    childDocument->didClearTouchEventHandlers(childDocument);
    document->didClearTouchEventHandlers(document);
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    document->didRemoveTouchEventHandler(childFrame);
    EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
    EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
    m_webViewHelper.reset();
}
TEST_F ( WebViewTest , HasTouchEventHandlers ) { TouchEventHandlerWebViewClient client ; std :: string url = m_baseURL + " " ; URLTestHelpers :: registerMockedURLLoad ( toKURL ( url ) , " " ) ; WebViewImpl * webViewImpl = m_webViewHelper . initializeAndLoad ( url , true , 0 , & client ) ; EXPECT_GE ( client . getAndResetHasTouchEventHandlerCallCount ( false ) , 1 ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; WebCore :: Document * document = webViewImpl -> mainFrameImpl ( ) -> frame ( ) -> document ( ) ; document -> didAddTouchEventHandler ( document ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( document ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didRemoveTouchEventHandler ( document ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didRemoveTouchEventHandler ( document ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; WebCore :: Element * parentDiv = document -> getElementById ( " " ) ; ASSERT ( parentDiv ) ; document -> didAddTouchEventHandler ( parentDiv ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( parentDiv ) ; document -> didClearTouchEventHandlers ( document ) ; document -> didRemoveTouchEventHandler ( parentDiv ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didRemoveTouchEventHandler ( parentDiv ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( parentDiv ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( parentDiv ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didClearTouchEventHandlers ( parentDiv ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; WebCore :: Element * childFrame = document -> getElementById ( " " ) ; ASSERT ( childFrame ) ; WebCore :: Document * childDocument = toHTMLIFrameElement ( childFrame ) -> contentDocument ( ) ; WebCore :: Element * childDiv = childDocument -> getElementById ( " " ) ; ASSERT ( childDiv ) ; childDocument -> didAddTouchEventHandler ( childDiv ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( document ) ; document -> didAddTouchEventHandler ( childFrame ) ; childDocument -> didAddTouchEventHandler ( childDocument ) ; document -> didClearTouchEventHandlers ( document ) ; document -> didClearTouchEventHandlers ( childFrame ) ; childDocument -> didClearTouchEventHandlers ( childDocument ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; childDocument -> didRemoveTouchEventHandler ( childDiv ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; childDocument -> didAddTouchEventHandler ( childDocument ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didAddTouchEventHandler ( childFrame ) ; childDocument -> didRemoveTouchEventHandler ( childDocument ) ; childDocument -> didClearTouchEventHandlers ( childDocument ) ; document -> didClearTouchEventHandlers ( document ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; document -> didRemoveTouchEventHandler ( childFrame ) ; EXPECT_EQ ( 1 , client . getAndResetHasTouchEventHandlerCallCount ( false ) ) ; EXPECT_EQ ( 0 , client . getAndResetHasTouchEventHandlerCallCount ( true ) ) ; m_webViewHelper . reset ( ) ; }
This test verifies that WebWidgetClient::hasTouchEventHandlers is called accordingly for various
calls to Document::did{Add|Remove|Clear}TouchEventHandler.
This test verifies that WebWidgetClient :: hasTouchEventHandlers is called accordingly for various calls to Document :: did { Add|Remove|Clear } TouchEventHandler .
// 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. // Adding the first document handler results in a has-handlers call. // Adding another handler has no effect. // Removing the duplicate handler has no effect. // Removing the final handler results in a no-handlers call. // Adding a handler on a div results in a has-handlers call. // 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. // Removing the final handler on the div results in a no-handlers call. // Adding two handlers then clearing them in a single call results in a // has-handlers then no-handlers call. // Adding a handler inside of a child iframe results in a has-handlers call. // Adding and clearing handlers in the parent doc or elsewhere in the child doc // has no impact. // Removing the final handler inside the child frame results in a no-handlers call. // Adding a handler inside the child frame results in a has-handlers call. // Adding a handler in the parent document and removing the one in the frame // has no effect. // Now removing the handler in the parent document results in a no-handlers call. // Free the webView before the TouchEventHandlerWebViewClient gets freed.