Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / tests / TouchActionTest.cpp
old mode 100755 (executable)
new mode 100644 (file)
index ef4be34..064d1e9
 
 #include "config.h"
 
-#include "FrameTestHelpers.h"
-#include "RuntimeEnabledFeatures.h"
-#include "URLTestHelpers.h"
-#include "WebDocument.h"
-#include "WebFrame.h"
-#include "WebInputEvent.h"
-#include "WebView.h"
-#include "WebViewClient.h"
-#include "WebViewImpl.h"
 #include "core/dom/ClientRect.h"
 #include "core/dom/ClientRectList.h"
 #include "core/dom/Document.h"
 #include "core/dom/Element.h"
+#include "core/dom/StaticNodeList.h"
 #include "core/dom/shadow/ShadowRoot.h"
-#include "core/frame/Frame.h"
 #include "core/frame/FrameView.h"
+#include "core/frame/LocalFrame.h"
 #include "core/page/EventHandler.h"
 #include "core/rendering/HitTestResult.h"
 #include "core/rendering/RenderTreeAsText.h"
+#include "core/testing/URLTestHelpers.h"
 #include "public/platform/Platform.h"
 #include "public/platform/WebUnitTestSupport.h"
+#include "public/web/WebDocument.h"
+#include "public/web/WebFrame.h"
 #include "public/web/WebHitTestResult.h"
+#include "public/web/WebInputEvent.h"
 #include "public/web/WebTouchAction.h"
+#include "public/web/WebView.h"
+#include "public/web/WebViewClient.h"
 #include "public/web/WebWidgetClient.h"
+#include "web/WebViewImpl.h"
+#include "web/tests/FrameTestHelpers.h"
 
 #include <gtest/gtest.h>
 
@@ -62,7 +62,7 @@ using blink::FrameTestHelpers::runPendingTasks;
 
 namespace {
 
-class TouchActionTrackingWebViewClient : public WebViewClient {
+class TouchActionTrackingWebViewClient : public FrameTestHelpers::TestWebViewClient {
 public:
     TouchActionTrackingWebViewClient() :
         m_actionSetCount(0),
@@ -108,7 +108,6 @@ public:
     {
         URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), "touch-action-tests.css");
         URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), "touch-action-tests.js");
-        WebCore::RuntimeEnabledFeatures::setCSSTouchActionEnabled(true);
     }
 
     virtual void TearDown()
@@ -119,9 +118,9 @@ public:
 protected:
     void runTouchActionTest(std::string file);
     void runShadowDOMTest(std::string file);
-    void sendTouchEvent(WebView*, WebInputEvent::Type, WebCore::IntPoint clientPoint);
+    void sendTouchEvent(WebView*, WebInputEvent::Type, IntPoint clientPoint);
     WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&);
-    void runTestOnTree(WebCore::ContainerNode* root, WebView*, TouchActionTrackingWebViewClient&);
+    void runTestOnTree(ContainerNode* root, WebView*, TouchActionTrackingWebViewClient&);
 
     std::string m_baseURL;
     FrameTestHelpers::WebViewHelper m_webViewHelper;
@@ -131,10 +130,22 @@ void TouchActionTest::runTouchActionTest(std::string file)
 {
     TouchActionTrackingWebViewClient client;
 
+    // runTouchActionTest() loads a document in a frame, setting up a
+    // nested message loop. Should any Oilpan GC happen while it is in
+    // effect, the implicit assumption that we're outside any event
+    // loop (=> there being no pointers on the stack needing scanning)
+    // when that GC strikes will no longer hold.
+    //
+    // To ensure that the references on the stack are also traced, we
+    // turn them into persistent, stack allocated references. This
+    // workaround is sufficient to handle this artificial test
+    // scenario.
     WebView* webView = setupTest(file, client);
 
-    RefPtr<WebCore::Document> document = static_cast<PassRefPtr<WebCore::Document> >(webView->mainFrame()->document());
+    RefPtrWillBePersistent<Document> document = static_cast<PassRefPtrWillBeRawPtr<Document> >(webView->mainFrame()->document());
     runTestOnTree(document.get(), webView, client);
+
+    m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
 }
 
 void TouchActionTest::runShadowDOMTest(std::string file)
