aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquick2/qquickcanvasitem/data/tst_context.qml
blob: b72e755ed9e795bf5342c6208c27256ae1b965bd (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
62
63
64
65
66
67
68
69
70
71
72
73

import QtQuick 2.0
import QtTest 1.0

Canvas {
    id: canvas
    width: 1
    height: 1
    contextType: "2d"

    property var contextInPaint

    SignalSpy {
        id: paintedSpy
        target: canvas
        signalName: "paint"
    }

    SignalSpy {
        id: contextSpy
        target: canvas
        signalName: "contextChanged"
    }

    onPaint: {
        contextInPaint = context;
    }

    TestCase {
        name: "ContextTypeStored"
        when: windowShown

        function test_contextType() {
            compare(canvas.contextType, "2d");
        }
    }

    TestCase {
        name: "ContextValidWhenTypePredefined"
        when: canvas.available

        function test_context() {
            // Wait for the context to become active
            wait(100);
            compare(contextSpy.count, 1);

            // Context is available
            verify(canvas.context)
        }

        function test_contextIsConsistent() {
            // Wait for the context to become active
            wait(100);
            compare(contextSpy.count, 1);

            // getContext("2d") is the same as the context property
            compare(canvas.getContext("2d"), canvas.context);
        }

        function test_paintHadContext() {
            // Make there was a paint signal
            wait(100);
            verify(paintedSpy.count, 1)

            // Paint was called with a valid context when contextType is
            // specified
            verify(canvas.contextInPaint)

            // paints context was the correct one
            compare(canvas.contextInPaint, canvas.getContext("2d"));
        }
   }
}