@@ -33,6 +33,10 @@ Rectangle {
3333 "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.invalid" }
3434 }
3535
36+ property var jsonPurchaseCancel: {
37+ "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.cancel" }
38+ }
39+
3640 SignalSpy {
3741 id: spy
3842 target: previewPayments
@@ -160,5 +164,40 @@ Rectangle {
160164 compare(args[1], "purchaseError");
161165 compare(args[2], jsonPurchaseError["source"]);
162166 }
167+
168+ function test_purchase_cancelled() {
169+ // The mock Payments triggers cancellation when com.example.cancel
170+ // is passed to it as store_item_id. Exercise it here
171+ previewPayments.widgetData = jsonPurchaseCancel;
172+
173+ var button = findChild(previewPayments, "paymentButton");
174+ var progress = findChild(previewPayments, "loadingBar");
175+ verify(button, "Button not found.");
176+ verify(progress, "Progress not found.");
177+
178+ mouseClick(button, button.width / 2, button.height / 2);
179+
180+ tryCompare(progress, "visible", true);
181+ tryCompare(progress, "opacity", 1);
182+ tryCompare(button, "visible", false);
183+ tryCompare(button, "opacity", 0);
184+
185+ paymentClient.process();
186+
187+ // Signal is not used at the moment, to avoid preview refresh.
188+ /*
189+ *spy.wait();
190+ *
191+ * var args = spy.signalArguments[0];
192+ * compare(args[0], "previewPayments");
193+ * compare(args[1], "purchaseCancelled");
194+ * compare(args[2], jsonPurchaseCancel["source"]);
195+ */
196+
197+ tryCompare(progress, "visible", false);
198+ tryCompare(progress, "opacity", 0);
199+ tryCompare(button, "visible", true);
200+ tryCompare(button, "opacity", 1);
201+ }
163202 }
164203}