Title: [117942] trunk/Source/WebKit2
Revision
117942
Author
[email protected]
Date
2012-05-22 03:45:24 -0700 (Tue, 22 May 2012)

Log Message

[Qt] Add UI tests for fit-to-view
https://bugs.webkit.org/show_bug.cgi?id=86857

Reviewed by Simon Hausmann.

Make sure to always emit contentsScaleCommitted when the
contents size changes, so that it can be used for testing.

Also add a method to do single taps.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewFlickablePrivate::didChangeContentsSize):
* UIProcess/API/qt/qwebkittest.cpp:
(touchPoint):
(QWebKitTest::touchTap):
(QWebKitTest::touchDoubleTap):
* UIProcess/API/qt/qwebkittest_p.h:
* UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (117941 => 117942)


--- trunk/Source/WebKit2/ChangeLog	2012-05-22 10:15:16 UTC (rev 117941)
+++ trunk/Source/WebKit2/ChangeLog	2012-05-22 10:45:24 UTC (rev 117942)
@@ -1,3 +1,24 @@
+2012-05-22  Kenneth Rohde Christiansen  <[email protected]>
+
+        [Qt] Add UI tests for fit-to-view
+        https://bugs.webkit.org/show_bug.cgi?id=86857
+
+        Reviewed by Simon Hausmann.
+
+        Make sure to always emit contentsScaleCommitted when the
+        contents size changes, so that it can be used for testing.
+
+        Also add a method to do single taps.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewFlickablePrivate::didChangeContentsSize):
+        * UIProcess/API/qt/qwebkittest.cpp:
+        (touchPoint):
+        (QWebKitTest::touchTap):
+        (QWebKitTest::touchDoubleTap):
+        * UIProcess/API/qt/qwebkittest_p.h:
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml: Added.
+
 2012-05-21  Brady Eidson  <[email protected]>
 
         <rdar://problem/11460336> and https://bugs.webkit.org/show_bug.cgi?id=87061

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (117941 => 117942)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-05-22 10:15:16 UTC (rev 117941)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-05-22 10:45:24 UTC (rev 117942)
@@ -942,15 +942,26 @@
 
     float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(attributes, viewportSize, newSize);
 
+    bool scaleCommitNotified = false;
+
     if (!qFuzzyCompare(minimumScale, attributes.minimumScale)) {
         interactionEngine->setCSSScaleBounds(minimumScale, attributes.maximumScale);
         emit q->experimental()->test()->viewportChanged();
 
-        if (!interactionEngine->hadUserInteraction() && !pageIsSuspended)
+        if (!interactionEngine->hadUserInteraction() && !pageIsSuspended) {
+            // Emits contentsScaleCommitted();
+            scaleCommitNotified = true;
             interactionEngine->setCSSScale(minimumScale);
+        }
     }
+
+    // Emit for testing purposes, so that it can be verified that
+    // we didn't do scale adjustment.
+    if (!scaleCommitNotified)
+        emit q->experimental()->test()->contentsScaleCommitted();
 }
 
