test_abortPayment.html (2619B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1345367 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1345367</title> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <script type="application/javascript"> 12 13 "use strict"; 14 SimpleTest.waitForExplicitFinish(); 15 16 var gUrl = SimpleTest.getTestFileURL('GeneralChromeScript.js'); 17 var gScript = SpecialPowers.loadChromeScript(gUrl); 18 19 const defaultMethods = [{ 20 supportedMethods: "basic-card", 21 }]; 22 const defaultDetails = { 23 total: { 24 label: "Total", 25 amount: { 26 currency: "USD", 27 value: "1.00" 28 } 29 }, 30 }; 31 32 function testBeforeShow() { 33 return new Promise((resolve, reject) => { 34 const payRequest = new PaymentRequest(defaultMethods, defaultDetails); 35 payRequest.abort().then((result) => { 36 ok(false, "Should throw 'InvalidStateError', but got resolved."); 37 resolve(); 38 }).catch((err) => { 39 is(err.name, "InvalidStateError", 40 "Expected 'InvalidStateError', but got '" + err.name + "'"); 41 resolve(); 42 }); 43 }); 44 } 45 46 function testAfterShow() { 47 const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); 48 49 return new Promise((resolve, reject) => { 50 const payRequest = new PaymentRequest(defaultMethods, defaultDetails); 51 const acceptPromise = payRequest.show(); 52 payRequest.abort().then((abortResult) => { 53 is(abortResult, undefined, "Should be resolved with undefined."); 54 resolve(); 55 }).catch( (err) => { 56 ok(false, "Expected no error, but got '" + err.name + "'."); 57 resolve(); 58 }).finally(handler.destruct); 59 }); 60 } 61 62 function teardown() { 63 gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() { 64 gScript.removeMessageListener("teardown-complete", teardownCompleteHandler); 65 gScript.destroy(); 66 SimpleTest.finish(); 67 }); 68 gScript.sendAsyncMessage("teardown"); 69 } 70 71 function runTests() { 72 testBeforeShow() 73 .then(testAfterShow) 74 .then(teardown) 75 .catch( e => { 76 ok(false, "Unexpected error: " + e.name); 77 SimpleTest.finish(); 78 }); 79 } 80 81 window.addEventListener('load', function() { 82 SpecialPowers.pushPrefEnv({ 83 'set': [ 84 ['dom.payments.request.enabled', true], 85 ] 86 }, runTests); 87 }); 88 89 </script> 90 </head> 91 <body> 92 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1345367">Mozilla Bug 1345367</a> 93 </pre> 94 </body> 95 </html>