QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickcanvasitem / data / tst_context.qml
1
2 import QtQuick 2.0
3 import QtTest 1.0
4
5 Canvas {
6     id: canvas
7     width: 1
8     height: 1
9     contextType: "2d"
10
11     property var contextInPaint
12
13     SignalSpy {
14         id: paintedSpy
15         target: canvas
16         signalName: "paint"
17     }
18
19     SignalSpy {
20         id: contextSpy
21         target: canvas
22         signalName: "contextChanged"
23     }
24
25     onPaint: {
26         contextInPaint = context;
27     }
28
29     TestCase {
30         name: "ContextTypeStored"
31         when: windowShown
32
33         function test_contextType() {
34             compare(canvas.contextType, "2d");
35         }
36     }
37
38     TestCase {
39         name: "ContextValidWhenTypePredefined"
40         when: canvas.available
41
42         function test_context() {
43             // Wait for the context to become active
44             wait(100);
45             compare(contextSpy.count, 1);
46
47             // Context is available
48             verify(canvas.context)
49         }
50
51         function test_contextIsConsistent() {
52             // Wait for the context to become active
53             wait(100);
54             compare(contextSpy.count, 1);
55
56             // getContext("2d") is the same as the context property
57             compare(canvas.getContext("2d"), canvas.context);
58         }
59
60         function test_paintHadContext() {
61             // Make there was a paint signal
62             wait(100);
63             verify(paintedSpy.count, 1)
64
65             // Paint was called with a valid context when contextType is
66             // specified
67             verify(canvas.contextInPaint)
68
69             // paints context was the correct one
70             compare(canvas.contextInPaint, canvas.getContext("2d"));
71         }
72    }
73 }