summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qmltests/data/tst_loadProgress.qml
blob: 2c06a02070faad35c2db87d2b51aadd17058e232 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

import QtQuick
import QtTest
import QtWebEngine

import Test.Shared as Shared

TestWebEngineView {
    id: webEngineView
    width: 400
    height: 300

    property var loadProgressArray: []

    onLoadProgressChanged: {
        loadProgressArray.push(webEngineView.loadProgress)
    }

    SignalSpy {
        id: spyProgress
        target: webEngineView
        signalName: "loadProgressChanged"
    }

    TestCase {
        name: "WebEngineViewLoadProgress"

        function test_loadProgress() {
            compare(webEngineView.loadProgress, 0)
            compare(spyProgress.count, 0)
            loadProgressArray = []

            verify(Shared.HttpServer.start())
            Shared.HttpServer.newRequest.connect(request => {
                wait(250) // just add delay to trigger some progress for every sub resource
            })
            webEngineView.url = Shared.HttpServer.url('/loadprogress/main.html')
            // Wait for the first loadProgressChanged signal, which have to be non-negative
            spyProgress.wait()
            compare(loadProgressArray[0], 0)
            verify(webEngineView.loadProgress >= 0)

            // Wait for the last loadProgressChanged signal, which have to be 100%
            verify(webEngineView.waitForLoadSucceeded())
            spyProgress.wait()
            compare(loadProgressArray[loadProgressArray.length - 1], 100)
            compare(webEngineView.loadProgress, 100)

            // Test whether the chromium emits progress numbers in strict monotonic ascending order
            let progress = 0
            for (let i = 1; i < loadProgressArray.length; ++i) {
                let nextProgress = loadProgressArray[i]
                if (nextProgress <= progress)
                    fail("Invalid sequence of progress-values: " + loadProgressArray)
                progress = nextProgress
            }
        }
    }
}