@@ -143,19 +154,23 @@ void TouchActionTest::runShadowDOMTest(std::string file)
 
     WebView* webView = setupTest(file, client);
 
-    WebCore::TrackExceptionState es;
-    RefPtr<WebCore::Document> document = static_cast<PassRefPtr<WebCore::Document> >(webView->mainFrame()->document());
-    RefPtr<WebCore::NodeList> hostNodes = document->querySelectorAll("[shadow-host]", es);
+    TrackExceptionState es;
+
+    // Oilpan: see runTouchActionTest() comment why these are persistent references.
+    RefPtrWillBePersistent<Document> document = static_cast<PassRefPtrWillBeRawPtr<Document> >(webView->mainFrame()->document());
+    RefPtrWillBePersistent<StaticElementList> hostNodes = document->querySelectorAll("[shadow-host]", es);
     ASSERT_FALSE(es.hadException());
     ASSERT_GE(hostNodes->length(), 1u);
 
     for (unsigned index = 0; index < hostNodes->length(); index++) {
-        WebCore::ShadowRoot* shadowRoot = WebCore::toElement(hostNodes->item(index))->shadowRoot();
+        ShadowRoot* shadowRoot = hostNodes->item(index)->shadowRoot();
         runTestOnTree(shadowRoot, webView, client);
     }
 
     // Projections show up in the main document.
     runTestOnTree(document.get(), webView, client);
+
+    m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
 }
 
 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebViewClient& client)
@@ -164,28 +179,32 @@ WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView
     // Note that JavaScript must be enabled for shadow DOM tests.
     WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client);
 
+    // Lock page scale factor to avoid zooming out to contents size.
+    m_webViewHelper.webView()->setPageScaleFactorLimits(1, 1);
+
     // Set size to enable hit testing, and avoid line wrapping for consistency with browser.
-    webView->resize(WebSize(700, 1000));
+    webView->resize(WebSize(800, 1200));
 
     // Scroll to verify the code properly transforms windows to client co-ords.
     const int kScrollOffset = 100;
-    RefPtr<WebCore::Document> document = static_cast<PassRefPtr<WebCore::Document> >(webView->mainFrame()->document());
-    document->frame()->view()->setScrollOffset(WebCore::IntPoint(0, kScrollOffset));
+    RefPtrWillBeRawPtr<Document> document = static_cast<PassRefPtrWillBeRawPtr<Document> >(webView->mainFrame()->document());
+    document->frame()->view()->setScrollOffset(IntPoint(0, kScrollOffset));
 
     return webView;
 }
 
