summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/TestWebView.qml
blob: 5a05f9b3eab3460ddeca5d27663caee6d91cbac1 (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
import QtQuick 2.0
import QtTest 1.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0

WebView {
    property var loadStatus: null
    property var viewportReady: false

    function waitForLoadSucceeded() {
        var success = _waitFor(function() { return loadStatus == WebView.LoadSucceededStatus })
        loadStatus = null
        return success
    }
    function waitForViewportReady() {
        // Note: You need to have "when: windowShown" in your TestCase for this to work.
        // The viewport is locked until the first frame is rendered, and the rendering isn't
        // activated until the WebView is visible in a mapped QQuickView.
        return _waitFor(function() { return viewportReady })
    }
    function waitForLoadFailed() {
        var failure = _waitFor(function() { return loadStatus == WebView.LoadFailedStatus })
        loadStatus = null
        return failure
    }
    function waitForLoadStopped() {
        var stop = _waitFor(function() { return loadStatus == WebView.LoadStoppedStatus })
        loadStatus = null
        return stop
    }
    function _waitFor(predicate) {
        var timeout = 5000
        var i = 0
        while (i < timeout && !predicate()) {
            testResult.wait(50)
            i += 50
        }
        return predicate()
    }

    TestResult { id: testResult }

    experimental.onLoadVisuallyCommitted: viewportReady = true
    onLoadingChanged: {
        loadStatus = loadRequest.status
        if (loadRequest.status == WebView.LoadStartedStatus)
            viewportReady = false
    }

}