@@ -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,36 @@ 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+ spy.wait();
187+
188+ var args = spy.signalArguments[0];
189+ compare(args[0], "previewPayments");
190+ compare(args[1], "purchaseCancelled");
191+ compare(args[2], jsonPurchaseCancel["source"]);
192+
193+ tryCompare(progress, "visible", false);
194+ tryCompare(progress, "opacity", 0);
195+ tryCompare(button, "visible", true);
196+ tryCompare(button, "opacity", 1);
197+ }
163198 }
164199}