+
 /*!
     \qmlsignal WebView::onNavigationRequested(WebNavigationRequest request)
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp (117941 => 117942)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp	2012-05-22 10:15:16 UTC (rev 117941)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp	2012-05-22 10:45:24 UTC (rev 117942)
@@ -38,8 +38,21 @@
 {
 }
 
-bool QWebKitTest::touchDoubleTap(QObject* item, qreal x, qreal y, int delay)
+static QTouchEvent::TouchPoint touchPoint(qreal x, qreal y)
 {
+    QPointF localPos(x, y);
+
+    QTouchEvent::TouchPoint point;
+    point.setLastPos(localPos);
+    QRectF touchRect(0, 0, 40, 40);
+    touchRect.moveCenter(localPos);
+    point.setRect(touchRect);
+
+    return point;
+}
+
+bool QWebKitTest::touchTap(QObject* item, qreal x, qreal y, int delay)
+{
     if (!qobject_cast<QQuickWebView*>(item)) {
         // FIXME: We only support the actual web view for now.
         qWarning("Touch event \"DoubleTap\" not accepted by receiving item");
@@ -48,17 +61,24 @@
 
     // FIXME: implement delay using QTest::qWait() or similar.
     Q_UNUSED(delay);
+    m_webViewPrivate->pageView->eventHandler()->handleSingleTapEvent(touchPoint(x, y));
 
-    QPointF localPos(x, y);
+    return true;
+}
 
-    QTouchEvent::TouchPoint point;
-    point.setLastPos(localPos);
-    QRectF touchRect(0, 0, 40, 40);
-    touchRect.moveCenter(localPos);
-    point.setRect(touchRect);
+bool QWebKitTest::touchDoubleTap(QObject* item, qreal x, qreal y, int delay)
+{
+    if (!qobject_cast<QQuickWebView*>(item)) {
+        // FIXME: We only support the actual web view for now.
+        qWarning("Touch event \"DoubleTap\" not accepted by receiving item");
+        return false;
+    }
 
-    m_webViewPrivate->pageView->eventHandler()->handleDoubleTapEvent(point);
+    // FIXME: implement delay using QTest::qWait() or similar.
+    Q_UNUSED(delay);
 
+    m_webViewPrivate->pageView->eventHandler()->handleDoubleTapEvent(touchPoint(x, y));
+
     return true;
 }
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h (117941 => 117942)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h	2012-05-22 10:15:16 UTC (rev 117941)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h	2012-05-22 10:45:24 UTC (rev 117942)
@@ -53,6 +53,7 @@
     void viewportChanged();
 
 public slots:
+    bool touchTap(QObject* item, qreal x, qreal y, int delay = -1);
     bool touchDoubleTap(QObject* item, qreal x, qreal y, int delay = -1);
 
 public:

Added: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml (0 => 117942)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml	2012-05-22 10:45:24 UTC (rev 117942)
@@ -0,0 +1,99 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit 3.0
+import QtWebKit.experimental 1.0
+import Test 1.0
+import "../common"
+
+Item {
+    TestWebView {
+        id: webView
+        width: 480
+        height: 720
+
+        property variant result
+
+        experimental.test.onContentsScaleCommitted: scaleChanged()
+
+        property variant content: "data:text/html," +
+            "<head>" +
+            "    <meta name='viewport' content='width=device-width'>" +
+            "</head>" +
+            "<body style='margin: 0px'>" +
+            "    <div id='target' style='display:none; width:960px; height:1440px;'></div>" +
+            "</body>"
+
+        signal resultReceived
+        signal scaleChanged
+    }
+
+    SignalSpy {
+        id: resultSpy
+        target: webView
+        signalName: "resultReceived"
+    }
+
+    SignalSpy {
+        id: scaleSpy
+        target: webView
+        signalName: "scaleChanged"
+    }
+
+    TestCase {
+        name: "FitToView"
+
+        property variant test: webView.experimental.test
+
+        function init() {
+            resultSpy.clear()
+            scaleSpy.clear()
+        }
+
+        function run(signalSpy, script) {
+            signalSpy.clear();
+            var result;
+             webView.experimental.evaluateJavaScript(
+                script, function(value) { webView.resultReceived(); result = value });
+            signalSpy.wait();
+            return result;
+        }
+
+        function documentSize() {
+            return run(resultSpy, "document.width + 'x' + document.height");
+        }
+
+        function setDisplay(id, value) {
+            // When changing to/from 'none' to 'block', this will result in a
+            // contentsScaleCommitted scale, even if it results in  the same
+            // scale, making it possible to check whether user interaction
+            // blocks fit-to-view or not.
+            run(scaleSpy, "document.getElementById('" + id + "').style.display = '" + value + "';");
+        }
+
+        function test_basic() {
+            webView.url = ""
+            verify(webView.waitForLoadSucceeded())
+
+            compare(documentSize(), "480x720")
+            compare(test.contentsScale, 1.0)
+
+            setDisplay("target", "block")
+            compare(documentSize(), "960x1440")
+            compare(test.contentsScale, 0.5)
+
+            // Add user interaction.
+            test.touchTap(webView, 10, 10)
+
+            // We are no longer within valid bounds after this change
+            // so we have to change our scale back to 1.0.
+            setDisplay("target", "none")
+            compare(documentSize(), "480x720")
+            compare(test.contentsScale, 1.0)
+
+            // We had user interaction, size should change but not scale.
+            setDisplay("target", "block")
+            compare(documentSize(), "960x1440")
+            compare(test.contentsScale, 1.0)
+        }
+    }
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to