Binding CodeGenerators don't support Conditional= on constants
[WebKit.git] / Source / WebKit2 / UIProcess / API / qt / tests / qmltests / WebView / tst_download.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import QtWebKit 3.0
4 import QtWebKit.experimental 3.0
5
6 WebView {
7     id: webView
8     width: 200
9     height: 200
10
11     property int expectedLength: 0
12     property bool downloadFinished: false
13     property int totalBytes: 0
14
15     SignalSpy {
16         id: spy
17         target: experimental
18         signalName: "downloadRequested"
19     }
20
21     experimental.onDownloadRequested: {
22         download.target = downloadItem
23         expectedLength = downloadItem.expectedContentLength
24         downloadItem.destinationPath = downloadItem.suggestedFilename
25         downloadItem.start()
26     }
27
28     Connections {
29         id: download
30         ignoreUnknownSignals: true
31         onSucceeded: {
32             downloadFinished = true
33             totalBytes = download.target.totalBytesReceived
34         }
35     }
36
37     TestCase {
38         name: "WebViewDownload"
39
40         // Delayed windowShown to workaround problems with Qt5 in debug mode.
41         when: false
42         Timer {
43             running: parent.windowShown
44             repeat: false
45             interval: 1
46             onTriggered: parent.when = true
47         }
48
49         function init() {
50             spy.clear()
51             expectedLength = 0
52             downloadFinished = false
53         }
54
55         function test_downloadRequest() {
56             compare(spy.count, 0)
57             webView.load(Qt.resolvedUrl("../common/download.zip"))
58             spy.wait()
59             compare(spy.count, 1)
60         }
61
62         function test_expectedLength() {
63             compare(spy.count, 0)
64             webView.load(Qt.resolvedUrl("../common/download.zip"))
65             spy.wait()
66             compare(spy.count, 1)
67             compare(expectedLength, 325)
68         }
69
70         function test_succeeded() {
71             compare(spy.count, 0)
72             webView.load(Qt.resolvedUrl("../common/download.zip"))
73             spy.wait()
74             compare(spy.count, 1)
75             verify(downloadFinished)
76             compare(totalBytes, expectedLength)
77         }
78     }
79 }