@@ -33,6 +33,10 @@ Rectangle {
33 "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.invalid" }
33 "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.invalid" }
36+ property var jsonPurchaseCancel: {
37+ "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.cancel" }
36 SignalSpy {
40 SignalSpy {
38 target: previewPayments
42 target: previewPayments
@@ -160,5 +164,36 @@ Rectangle {
160 compare(args[1], "purchaseError");
164 compare(args[1], "purchaseError");
161 compare(args[2], jsonPurchaseError["source"]);
165 compare(args[2], jsonPurchaseError["source"]);
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;
173+ var button = findChild(previewPayments, "paymentButton");
174+ var progress = findChild(previewPayments, "loadingBar");
175+ verify(button, "Button not found.");
176+ verify(progress, "Progress not found.");
178+ mouseClick(button, button.width / 2, button.height / 2);
180+ tryCompare(progress, "visible", true);
181+ tryCompare(progress, "opacity", 1);
182+ tryCompare(button, "visible", false);
183+ tryCompare(button, "opacity", 0);
185+ paymentClient.process();
188+ var args = spy.signalArguments[0];
189+ compare(args[0], "previewPayments");
190+ compare(args[1], "purchaseCancelled");
191+ compare(args[2], jsonPurchaseCancel["source"]);
193+ tryCompare(progress, "visible", false);
194+ tryCompare(progress, "opacity", 0);
195+ tryCompare(button, "visible", true);
196+ tryCompare(button, "opacity", 1);