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]; |
11 } | 11 } |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 function buildItem(optionalSubstituteKeyValuePair) { | 15 function buildItem(optionalSubstituteKeyValuePair) { |
16 var item = {'id': 'item_id', 'label': 'Item Description', 'amount': {'curren
cy': 'USD', 'value': '10.00'}}; | 16 var item = {'id': 'item_id', 'label': 'Item Description', 'amount': {'curren
cy': 'USD', 'value': '10.00'}}; |
17 | 17 |
18 if (optionalSubstituteKeyValuePair) { | 18 if (optionalSubstituteKeyValuePair) { |
19 substitute(item, optionalSubstituteKeyValuePair); | 19 substitute(item, optionalSubstituteKeyValuePair); |
20 substitute(item['amount'], optionalSubstituteKeyValuePair); | 20 substitute(item['amount'], optionalSubstituteKeyValuePair); |
21 } | 21 } |
22 | 22 |
23 return item; | 23 return item; |
24 } | 24 } |
25 | 25 |
26 function buildDetails(optionalDetailName, optionalSubstituteKeyValuePair) { | 26 function buildDetails(optionalDetailName, optionalSubstituteKeyValuePair) { |
27 var details = {}; | 27 var details = {}; |
28 var detailNames = ['items', 'shippingOptions']; | 28 var detailNames = ['displayItems', 'shippingOptions']; |
| 29 |
| 30 assert_true(!optionalDetailName || detailNames.indexOf(optionalDetailName) >
= 0, 'Detail name "' + optionalDetailName + '" should be either "displayItems" o
r "shippingOptions".'); |
29 | 31 |
30 for (var i in detailNames) { | 32 for (var i in detailNames) { |
31 if (optionalDetailName == detailNames[i]) { | 33 if (optionalDetailName == detailNames[i]) { |
32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair)
]; | 34 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair)
]; |
33 } else { | 35 } else { |
34 details[detailNames[i]] = [buildItem()]; | 36 details[detailNames[i]] = [buildItem()]; |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
38 return details; | 40 return details; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {'
id': 'standard'}), {'requestShipping': false}); | 99 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {'
id': 'standard'}), {'requestShipping': false}); |
98 assert_equals(null, request.shippingOption); | 100 assert_equals(null, request.shippingOption); |
99 }, 'Shipping option identifier should be null if shipping is explicitly not requ
ested.'); | 101 }, 'Shipping option identifier should be null if shipping is explicitly not requ
ested.'); |
100 | 102 |
101 test(function() { | 103 test(function() { |
102 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {'
id': 'standard'}), {'requestShipping': true}); | 104 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {'
id': 'standard'}), {'requestShipping': true}); |
103 assert_equals('standard', request.shippingOption); | 105 assert_equals('standard', request.shippingOption); |
104 }, 'Shipping option identifier should default to the single provided option.'); | 106 }, 'Shipping option identifier should default to the single provided option.'); |
105 | 107 |
106 test(function() { | 108 test(function() { |
107 var request = new PaymentRequest(['foo'], {"items": [buildItem()]}, {'reques
tShipping': true}); | 109 var request = new PaymentRequest(['foo'], {'displayItems': [buildItem()]}, {
'requestShipping': true}); |
108 assert_equals(null, request.shippingOption); | 110 assert_equals(null, request.shippingOption); |
109 }, 'Shipping option identifier should be null when no shipping options are provi
ded.'); | 111 }, 'Shipping option identifier should be null when no shipping options are provi
ded.'); |
110 | 112 |
111 test(function() { | 113 test(function() { |
112 var request = new PaymentRequest(['foo'], {'items': [buildItem()], 'shipping
Options': [buildItem({'id': 'standard'}), buildItem({'id': 'express'})]}, {'requ
estShipping': true}); | 114 var request = new PaymentRequest(['foo'], {'displayItems': [buildItem()], 's
hippingOptions': [buildItem({'id': 'standard'}), buildItem({'id': 'express'})]},
{'requestShipping': true}); |
113 assert_equals(null, request.shippingOption); | 115 assert_equals(null, request.shippingOption); |
114 }, 'Shipping option identifier should be null at first when multiple shipping op
tions are provided.'); | 116 }, 'Shipping option identifier should be null at first when multiple shipping op
tions are provided.'); |
115 | 117 |
116 | 118 |
117 generate_tests(assert_throws, [ | 119 generate_tests(assert_throws, [ |
118 ['PaymentRequest constructor should throw for incorrect parameter types.', n
ull, function() { | 120 ['PaymentRequest constructor should throw for incorrect parameter types.', n
ull, function() { |
119 new PaymentRequest('', '', '', '') | 121 new PaymentRequest('', '', '', '') |
120 }], | 122 }], |
121 ['PaymentRequest constructor should throw for undefined required parameters.
', null, function() { | 123 ['PaymentRequest constructor should throw for undefined required parameters.
', null, function() { |
122 new PaymentRequest(undefined, undefined) | 124 new PaymentRequest(undefined, undefined) |
123 }], | 125 }], |
124 ['PaymentRequest constructor should throw for null required parameter.', nul
l, function() { | 126 ['PaymentRequest constructor should throw for null required parameter.', nul
l, function() { |
125 new PaymentRequest(null, null) | 127 new PaymentRequest(null, null) |
126 }], | 128 }], |
127 ['Empty list of supported payment method identifiers should throw TypeError.
', new TypeError(), function() { | 129 ['Empty list of supported payment method identifiers should throw TypeError.
', new TypeError(), function() { |
128 new PaymentRequest([], buildDetails()) | 130 new PaymentRequest([], buildDetails()) |
129 }], | 131 }], |
130 ['Keys in payment method specific data object should match accepted method i
dentifiers.', null, function() { | 132 ['Keys in payment method specific data object should match accepted method i
dentifiers.', null, function() { |
131 new PaymentRequest(['foo'], buildDetails(), {}, {'bar': {'gateway': 'baz
'}}) | 133 new PaymentRequest(['foo'], buildDetails(), {}, {'bar': {'gateway': 'baz
'}}) |
132 }], | 134 }], |
133 ['Empty details should throw', null, function() { | 135 ['Empty details should throw', null, function() { |
134 new PaymentRequest(['foo'], {}) | 136 new PaymentRequest(['foo'], {}) |
135 }], | 137 }], |
136 ['Empty items should throw', null, function() { | 138 ['Empty items should throw', null, function() { |
137 new PaymentRequest(['foo'], {'items': []}) | 139 new PaymentRequest(['foo'], {'displayItems': []}) |
138 }], | 140 }], |
139 ['Aborting before showing should throw.', null, function() { | 141 ['Aborting before showing should throw.', null, function() { |
140 new PaymentRequest(['foo'], buildDetails()).abort() | 142 new PaymentRequest(['foo'], buildDetails()).abort() |
141 }], | 143 }], |
142 | 144 |
143 // Payment method specific data should be a JSON-serializable object. | 145 // Payment method specific data should be a JSON-serializable object. |
144 ['Array value for payment method specific data parameter should throw', null
, function() { | 146 ['Array value for payment method specific data parameter should throw', null
, function() { |
145 new PaymentRequest(['foo'], buildDetails(), {}, []) | 147 new PaymentRequest(['foo'], buildDetails(), {}, []) |
146 }], | 148 }], |
147 ['String value for payment method specific data parameter should throw', nul
l, function() { | 149 ['String value for payment method specific data parameter should throw', nul
l, function() { |
(...skipping 13 matching lines...) Expand all Loading... |
161 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': []}) | 163 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': []}) |
162 }], | 164 }], |
163 ['String value for one of the payment method specific data pieces should thr
ow', null, function() { | 165 ['String value for one of the payment method specific data pieces should thr
ow', null, function() { |
164 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 'bar'}) | 166 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 'bar'}) |
165 }], | 167 }], |
166 ['Numeric value for one of the payment method specific data pieces should th
row', null, function() { | 168 ['Numeric value for one of the payment method specific data pieces should th
row', null, function() { |
167 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 42}) | 169 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 42}) |
168 }], | 170 }], |
169 ]); | 171 ]); |
170 | 172 |
171 var detailNames = ['items', 'shippingOptions']; | 173 var detailNames = ['displayItems', 'shippingOptions']; |
172 for (var i in detailNames) { | 174 for (var i in detailNames) { |
173 generate_tests(assert_throws, [ | 175 generate_tests(assert_throws, [ |
174 // Invalid currency code formats. | 176 // Invalid currency code formats. |
175 ['Invalid currency code US1 should throw', null, function() { | 177 ['Invalid currency code US1 should throw', null, function() { |
176 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency'
: 'US1'})) | 178 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency'
: 'US1'})) |
177 }], | 179 }], |
178 ['Invalid currency code US should throw', null, function() { | 180 ['Invalid currency code US should throw', null, function() { |
179 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency'
: 'US'})) | 181 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency'
: 'US'})) |
180 }], | 182 }], |
181 ['Invalid currency code USDO should throw', null, function() { | 183 ['Invalid currency code USDO should throw', null, function() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 }], | 235 }], |
234 ['Null amount should throw', null, function() { | 236 ['Null amount should throw', null, function() { |
235 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n
ull})) | 237 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n
ull})) |
236 }], | 238 }], |
237 ['Undefined amount should throw', null, function() { | 239 ['Undefined amount should throw', null, function() { |
238 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u
ndefined})) | 240 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u
ndefined})) |
239 }], | 241 }], |
240 ]); | 242 ]); |
241 } | 243 } |
242 </script> | 244 </script> |
OLD | NEW |