Title: [102959] trunk/Source/WebKit2
Revision
102959
Author
[email protected]
Date
2011-12-15 10:39:51 -0800 (Thu, 15 Dec 2011)

Log Message

[Qt][WK2] Add test for download policy on navigation request
https://bugs.webkit.org/show_bug.cgi?id=74541

Patch by Rafael Brandao <[email protected]> on 2011-12-15
Reviewed by Tor Arne Vestbø.

* UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml:
* UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml: Make it wait for a
downloadFinished signal to finish the test.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (102958 => 102959)


--- trunk/Source/WebKit2/ChangeLog	2011-12-15 18:28:29 UTC (rev 102958)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-15 18:39:51 UTC (rev 102959)
@@ -1,3 +1,14 @@
+2011-12-15  Rafael Brandao  <[email protected]>
+
+        [Qt][WK2] Add test for download policy on navigation request
+        https://bugs.webkit.org/show_bug.cgi?id=74541
+
+        Reviewed by Tor Arne Vestbø.
+
+        * UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml:
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml: Make it wait for a
+        downloadFinished signal to finish the test.
+
 2011-12-15  Anders Carlsson  <[email protected]>
 
         Move WorkQueue Mach handlers over to WTF::Function

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml (102958 => 102959)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml	2011-12-15 18:28:29 UTC (rev 102958)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml	2011-12-15 18:39:51 UTC (rev 102959)
@@ -3,16 +3,41 @@
 import QtWebKit 3.0
 
 Item {
+    property int expectedLength: 0
+    property int totalBytes: 0
+    property bool shouldDownload: false
+
     DesktopWebView {
         id: webView
         width: 200
         height: 200
+
+        signal downloadFinished()
+
         onNavigationRequested: {
-            if (request.button == Qt.MiddleButton && request.modifiers & Qt.ControlModifier) {
+            if (shouldDownload)
+                request.action = ""
+            else if (request.button == Qt.MiddleButton && request.modifiers & Qt.ControlModifier) {
                 otherWebView.load(request.url)
                 request.action = ""
             }
         }
+
+        experimental.onDownloadRequested: {
+            download.target = downloadItem
+            expectedLength = downloadItem.expectedContentLength
+            downloadItem.destinationPath = downloadItem.suggestedFilename
+            downloadItem.start()
+        }
+
+        Connections {
+            id: download
+            ignoreUnknownSignals: true
+            onSucceeded: {
+                totalBytes = download.target.totalBytesReceived
+                webView.downloadFinished()
+            }
+        }
     }
 
     SignalSpy {
@@ -31,6 +56,18 @@
         signalName: "loadSucceeded"
     }
 
+    SignalSpy {
+        id: downloadSpy
+        target: webView.experimental
+        signalName: "downloadRequested"
+    }
+
+    SignalSpy {
+        id: downloadFinishedSpy
+        target: webView
+        signalName: "downloadFinished"
+    }
+
     TestCase {
         name: "DesktopWebViewNavigationRequested"
 
@@ -43,6 +80,14 @@
             onTriggered: parent.when = true
         }
 
+        function init() {
+            spy.clear()
+            otherSpy.clear()
+            downloadSpy.clear()
+            downloadFinishedSpy.clear()
+            shouldDownload = false
+        }
+
         function test_usePolicy() {
             webView.load(Qt.resolvedUrl("../common/test2.html"))
             spy.wait()
@@ -65,5 +110,22 @@
             compare(otherSpy.count, 1)
             compare(otherWebView.title, "Test page 1")
         }
+
+        function test_downloadPolicy() {
+            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            spy.wait()
+            spy.clear()
+            compare(spy.count, 0)
+            downloadSpy.clear()
+            downloadFinishedSpy.clear()
+            expectedLength = 0
+            shouldDownload = true
+            mouseClick(webView, 100, 100, Qt.LeftButton)
+            downloadSpy.wait()
+            compare(downloadSpy.count, 1)
+            downloadFinishedSpy.wait()
+            compare(downloadFinishedSpy.count, 1)
+            compare(totalBytes, expectedLength)
+        }
     }
 }

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml (102958 => 102959)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml	2011-12-15 18:28:29 UTC (rev 102958)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml	2011-12-15 18:39:51 UTC (rev 102959)
@@ -9,15 +9,22 @@
     height: 200
 
     property int expectedLength: 0
-    property bool downloadFinished: false
     property int totalBytes: 0
 
+    signal downloadFinished()
+
     SignalSpy {
         id: spy
         target: experimental
         signalName: "downloadRequested"
     }
 
+    SignalSpy {
+        id: downloadFinishedSpy
+        target: webView
+        signalName: "downloadFinished"
+    }
+
     experimental.onDownloadRequested: {
         download.target = downloadItem
         expectedLength = downloadItem.expectedContentLength
@@ -29,8 +36,8 @@
         id: download
         ignoreUnknownSignals: true
         onSucceeded: {
-            downloadFinished = true
             totalBytes = download.target.totalBytesReceived
+            webView.downloadFinished()
         }
     }
 
@@ -48,8 +55,8 @@
 
         function init() {
             spy.clear()
+            downloadFinishedSpy.clear()
             expectedLength = 0
-            downloadFinished = false
         }
 
         function test_downloadRequest() {
@@ -72,7 +79,7 @@
             webView.load(Qt.resolvedUrl("../common/download.zip"))
             spy.wait()
             compare(spy.count, 1)
-            verify(downloadFinished)
+            downloadFinishedSpy.wait()
             compare(totalBytes, expectedLength)
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to