summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtquick2/qquickcanvasitem/data/tst_canvas.qml78
-rw-r--r--tests/auto/qtquick2/qquickcanvasitem/data/tst_context.qml73
-rw-r--r--tests/auto/qtquick2/qquickcanvasitem/data/tst_fillrect.qml17
-rw-r--r--tests/auto/qtquick2/qquickcanvasitem/qquickcanvasitem.pro3
4 files changed, 126 insertions, 45 deletions
diff --git a/tests/auto/qtquick2/qquickcanvasitem/data/tst_canvas.qml b/tests/auto/qtquick2/qquickcanvasitem/data/tst_canvas.qml
index 98ddab66b5..a00ccc3c3f 100644
--- a/tests/auto/qtquick2/qquickcanvasitem/data/tst_canvas.qml
+++ b/tests/auto/qtquick2/qquickcanvasitem/data/tst_canvas.qml
@@ -11,6 +11,7 @@ Rectangle {
id:c
width:100;height:100
onPaint: {
+ var context = getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 100, 100);
}
@@ -18,27 +19,31 @@ Rectangle {
property int paintedCount:spyPainted.count
property int canvasSizeChangedCount:spyCanvasSizeChanged.count
property int tileSizeChangedCount:spyTileSizeChanged.count
- property int renderInThreadChangedCount:spyRenderInThreadChanged.count
+ property int renderStrategyChangedCount:spyRenderStrategyChanged.count
property int canvasWindowChangedCount:spyCanvasWindowChanged.count
property int renderTargetChangedCount:spyRenderTargetChanged.count
property int imageLoadedCount:spyImageLoaded.count
+ property int availableChangedCount:spyAvailableChanged.count
SignalSpy {id: spyPaint;target:c;signalName: "paint"}
SignalSpy {id: spyPainted;target:c;signalName: "painted"}
SignalSpy {id: spyCanvasSizeChanged;target:c;signalName: "canvasSizeChanged"}
SignalSpy {id: spyTileSizeChanged;target:c;signalName: "tileSizeChanged"}
- SignalSpy {id: spyRenderInThreadChanged;target:c;signalName: "renderInThreadChanged"}
+ SignalSpy {id: spyRenderStrategyChanged;target:c;signalName: "renderStrategyChanged"}
SignalSpy {id: spyCanvasWindowChanged;target:c;signalName: "canvasWindowChanged"}
SignalSpy {id: spyRenderTargetChanged;target:c;signalName: "renderTargetChanged"}
SignalSpy {id: spyImageLoaded;target:c;signalName: "imageLoaded"}
+ SignalSpy {id: spyAvailableChanged;target:c;signalName: "availableChanged"}
}
}
TestCase {
name: "Canvas"; when: windowShown
function test_canvasSize() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
//by default canvasSize is same with canvas' actual size
// when canvas size changes, canvasSize should be changed as well.
@@ -74,8 +79,10 @@ Rectangle {
c.destroy();
}
function test_tileSize() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
compare(c.tileSize.width, c.width);
compare(c.tileSize.height, c.height);
@@ -109,8 +116,10 @@ Rectangle {
}
function test_canvasWindow() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
compare(c.canvasWindow.x, 0);
compare(c.canvasWindow.y, 0);
compare(c.canvasWindow.width, c.width);
@@ -135,34 +144,22 @@ Rectangle {
c.destroy();
}
- function test_renderTargetAndThread() {
- var c = canvas.createObject();
+ function test_renderTargetAndStrategy() {
+ var c = canvas.createObject(container);
verify(c);
-
- compare(c.renderTarget, Canvas.FramebufferObject);
- verify(!c.renderInThread);
- c.renderTarget = Canvas.Image;
- compare(c.renderTargetChangedCount, 1);
- compare(c.renderInThreadChangedCount, 0);
+ wait(100);
+ verify(c.availableChangedCount, 1);
compare(c.renderTarget, Canvas.Image);
- verify(!c.renderInThread);
- c.renderInThread = true;
- verify(c.renderInThread);
- compare(c.renderTargetChangedCount, 1);
- compare(c.renderInThreadChangedCount, 1);
-
- ignoreWarning("Canvas: render target does not support thread rendering, force to non-thread rendering mode.");
- c.renderTarget = Canvas.FramebufferObject;
- verify(!c.renderInThread);
- compare(c.renderTargetChangedCount, 2);
- compare(c.renderInThreadChangedCount, 2);
+ compare(c.renderStrategy, Canvas.Threaded);
c.destroy();
}
function test_save() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
c.renderTarget = Canvas.Image;
c.requestPaint();
@@ -188,16 +185,16 @@ Rectangle {
}
function test_toDataURL(data) {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
- c.renderTarget = Canvas.Image;
- var ctx = c.getContext();
+ var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(0, 0, c.width, c.height);
-
- c.requestPaint();
wait(100);
+
var dataUrl = c.toDataURL();
verify(dataUrl != "data:,");
dataUrl = c.toDataURL("image/invalid");
@@ -205,12 +202,13 @@ Rectangle {
dataUrl = c.toDataURL(data.mimeType);
verify(dataUrl != "data:,");
+
ctx.save();
ctx.fillStyle = "blue";
ctx.fillRect(0, 0, c.width, c.height);
ctx.restore();
- c.requestPaint();
wait(100);
+
var dataUrl2 = c.toDataURL(data.mimeType);
verify (dataUrl2 != "data:,");
verify (dataUrl2 != dataUrl);
@@ -218,12 +216,14 @@ Rectangle {
}
function test_paint() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
c.renderTarget = Canvas.Image;
- c.renderInThread = true;
- var ctx = c.getContext();
+ c.renderStrategy = Canvas.Immediate;
+ var ctx = c.getContext("2d");
ctx.fillRect(0, 0, c.width, c.height);
c.toDataURL();
wait(100);
@@ -234,8 +234,10 @@ Rectangle {
}
function test_loadImage() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
c.loadImage("red.png");
wait(200);
@@ -253,10 +255,12 @@ Rectangle {
}
function test_getContext() {
- var c = canvas.createObject();
+ var c = canvas.createObject(container);
verify(c);
+ wait(100);
+ verify(c.availableChangedCount, 1);
- var ctx = c.getContext();
+ var ctx = c.getContext("2d");
verify(ctx);
compare(ctx.canvas, c);
ctx = c.getContext('2d');
diff --git a/tests/auto/qtquick2/qquickcanvasitem/data/tst_context.qml b/tests/auto/qtquick2/qquickcanvasitem/data/tst_context.qml
new file mode 100644
index 0000000000..b72e755ed9
--- /dev/null
+++ b/tests/auto/qtquick2/qquickcanvasitem/data/tst_context.qml
@@ -0,0 +1,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"));
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquickcanvasitem/data/tst_fillrect.qml b/tests/auto/qtquick2/qquickcanvasitem/data/tst_fillrect.qml
index 2061647268..08197816e9 100644
--- a/tests/auto/qtquick2/qquickcanvasitem/data/tst_fillrect.qml
+++ b/tests/auto/qtquick2/qquickcanvasitem/data/tst_fillrect.qml
@@ -2,15 +2,18 @@ import QtQuick 2.0
import QtTest 1.0
Canvas {
- id:canvas; width:1;height:1; renderTarget:Canvas.Image
- onPaint: {
- context.fillStyle = "red";
- context.fillRect(0, 0, canvas.width, canvas.height);
- }
+ id:canvas; width:1;height:1;
+ renderTarget:Canvas.Image
+ renderStrategy: Canvas.Immediate
+
TestCase {
- name: "FillRect"; when: windowShown
+ name: "FillRect"; when: canvas.available
+
function test_fillRect() {
var ctx = canvas.getContext('2d');
+ ctx.fillStyle = "red";
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+
var imageData = ctx.getImageData(0, 0, 1, 1);
var d = imageData.data;
verify(d.length == 4);
@@ -20,4 +23,4 @@ Canvas {
verify(d[3] == 255);
}
}
-} \ No newline at end of file
+}
diff --git a/tests/auto/qtquick2/qquickcanvasitem/qquickcanvasitem.pro b/tests/auto/qtquick2/qquickcanvasitem/qquickcanvasitem.pro
index 141e477416..93539dab15 100644
--- a/tests/auto/qtquick2/qquickcanvasitem/qquickcanvasitem.pro
+++ b/tests/auto/qtquick2/qquickcanvasitem/qquickcanvasitem.pro
@@ -27,7 +27,8 @@ OTHER_FILES += \
data/tst_pixel.qml \
data/tst_gradient.qml \
data/tst_arcto.qml \
- data/tst_arc.qml
+ data/tst_arc.qml \
+ data/tst_context.qml