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