OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
3 <title>Tests for PaymentRequest interface</title> | 3 <title>Tests for PaymentRequest interface</title> |
4 <script src="../resources/testharness.js"></script> | 4 <script src="../resources/testharness.js"></script> |
5 <script src="../resources/testharnessreport.js"></script> | 5 <script src="../resources/testharnessreport.js"></script> |
6 <script> | 6 <script> |
7 function substitute(originalObject, substituteKeyValuePair) { | 7 function substitute(originalObject, substituteKeyValuePair) { |
8 for (var key in originalObject) { | 8 for (var key in originalObject) { |
9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePair.hasOwnP roperty(key)) { | 9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePair.hasOwnP roperty(key)) { |
10 originalObject[key] = substituteKeyValuePair[key]; | 10 originalObject[key] = substituteKeyValuePair[key]; |
(...skipping 21 matching lines...) Expand all Loading... | |
32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair) ]; | 32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair) ]; |
33 } else { | 33 } else { |
34 details[detailNames[i]] = [buildItem()]; | 34 details[detailNames[i]] = [buildItem()]; |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 return details; | 38 return details; |
39 } | 39 } |
40 | 40 |
41 test(function() { | 41 test(function() { |
42 new PaymentRequest(['foo'], buildDetails(), {}, {}); | 42 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), {}, {}); |
43 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ; | 43 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ; |
44 | 44 |
45 test(function() { | 45 test(function() { |
46 new PaymentRequest(['foo'], buildDetails(), {}, {}, ''); | 46 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), {}, {}, ''); |
47 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ; | 47 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ; |
48 | 48 |
49 test(function() { | 49 test(function() { |
50 new PaymentRequest(['foo'], buildDetails()); | 50 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails()); |
51 }, 'Creating a PaymentRequest with omitted optional parameters should not throw or crash.'); | 51 }, 'Creating a PaymentRequest with omitted optional parameters should not throw or crash.'); |
52 | 52 |
53 test(function() { | 53 test(function() { |
54 new PaymentRequest(['foo'], buildDetails(), undefined, undefined); | 54 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), undefine d, undefined); |
55 }, 'Creating a PaymentRequest with undefined optional parameters should not thro w or crash.'); | 55 }, 'Creating a PaymentRequest with undefined optional parameters should not thro w or crash.'); |
56 | 56 |
57 test(function() { | 57 test(function() { |
58 new PaymentRequest(['foo'], buildDetails(), null, null); | 58 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), null, nu ll); |
59 }, 'Creating a PaymentRequest with null optional parameters should not throw or crash.'); | 59 }, 'Creating a PaymentRequest with null optional parameters should not throw or crash.'); |
60 | 60 |
61 test(function() { | 61 test(function() { |
62 var request = new PaymentRequest(['foo'], buildDetails()); | 62 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls()); |
63 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re adonly shippingAddress property.'); | 63 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re adonly shippingAddress property.'); |
64 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea donly shippingOption property.'); | 64 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea donly shippingOption property.'); |
65 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.'); | 65 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.'); |
66 | 66 |
67 test(function() { | 67 test(function() { |
68 var request = new PaymentRequest(['foo'], buildDetails()); | 68 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls()); |
69 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques t should have onShippingAddressChange event.'); | 69 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques t should have onShippingAddressChange event.'); |
70 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest should have onShippingOptionChange event.'); | 70 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest should have onShippingOptionChange event.'); |
71 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.'); | 71 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.'); |
72 | 72 |
73 test(function() { | 73 test(function() { |
74 var request = new PaymentRequest(['foo'], buildDetails()); | 74 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls()); |
75 assert_not_equals(request.abort, undefined, 'PaymentRequest should have abor t() method.'); | 75 assert_not_equals(request.abort, undefined, 'PaymentRequest should have abor t() method.'); |
76 assert_not_equals(request.show, undefined, 'PaymentRequest should have show( ) method.'); | 76 assert_not_equals(request.show, undefined, 'PaymentRequest should have show( ) method.'); |
77 }, 'PaymentRequest should have methods abort() and show().'); | 77 }, 'PaymentRequest should have methods abort() and show().'); |
78 | 78 |
79 test(function() { | 79 test(function() { |
80 var request = new PaymentRequest(['foo'], buildDetails()); | 80 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls()); |
81 request.show(); | 81 request.show(); |
82 request.abort(); | 82 request.abort(); |
83 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' ); | 83 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' ); |
84 | 84 |
85 test(function() { | 85 test(function() { |
86 var request = new PaymentRequest(['foo'], buildDetails(), {'requestShipping' : true}, {'foo': {'gateway': 'bar'}}); | 86 var request = new PaymentRequest([{'supportedMethods': ['foo'], 'data': {'fo o': {'gateway': 'bar'}}}], buildDetails(), {'requestShipping': true}); |
87 request.show(); | 87 request.show(); |
88 request.abort(); | 88 request.abort(); |
89 }, 'Valid data causes no errors.'); | 89 }, 'Valid data causes no errors.'); |
90 | 90 |
91 test(function() { | 91 test(function() { |
92 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'})); | 92 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'})); |
93 assert_equals(null, request.shippingOption); | 93 assert_equals(null, request.shippingOption); |
94 }, 'Shipping option identifier should be null if shipping request is omitted.'); | 94 }, 'Shipping option identifier should be null if shipping request is omitted.'); |
95 | 95 |
96 test(function() { | 96 test(function() { |
97 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': false}); | 97 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'}), {'requestShipping': false}); |
98 assert_equals(null, request.shippingOption); | 98 assert_equals(null, request.shippingOption); |
99 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.'); | 99 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.'); |
100 | 100 |
101 test(function() { | 101 test(function() { |
102 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': true}); | 102 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'}), {'requestShipping': true}); |
103 assert_equals('standard', request.shippingOption); | 103 assert_equals('standard', request.shippingOption); |
104 }, 'Shipping option identifier should default to the single provided option.'); | 104 }, 'Shipping option identifier should default to the single provided option.'); |
105 | 105 |
106 test(function() { | 106 test(function() { |
107 var request = new PaymentRequest(['foo'], {"items": [buildItem()]}, {'reques tShipping': true}); | 107 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {"items": [buildItem()]}, {'requestShipping': true}); |
108 assert_equals(null, request.shippingOption); | 108 assert_equals(null, request.shippingOption); |
109 }, 'Shipping option identifier should be null when no shipping options are provi ded.'); | 109 }, 'Shipping option identifier should be null when no shipping options are provi ded.'); |
110 | 110 |
111 test(function() { | 111 test(function() { |
112 var request = new PaymentRequest(['foo'], {'items': [buildItem()], 'shipping Options': [buildItem({'id': 'standard'}), buildItem({'id': 'express'})]}, {'requ estShipping': true}); | 112 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {'items': [buildItem()], 'shippingOptions': [buildItem({'id': 'standard'}), buildItem({'id ': 'express'})]}, {'requestShipping': true}); |
113 assert_equals(null, request.shippingOption); | 113 assert_equals(null, request.shippingOption); |
114 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.'); | 114 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.'); |
115 | 115 |
116 | 116 |
117 generate_tests(assert_throws, [ | 117 generate_tests(assert_throws, [ |
118 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() { | 118 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() { |
119 new PaymentRequest('', '', '', '') | 119 new PaymentRequest('', '', '', '') |
120 }], | 120 }], |
121 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() { | 121 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() { |
122 new PaymentRequest(undefined, undefined) | 122 new PaymentRequest(undefined, undefined) |
123 }], | 123 }], |
124 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() { | 124 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() { |
125 new PaymentRequest(null, null) | 125 new PaymentRequest(null, null) |
126 }], | 126 }], |
127 ['Empty list of supported payment method identifiers should throw.', null, f unction() { | 127 ['Empty list of supported payment method identifiers should throw.', null, f unction() { |
128 new PaymentRequest([], buildDetails()) | 128 new PaymentRequest([], buildDetails()) |
129 }], | 129 }], |
130 ['Keys in payment method specific data object should match accepted method i dentifiers.', null, function() { | |
131 new PaymentRequest(['foo'], buildDetails(), {}, {'bar': {'gateway': 'baz '}}) | |
132 }], | |
133 ['Empty details should throw', null, function() { | 130 ['Empty details should throw', null, function() { |
134 new PaymentRequest(['foo'], {}) | 131 new PaymentRequest([{'supportedMethods': ['foo']}], {}) |
135 }], | 132 }], |
136 ['Empty items should throw', null, function() { | 133 ['Empty items should throw', null, function() { |
137 new PaymentRequest(['foo'], {'items': []}) | 134 new PaymentRequest([{'supportedMethods': ['foo']}], {'items': []}) |
138 }], | 135 }], |
139 ['Aborting before showing should throw.', null, function() { | 136 ['Aborting before showing should throw.', null, function() { |
140 new PaymentRequest(['foo'], buildDetails()).abort() | 137 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails()).abor t() |
141 }], | 138 }], |
142 | 139 |
143 // Payment method specific data should be a JSON-serializable object. | 140 // Payment method specific data should be a JSON-serializable object. |
144 ['Array value for payment method specific data parameter should throw', null , function() { | 141 ['Array value for payment method specific data parameter should throw', null , function() { |
145 new PaymentRequest(['foo'], buildDetails(), {}, []) | 142 new PaymentRequest([{'supportedMethods': ['foo'], data : [] }], buildDet ails(), {}) |
please use gerrit instead
2016/05/29 19:57:12
No space between [] and } .
Here and everywhere:
zino
2016/06/01 17:43:46
Done.
| |
146 }], | 143 }], |
147 ['String value for payment method specific data parameter should throw', nul l, function() { | 144 ['String value for payment method specific data parameter should throw', nul l, function() { |
148 new PaymentRequest(['foo'], buildDetails(), {}, 'foo') | 145 new PaymentRequest([{'supportedMethods': ['foo'], data : 'foo' }], build Details(), {}) |
please use gerrit instead
2016/05/29 19:57:12
No space between 'foo' and }.
zino
2016/06/01 17:43:46
Done.
| |
149 }], | 146 }], |
150 ['Numeric value for payment method specific data parameter should throw', nu ll, function() { | 147 ['Numeric value for payment method specific data parameter should throw', nu ll, function() { |
151 new PaymentRequest(['foo'], buildDetails(), {}, 42) | 148 new PaymentRequest([{'supportedMethods': ['foo'], data : 42 }], buildDet ails(), {}) |
please use gerrit instead
2016/05/29 19:57:12
No space between 42 and }.
zino
2016/06/01 17:43:46
Done.
| |
152 }], | 149 }], |
153 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() { | 150 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() { |
154 var infiniteData = {'foo': {}}; | 151 var infiniteData = {'foo': {}}; |
155 infiniteData.foo = infiniteData; | 152 infiniteData.foo = infiniteData; |
156 new PaymentRequest(['foo'], buildDetails(), {}, infiniteData) | 153 new PaymentRequest([{'supportedMethods': ['foo'], data : infiniteData }] , buildDetails(), {}) |
please use gerrit instead
2016/05/29 19:57:11
No space between infiniteData and }.
please use gerrit instead
2016/05/29 19:57:12
Add tests for
* 'data': null
* 'data': undefined
zino
2016/06/01 17:43:46
Done.
I added null case only.
The 'data' is not r
Marijn Kruisselbrink
2016/06/01 18:20:24
Yeah, throwing for null while treating undefined t
| |
157 }], | 154 }] |
158 | |
159 // Values in payment method specific data object should be JSON-serializable objects. | |
160 ['Array value for one of the payment method specific data pieces should thro w', null, function() { | |
161 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': []}) | |
162 }], | |
163 ['String value for one of the payment method specific data pieces should thr ow', null, function() { | |
164 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 'bar'}) | |
165 }], | |
166 ['Numeric value for one of the payment method specific data pieces should th row', null, function() { | |
167 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 42}) | |
168 }], | |
169 ]); | 155 ]); |
170 | 156 |
171 var detailNames = ['items', 'shippingOptions']; | 157 var detailNames = ['items', 'shippingOptions']; |
172 for (var i in detailNames) { | 158 for (var i in detailNames) { |
173 generate_tests(assert_throws, [ | 159 generate_tests(assert_throws, [ |
174 // Invalid currency code formats. | 160 // Invalid currency code formats. |
175 ['Invalid currency code US1 should throw', null, function() { | 161 ['Invalid currency code US1 should throw', null, function() { |
176 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'US1'})) | 162 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'US1'})) |
177 }], | 163 }], |
178 ['Invalid currency code US should throw', null, function() { | 164 ['Invalid currency code US should throw', null, function() { |
179 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'US'})) | 165 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'US'})) |
180 }], | 166 }], |
181 ['Invalid currency code USDO should throw', null, function() { | 167 ['Invalid currency code USDO should throw', null, function() { |
182 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'USDO'})) | 168 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'USDO'})) |
183 }], | 169 }], |
184 ['Invalid currency code usd should throw', null, function() { | 170 ['Invalid currency code usd should throw', null, function() { |
185 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'usd'})) | 171 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'usd'})) |
186 }], | 172 }], |
187 ['Empty currency code should throw', null, function() { | 173 ['Empty currency code should throw', null, function() { |
188 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : ''})) | 174 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': ''})) |
189 }], | 175 }], |
190 ['Null currency code should throw', null, function() { | 176 ['Null currency code should throw', null, function() { |
191 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : null})) | 177 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': null})) |
192 }], | 178 }], |
193 ['Undefined currency code should throw', null, function() { | 179 ['Undefined currency code should throw', null, function() { |
194 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : undefined})) | 180 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': undefined})) |
195 }], | 181 }], |
196 | 182 |
197 // Invalid amount formats. | 183 // Invalid amount formats. |
198 ['Invalid amount "-" should throw', null, function() { | 184 ['Invalid amount "-" should throw', null, function() { |
199 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -'})) | 185 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-'})) |
200 }], | 186 }], |
201 ['Invalid amount "notdigits" should throw', null, function() { | 187 ['Invalid amount "notdigits" should throw', null, function() { |
202 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' notdigits'})) | 188 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': 'notdigits'})) |
203 }], | 189 }], |
204 ['Invalid amount "ALSONOTDIGITS" should throw', null, function() { | 190 ['Invalid amount "ALSONOTDIGITS" should throw', null, function() { |
205 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' ALSONOTDIGITS'})) | 191 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': 'ALSONOTDIGITS'})) |
206 }], | 192 }], |
207 ['Invalid amount "10." should throw', null, function() { | 193 ['Invalid amount "10." should throw', null, function() { |
208 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10.'})) | 194 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '10.'})) |
209 }], | 195 }], |
210 ['Invalid amount ".99" should throw', null, function() { | 196 ['Invalid amount ".99" should throw', null, function() { |
211 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' .99'})) | 197 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '.99'})) |
212 }], | 198 }], |
213 ['Invalid amount "-10." should throw', null, function() { | 199 ['Invalid amount "-10." should throw', null, function() { |
214 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -10.'})) | 200 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-10.'})) |
215 }], | 201 }], |
216 ['Invalid amount "-.99" should throw', null, function() { | 202 ['Invalid amount "-.99" should throw', null, function() { |
217 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -.99'})) | 203 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-.99'})) |
218 }], | 204 }], |
219 ['Invalid amount "10-" should throw', null, function() { | 205 ['Invalid amount "10-" should throw', null, function() { |
220 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10-'})) | 206 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '10-'})) |
221 }], | 207 }], |
222 ['Invalid amount "1-0" should throw', null, function() { | 208 ['Invalid amount "1-0" should throw', null, function() { |
223 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1-0'})) | 209 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1-0'})) |
224 }], | 210 }], |
225 ['Invalid amount "1.0.0" should throw', null, function() { | 211 ['Invalid amount "1.0.0" should throw', null, function() { |
226 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1.0.0'})) | 212 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1.0.0'})) |
227 }], | 213 }], |
228 ['Invalid amount "1/3" should throw', null, function() { | 214 ['Invalid amount "1/3" should throw', null, function() { |
229 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1/3'})) | 215 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1/3'})) |
230 }], | 216 }], |
231 ['Empty amount should throw', null, function() { | 217 ['Empty amount should throw', null, function() { |
232 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' '})) | 218 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': ''})) |
233 }], | 219 }], |
234 ['Null amount should throw', null, function() { | 220 ['Null amount should throw', null, function() { |
235 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n ull})) | 221 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null})) |
236 }], | 222 }], |
237 ['Undefined amount should throw', null, function() { | 223 ['Undefined amount should throw', null, function() { |
238 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u ndefined})) | 224 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined})) |
239 }], | 225 }], |
240 ]); | 226 ]); |
241 } | 227 } |
242 </script> | 228 </script> |
OLD | NEW |