onmerchantvalidation-attribute.https.html (2754B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Test for PaymentRequest's onmerchantvalidation attribute</title> 4 <link rel="help" href="https://w3c.github.io/browser-payment-api/#dom-paymentrequest-onmerchantvalidation"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script> 8 "use strict"; 9 const testMethod = Object.freeze({ supportedMethods: "not-a-real-method" }); 10 const applePay = Object.freeze({ 11 supportedMethods: "https://apple.com/apple-pay", 12 data: { 13 version: 3, 14 merchantIdentifier: "merchant.com.example", 15 countryCode: "US", 16 merchantCapabilities: ["supports3DS"], 17 supportedNetworks: ["visa"], 18 }, 19 }); 20 const defaultMethods = Object.freeze([testMethod, applePay]); 21 const defaultDetails = Object.freeze({ 22 total: { 23 label: "Total", 24 amount: { 25 currency: "USD", 26 value: "1.00", 27 }, 28 }, 29 }); 30 const validationURL = "https://example.com"; 31 32 test(() => { 33 const request = new PaymentRequest(defaultMethods, defaultDetails); 34 assert_idl_attribute(request, "onmerchantvalidation"); 35 }, "Must have a onmerchantvalidation IDL attribute"); 36 37 test(() => { 38 const request = new PaymentRequest(defaultMethods, defaultDetails); 39 const ev = new Event("merchantvalidation"); 40 let didHandle = false; 41 request.onmerchantvalidation = evt => { 42 assert_equals(ev, evt, "must be same event"); 43 didHandle = true; 44 }; 45 request.dispatchEvent(ev); 46 assert_true(didHandle, "event did not fire"); 47 }, `onmerchantvalidation attribute is a generic handler for "merchantvalidation"`); 48 49 test(() => { 50 const request = new PaymentRequest(defaultMethods, defaultDetails); 51 const ev = new MerchantValidationEvent("merchantvalidation", { validationURL }); 52 let didHandle = false; 53 request.onmerchantvalidation = evt => { 54 assert_equals(ev, evt, "must be same event"); 55 didHandle = true; 56 }; 57 request.dispatchEvent(ev); 58 assert_true(didHandle, "event did not fire"); 59 }, `onmerchantvalidation attribute is a handler for MerchantValidationEvent`); 60 61 test(() => { 62 const request = new PaymentRequest(defaultMethods, defaultDetails); 63 const ev = new MerchantValidationEvent("merchantvalidation", { validationURL }); 64 let didHandle = false; 65 let didListen = false; 66 request.onmerchantvalidation = evt => { 67 assert_equals(ev, evt, "must be same event"); 68 didHandle = true; 69 }; 70 request.addEventListener("merchantvalidation", evt => { 71 assert_equals(ev, evt, "must be same event"); 72 didListen = true; 73 }); 74 request.dispatchEvent(ev); 75 assert_true(didHandle, "onmerchantvalidation must receive the event"); 76 assert_true(didListen, "addEventListener must receive the event"); 77 }, `onmerchantvalidation attribute and listeners both work`); 78 </script>