-void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webView, TouchActionTrackingWebViewClient& client)
+void TouchActionTest::runTestOnTree(ContainerNode* root, WebView* webView, TouchActionTrackingWebViewClient& client)
 {
     // Find all elements to test the touch-action of in the document.
-    WebCore::TrackExceptionState es;
-    RefPtr<WebCore::NodeList> nodes = root->querySelectorAll("[expected-action]", es);
+    TrackExceptionState es;
+
+    // Oilpan: see runTouchActionTest() comment why these are persistent references.
+    RefPtrWillBePersistent<StaticElementList> elements = root->querySelectorAll("[expected-action]", es);
     ASSERT_FALSE(es.hadException());
 
-    for (unsigned index = 0; index < nodes->length(); index++) {
-        WebCore::Element* element = toElement(nodes->item(index));
+    for (unsigned index = 0; index < elements->length(); index++) {
+        Element* element = elements->item(index);
         element->scrollIntoViewIfNeeded();
-        ASSERT_TRUE(nodes->item(index)->isElementNode());
 
         std::string failureContext("Test case: ");
         if (element->hasID()) {
@@ -202,13 +221,13 @@ void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
         // Note that we don't want the bounding box because our tests sometimes have elements with
         // multiple border boxes with other elements in between. Use the first border box (which
         // we can easily visualize in a browser for debugging).
-        RefPtr<WebCore::ClientRectList> rects = element->getClientRects();
+        RefPtrWillBePersistent<ClientRectList> rects = element->getClientRects();
         ASSERT_GE(rects->length(), 0u) << failureContext;
-        RefPtr<WebCore::ClientRect> r = rects->item(0);
-        WebCore::FloatRect clientFloatRect = WebCore::FloatRect(r->left(), r->top(), r->width(), r->height());
-        WebCore::IntRect clientRect =  enclosedIntRect(clientFloatRect);
+        RefPtrWillBePersistent<ClientRect> r = rects->item(0);
+        FloatRect clientFloatRect = FloatRect(r->left(), r->top(), r->width(), r->height());
+        IntRect clientRect =  enclosedIntRect(clientFloatRect);
         for (int locIdx = 0; locIdx < 3; locIdx++) {
-            WebCore::IntPoint clientPoint;
+            IntPoint clientPoint;
             std::stringstream contextStream;
             contextStream << failureContext << " (";
             switch (locIdx) {
@@ -231,9 +250,9 @@ void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
             contextStream << "=" << clientPoint.x() << "," << clientPoint.y() << ").";
             std::string failureContextPos = contextStream.str();
 
-            WebCore::Frame* frame = root->document().frame();
-            WebCore::FrameView* frameView = frame->view();
-            WebCore::IntRect visibleRect = frameView->windowClipRect();
+            LocalFrame* frame = root->document().frame();
+            FrameView* frameView = frame->view();
+            IntRect visibleRect = frameView->windowClipRect();
             ASSERT_TRUE(visibleRect.contains(clientPoint)) << failureContextPos
                 << " Test point not contained in visible area: " << visibleRect.x() << "," << visibleRect.y()
                 << "-" << visibleRect.maxX() << "," << visibleRect.maxY();
@@ -242,8 +261,8 @@ void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
             // we intended. This is the easiest way for a test to be broken, but has nothing really
             // to do with touch action.
             // Note that we can't use WebView's hit test API because it doesn't look into shadow DOM.
-            WebCore::IntPoint docPoint(frameView->windowToContents(clientPoint));
-            WebCore::HitTestResult result = frame->eventHandler().hitTestResultAtPoint(docPoint, WebCore::HitTestRequest::ReadOnly | WebCore::HitTestRequest::Active);
+            IntPoint docPoint(frameView->windowToContents(clientPoint));
+            HitTestResult result = frame->eventHandler().hitTestResultAtPoint(docPoint, HitTestRequest::ReadOnly | HitTestRequest::Active);
             ASSERT_EQ(element, result.innerElement()) << "Unexpected hit test result " << failureContextPos
                 << "  Got element: \"" << result.innerElement()->outerHTML().stripWhiteSpace().left(80).ascii().data() << "\""
                 << std::endl << "Document render tree:" << std::endl << externalRepresentation(root->document().frame()).utf8().data();
@@ -268,6 +287,8 @@ void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
                         EXPECT_EQ(WebTouchActionPanY, client.lastTouchAction()) << failureContextPos;
                     } else if (expectedAction == "pan-x-y") {
                         EXPECT_EQ((WebTouchActionPanX | WebTouchActionPanY), client.lastTouchAction()) << failureContextPos;
+                    } else if (expectedAction == "manipulation") {
+                        EXPECT_EQ((WebTouchActionPanX | WebTouchActionPanY | WebTouchActionPinchZoom), client.lastTouchAction()) << failureContextPos;
                     } else {
                         FAIL() << "Unrecognized expected-action \"" << expectedAction.ascii().data()
                             << "\" " << failureContextPos;
@@ -282,12 +303,14 @@ void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
         }
     }
 }
-void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, WebCore::IntPoint clientPoint)
+void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, IntPoint clientPoint)
 {
     ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::TouchCancel);
 
     WebTouchEvent webTouchEvent;
     webTouchEvent.type = type;
+    if (type == WebInputEvent::TouchCancel)
+        webTouchEvent.cancelable = false;
     webTouchEvent.touchesLength = 1;
     webTouchEvent.touches[0].state = (type == WebInputEvent::TouchStart ?
         WebTouchPoint::StatePressed :
@@ -304,7 +327,8 @@ void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type,
     runPendingTasks();
 }
 
-TEST_F(TouchActionTest, Simple)
+// crbug.com/411038
+TEST_F(TouchActionTest, DISABLED_Simple)
 {
     runTouchActionTest("touch-action-simple.html");
 }