OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachus etts Institute of Technology, ERCIM, Keio University, Beihang). --> | |
3 <meta charset="utf-8"> | |
4 <title>Test for PaymentRequest Constructor</title> | |
5 <script src="../resources/testharness.js"></script> | |
Marijn Kruisselbrink
2017/05/03 18:26:51
This should just be /resources/testharness.js
please use gerrit instead
2017/05/03 19:30:23
Done.
| |
6 <script src="../../../resources/testharnessreport.js"></script> | |
Marijn Kruisselbrink
2017/05/03 18:26:51
same here, /resources/testharnessreport.js
please use gerrit instead
2017/05/03 19:30:23
Done.
| |
7 <!-- https://w3c.github.io/browser-payment-api/#constructor --> | |
8 <script> | |
9 test(() => { | |
10 assert_equals((new PaymentRequest([{supportedMethods: ['basic-card']}], {id: ' foo', total: {label: '', amount: {currency: 'USD', value: '1.00'}}})).id, 'foo') ; | |
11 }); | |
Marijn Kruisselbrink
2017/05/03 18:26:51
Could you give every test() a name? The auto-gener
please use gerrit instead
2017/05/03 19:30:23
Done.
| |
12 | |
13 test(() => { | |
14 assert_throws({name: 'TypeError'}, | |
15 () => { | |
16 new PaymentRequest([], {total: {label: '', amount: {currency: 'USD', value : '1.00'}}}); | |
17 }, 'If the length of the methodData sequence is zero, then throw a TypeError '); | |
18 }); | |
19 | |
20 test(() => { | |
21 assert_throws({name: 'TypeError'}, | |
22 () => { | |
23 new PaymentRequest([{supportedMethods: []}], {total: {label: '', amount: { currency: 'USD', value: '1.00'}}}); | |
24 }, 'If the length of the paymentMethod.supportedMethods sequence is zero, th en throw a TypeError'); | |
25 }); | |
26 | |
27 const invalid_monetary_amounts = ['-', 'notdigits', 'ALSONOTDIGITS', '10.', '.99 ', '-10.', '-.99', '10-', '1-0', '1.0.0', '1/3', '', null]; | |
28 for (var i in invalid_monetary_amounts) { | |
Marijn Kruisselbrink
2017/05/03 18:26:51
for...in should generally never be used for arrays
please use gerrit instead
2017/05/03 19:30:23
Done.
| |
29 test(() => { | |
30 assert_throws({name: 'TypeError'}, | |
31 () => { | |
32 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: '', amount: {currency: 'USD', value: invalid_monetary_amounts[i]}}}); | |
33 }, 'If details.total.amount.value is not a valid decimal monetary value (i n this case "' + invalid_monetary_amounts[i] + '"), then throw a TypeError'); | |
34 }); | |
35 } | |
36 | |
37 test(() => { | |
38 assert_throws({name: 'TypeError'}, | |
39 () => { | |
40 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: | |
41 '', amount: {currency: 'USD', value: '-1.00'}}}); | |
42 }, 'If the first character of details.total.amount.value is U+002D HYPHEN-MI NUS, then throw a TypeError'); | |
43 }); | |
44 | |
45 for (var i in invalid_monetary_amounts) { | |
46 test(() => { | |
47 assert_throws({name: 'TypeError'}, | |
48 () => { | |
49 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: '', amount: {currency: 'USD', value: '1.00'}}, displayItems: [{label: '', amoun t: {currency: 'USD', value: invalid_monetary_amounts[i]}}]}); | |
50 }, 'For each item in details.displayItems: if item.amount.value is not a v alid decimal monetary value (in this case "' + invalid_monetary_amounts[i] + '") , then throw a TypeError'); | |
51 }); | |
52 } | |
53 | |
54 test(() => { | |
55 assert_throws({name: 'TypeError'}, | |
56 () => { | |
57 new PaymentRequest([{supportedMethods: ['basic-card']}], {}); | |
58 }, 'Total is required'); | |
59 }); | |
60 | |
61 test(() => { | |
62 assert_throws({name: 'TypeError'}, | |
63 () => { | |
64 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {amount: {currency: 'USD', value: '1.00'}}}); | |
65 }, 'Label is required'); | |
66 }); | |
67 | |
68 test(() => { | |
69 assert_throws({name: 'TypeError'}, | |
70 () => { | |
71 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: ' '}}); | |
72 }, 'Amount is required'); | |
73 }); | |
74 | |
75 test(() => { | |
76 assert_throws({name: 'TypeError'}, | |
77 () => { | |
78 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: ' ', amount: {currency: 'USD'}}}); | |
79 }, 'Amount value is required'); | |
80 }); | |
81 | |
82 test(() => { | |
83 assert_throws({name: 'TypeError'}, | |
84 () => { | |
85 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: ' ', amount: {value: '1.00'}}}); | |
86 }, 'Amount currency is required'); | |
87 }); | |
88 | |
89 test(() => { | |
90 assert_throws({name: 'TypeError'}, | |
91 () => { | |
92 new PaymentRequest([{supportedMethods: ['basic-card']}], {total: {label: ' ', amount: {currency: 'USD', value: '1.00'}}}, {shippingType: 'invalid'}); | |
93 }, 'Shipping type should be valid'); | |
94 }); | |
95 </script> | |
OLD | NEW |