@@ -0,0 +1,145 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import "../../../qml/Components"
20+import Unity.Test 0.1 as UT
21+
22+Rectangle {
23+ id: root
24+ width: units.gu(40)
25+ height: units.gu(80)
26+ color: "lightgrey"
27+
28+ property var widgetData0: {
29+ "source": "",
30+ "zoomable": false
31+ }
32+
33+ property var widgetData1: {
34+ "source": "../../../qml/graphics/phone_background.jpg",
35+ "zoomable": false
36+ }
37+
38+ property var widgetData2: {
39+ "source": "../../../qml/Dash/graphics/phone/screenshots/gallery@12.png",
40+ "zoomable": true
41+ }
42+
43+ ZoomableImage {
44+ id: zoomableImage
45+ width: parent.width
46+ anchors.fill: parent
47+ }
48+
49+ SignalSpy {
50+ id: signalSpy
51+ }
52+
53+ UT.UnityTestCase {
54+ name: "ZoomableImageTest"
55+ when: windowShown
56+
57+ function test_loadImage() {
58+ var image = findChild(zoomableImage, "image");
59+
60+ zoomableImage.source = widgetData0["source"];
61+ zoomableImage.zoomable = widgetData0["zoomable"];
62+ waitForRendering(zoomableImage);
63+ tryCompare(image, "state", "default");
64+
65+ signalSpy.signalName = "onStateChanged";
66+ signalSpy.target = image;
67+ signalSpy.clear();
68+
69+ zoomableImage.source = widgetData1["source"];
70+ zoomableImage.zoomable = widgetData1["zoomable"];
71+ waitForRendering(zoomableImage);
72+ tryCompare(image, "state", "ready");
73+ compare (signalSpy.count, 2);
74+ }
75+
76+ function test_zoomable_data() {
77+ return [ { source:widgetData2["source"],
78+ zoomable:false,
79+ answer1: true,
80+ answer2: false,
81+ answer3: true },
82+ { source:widgetData2["source"],
83+ zoomable:true,
84+ answer1: false,
85+ answer2: true,
86+ answer3: false }
87+ ]
88+ }
89+
90+ function test_zoomable(data) {
91+ var image = findChild(zoomableImage, "image");
92+
93+ signalSpy.signalName = "onScaleChanged";
94+ signalSpy.target = image;
95+ signalSpy.clear();
96+
97+ zoomableImage.source = data.source;
98+ zoomableImage.zoomable = data.zoomable;
99+ waitForRendering(zoomableImage);
100+
101+ tryCompare(image, "state", "ready");
102+ waitForRendering(image);
103+
104+ var event1 = touchEvent();
105+ var event2 = touchEvent();
106+ var x1Start = zoomableImage.width * 2 / 6;
107+ var y1Start = zoomableImage.height * 2 / 6;
108+ var x1End = zoomableImage.width * 1 / 6;
109+ var y1End = zoomableImage.height * 1 / 6;
110+ var x2Start = zoomableImage.width * 4 / 6;
111+ var y2Start = zoomableImage.height * 4 / 6;
112+ var x2End = zoomableImage.width * 5 / 6;
113+ var y2End = zoomableImage.height * 5 / 6;
114+
115+ var oldScale = image.scale;
116+
117+ mouseMove(zoomableImage, zoomableImage.width / 2, zoomableImage.height / 2);
118+ mouseWheel(zoomableImage, zoomableImage.width / 2, zoomableImage.height / 2, 0, 10);
119+
120+ event1.press(0, x1Start, y1Start);
121+ event1.commit();
122+ event1.press(1, x2Start, y2Start);
123+ event1.commit();
124+
125+ for (var i = 0.0; i < 1.0; i += 0.02) {
126+ event1.move(0, x1Start + (x1End - x1Start) * i, y1Start + (y1End - y1Start) * i);
127+ event1.move(1, x2Start + (x2End - x2Start) * i, y2Start + (y2End - y2Start) * i);
128+ event1.commit();
129+ wait(30);
130+ }
131+
132+ event1.release(0, x1End, y1End);
133+ event1.commit();
134+ event1.release(1, x2End, y2End);
135+ event1.commit();
136+
137+ var newScale = image.scale;
138+
139+ compare(newScale == oldScale, data.answer1, "scale factor error");
140+ compare(newScale > oldScale, data.answer2, "scale factor error");
141+ compare(signalSpy.count == 0, data.answer3, "scale signal error");
142+ }
143+
144+ }
145+}