constructor.https.html (6317B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <meta name="timeout" content="long"> 4 <title>Test for the 'secure-payment-confirmation' payment method constructor</title> 5 <link rel="help" href="https://w3c.github.io/secure-payment-confirmation/#sctn-payment-method-spc"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script> 9 'use strict'; 10 11 const details = {total: 12 {label: 'Total', amount: {value: '0.01', currency: 'USD'}}}; 13 14 // This file contains general tests for constructing a Secure Payment 15 // Confirmation payment request, that are not parts of the 'steps to validate 16 // payment method data'. For those, see constructor-validate-payment-method-data.https.html 17 18 test(() => { 19 new PaymentRequest([{ 20 supportedMethods: 'secure-payment-confirmation', 21 data: { 22 // All valid parameters. 23 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 24 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 25 payeeOrigin: window.location.origin, 26 timeout: 60000, 27 instrument: { 28 displayName: 'X', 29 icon: 'https://example.test/icon.png', 30 }, 31 rpId: 'relying-party.example', 32 }, 33 }], details); 34 }, 'Valid payment method data does not throw exceptions.'); 35 36 test(() => { 37 new PaymentRequest([{ 38 supportedMethods: 'secure-payment-confirmation', 39 data: { 40 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 41 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 42 payeeOrigin: window.location.origin, 43 // Omitted timeout field. 44 instrument: { 45 displayName: 'X', 46 icon: 'https://example.test/icon.png', 47 }, 48 rpId: 'relying-party.example', 49 }, 50 }], details); 51 }, 'The timeout field is optional.'); 52 53 test(() => { 54 assert_throws_js(RangeError, () => { 55 new PaymentRequest([{ 56 supportedMethods: 'secure-payment-confirmation', 57 data: { 58 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 59 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 60 payeeOrigin: window.location.origin, 61 timeout: 60000, 62 instrument: { 63 displayName: 'X', 64 icon: 'https://example.test/icon.png', 65 }, 66 rpId: 'relying-party.example', 67 }, 68 }, {supportedMethods: 'https://example.com/pay'}], details); 69 }); 70 }, 'Extra payment method not allowed afterward.'); 71 72 test(() => { 73 assert_throws_js(RangeError, () => { 74 new PaymentRequest([{supportedMethods: 'https://example.com/pay'}, { 75 supportedMethods: 'secure-payment-confirmation', 76 data: { 77 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 78 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 79 payeeOrigin: window.location.origin, 80 timeout: 60000, 81 instrument: { 82 displayName: 'X', 83 icon: 'https://example.test/icon.png', 84 }, 85 rpId: 'relying-party.example', 86 }, 87 }], details); 88 }); 89 }, 'Extra payment method not allowed beforehand.'); 90 91 test(() => { 92 assert_throws_js(TypeError, () => { 93 new PaymentRequest([{ 94 supportedMethods: 'secure-payment-confirmation', 95 data: { 96 // Omitted credentialIds field. 97 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 98 payeeOrigin: window.location.origin, 99 timeout: 60000, 100 instrument: { 101 displayName: 'X', 102 icon: 'https://example.test/icon.png', 103 }, 104 rpId: 'relying-party.example', 105 }, 106 }], details); 107 }); 108 }, 'The credentialIds field is required.'); 109 110 test(() => { 111 assert_throws_js(TypeError, () => { 112 new PaymentRequest([{ 113 supportedMethods: 'secure-payment-confirmation', 114 data: { 115 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 116 // Omitted challenge field. 117 payeeOrigin: window.location.origin, 118 timeout: 60000, 119 instrument: { 120 displayName: 'X', 121 icon: 'https://example.test/icon.png', 122 }, 123 rpId: 'relying-party.example', 124 }, 125 }], details); 126 }); 127 }, 'The challenge field is required.'); 128 129 test(() => { 130 assert_throws_js(TypeError, () => { 131 new PaymentRequest([{ 132 supportedMethods: 'secure-payment-confirmation', 133 data: { 134 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 135 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 136 payeeOrigin: window.location.origin, 137 timeout: 60000, 138 rpId: 'relying-party.example', 139 // Omitted instrument field. 140 }, 141 }], details); 142 }); 143 }, 'Instrument field is required.'); 144 145 test(() => { 146 assert_throws_js(TypeError, () => { 147 new PaymentRequest([{ 148 supportedMethods: 'secure-payment-confirmation', 149 data: { 150 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 151 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 152 payeeOrigin: window.location.origin, 153 timeout: 60000, 154 instrument: { 155 // Ommitted instrument display name. 156 icon: 'https://example.test/icon.png', 157 }, 158 rpId: 'relying-party.example', 159 }, 160 }], details); 161 }); 162 }, 'Instrument display name is required.'); 163 164 test(() => { 165 assert_throws_js(TypeError, () => { 166 new PaymentRequest([{ 167 supportedMethods: 'secure-payment-confirmation', 168 data: { 169 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 170 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 171 payeeOrigin: window.location.origin, 172 timeout: 60000, 173 instrument: { 174 displayName: 'X', 175 // Ommitted instrument icon. 176 }, 177 rpId: 'relying-party.example', 178 }, 179 }], details); 180 }); 181 }, 'Instrument icon is required.'); 182 183 test(() => { 184 assert_throws_js(TypeError, () => { 185 new PaymentRequest([{ 186 supportedMethods: 'secure-payment-confirmation', 187 data: { 188 credentialIds: [Uint8Array.from('x', c => c.charCodeAt(0))], 189 challenge: Uint8Array.from('x', c => c.charCodeAt(0)), 190 payeeOrigin: window.location.origin, 191 timeout: 60000, 192 instrument: { 193 displayName: 'X', 194 icon: 'https://example.test/icon.png', 195 }, 196 // Omitted rpId. 197 }, 198 }], details); 199 }); 200 }, 'rpId is required.'); 201 </script>