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, substituteKeyValuePairs) { | 7 function substitute(originalObject, substituteKeyValuePairs) { |
8 for (var key in originalObject) { | 8 for (var key in originalObject) { |
9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePairs.hasOwn
Property(key)) { | 9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePairs.hasOwn
Property(key)) { |
10 originalObject[key] = substituteKeyValuePairs[key]; | 10 originalObject[key] = substituteKeyValuePairs[key]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 }, 'Creating a PaymentRequest with undefined optional parameters should not thro
w or crash.'); | 78 }, 'Creating a PaymentRequest with undefined optional parameters should not thro
w or crash.'); |
79 | 79 |
80 test(function() { | 80 test(function() { |
81 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), null); | 81 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), null); |
82 }, 'Creating a PaymentRequest with null optional parameters should not throw or
crash.'); | 82 }, 'Creating a PaymentRequest with null optional parameters should not throw or
crash.'); |
83 | 83 |
84 test(function() { | 84 test(function() { |
85 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); | 85 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); |
86 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re
adonly shippingAddress property.'); | 86 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re
adonly shippingAddress property.'); |
87 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea
donly shippingOption property.'); | 87 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea
donly shippingOption property.'); |
| 88 assert_readonly(request, 'shippingType', 'PaymentRequest should have a reado
nly shippingType property.'); |
88 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope
rties.'); | 89 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope
rties.'); |
89 | 90 |
90 test(function() { | 91 test(function() { |
91 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); | 92 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); |
92 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques
t should have onShippingAddressChange event.'); | 93 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques
t should have onShippingAddressChange event.'); |
93 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest
should have onShippingOptionChange event.'); | 94 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest
should have onShippingOptionChange event.'); |
94 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang
e events.'); | 95 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang
e events.'); |
95 | 96 |
96 test(function() { | 97 test(function() { |
97 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); | 98 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 assert_equals('standard', request.shippingOption); | 149 assert_equals('standard', request.shippingOption); |
149 }, 'Shipping option identifier should default to the selected shipping option.')
; | 150 }, 'Shipping option identifier should default to the selected shipping option.')
; |
150 | 151 |
151 test(function() { | 152 test(function() { |
152 var shippingOptions = [buildItem({'id': 'standard', 'selected': true}), buil
dItem({'id': 'express', 'selected': true})]; | 153 var shippingOptions = [buildItem({'id': 'standard', 'selected': true}), buil
dItem({'id': 'express', 'selected': true})]; |
153 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {'total':
buildItem(), 'displayItems': [buildItem()], 'shippingOptions': shippingOptions},
{'requestShipping': true}); | 154 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {'total':
buildItem(), 'displayItems': [buildItem()], 'shippingOptions': shippingOptions},
{'requestShipping': true}); |
154 assert_equals('express', request.shippingOption); | 155 assert_equals('express', request.shippingOption); |
155 }, 'Shipping option identifier should default to the last selected shipping opti
on, if multiple are selected.'); | 156 }, 'Shipping option identifier should default to the last selected shipping opti
on, if multiple are selected.'); |
156 | 157 |
157 test(function() { | 158 test(function() { |
| 159 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': false}); |
| 160 assert_equals(null, request.shippingType); |
| 161 }, 'Shipping type should be null if shipping is explicitly not requested.'); |
| 162 |
| 163 test(function() { |
| 164 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true}); |
| 165 assert_equals('shipping', request.shippingType); |
| 166 }, 'Shipping type should be \'shipping\' by default if shipping type isn\'t spec
ified.'); |
| 167 |
| 168 test(function() { |
| 169 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': false, 'shippingType': 'shipping'}); |
| 170 assert_equals(null, request.shippingType); |
| 171 }, 'Shipping type should be null if shipping type is specified but requestShippi
ng is false.'); |
| 172 |
| 173 test(function() { |
| 174 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': 'shipping'}); |
| 175 assert_equals('shipping', request.shippingType); |
| 176 }, 'Shipping type should be \'shipping\' if shipping type is specified as \'ship
ping\'.'); |
| 177 |
| 178 test(function() { |
| 179 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': 'delivery'}); |
| 180 assert_equals('delivery', request.shippingType); |
| 181 }, 'Shipping type should be \'delivery\' if shipping type is specified as \'deli
very\'.'); |
| 182 |
| 183 test(function() { |
| 184 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': 'pickup'}); |
| 185 assert_equals('pickup', request.shippingType); |
| 186 }, 'Shipping type should be \'pickup\' if shipping type is specified as \'pickup
\'.'); |
| 187 |
| 188 test(function() { |
| 189 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': 'invalid'}); |
| 190 assert_equals('shipping', request.shippingType); |
| 191 }, 'Shipping type should be \'shipping\' if shipping type is specified as invali
d string.'); |
| 192 |
| 193 test(function() { |
| 194 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': null}); |
| 195 assert_equals('shipping', request.shippingType); |
| 196 }, 'Shipping type should be \'shipping\' if shipping type is specified as null.'
); |
| 197 |
| 198 test(function() { |
| 199 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': undefined}); |
| 200 assert_equals('shipping', request.shippingType); |
| 201 }, 'Shipping type should be \'shipping\' if shipping type is specified as undefi
ned.'); |
| 202 |
| 203 test(function() { |
| 204 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': []}); |
| 205 assert_equals('shipping', request.shippingType); |
| 206 }, 'Shipping type should be \'shipping\' if shipping type is specified as [].'); |
| 207 |
| 208 test(function() { |
| 209 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': {}}); |
| 210 assert_equals('shipping', request.shippingType); |
| 211 }, 'Shipping type should be \'shipping\' if shipping type is specified as {}.'); |
| 212 |
| 213 test(function() { |
| 214 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai
ls(), {'requestShipping': true, 'shippingType': 0}); |
| 215 assert_equals('shipping', request.shippingType); |
| 216 }, 'Shipping type should be \'shipping\' if shipping type is specified as a numb
er.'); |
| 217 |
| 218 test(function() { |
158 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), '
displayItems': undefined}); | 219 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), '
displayItems': undefined}); |
159 }, 'Undefined display items should not throw.'); | 220 }, 'Undefined display items should not throw.'); |
160 | 221 |
161 test(function() { | 222 test(function() { |
162 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), '
displayItems': []}); | 223 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), '
displayItems': []}); |
163 }, 'Empty display items should not throw.'); | 224 }, 'Empty display items should not throw.'); |
164 | 225 |
165 test(function() { | 226 test(function() { |
166 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails('total', {'
value': '0'})); | 227 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails('total', {'
value': '0'})); |
167 }, 'Non-negative total value should not throw.'); | 228 }, 'Non-negative total value should not throw.'); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 }], | 379 }], |
319 ['Null amount should throw', null, function() { | 380 ['Null amount should throw', null, function() { |
320 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det
ailNames[i], {'value': null})) | 381 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det
ailNames[i], {'value': null})) |
321 }], | 382 }], |
322 ['Undefined amount should throw', null, function() { | 383 ['Undefined amount should throw', null, function() { |
323 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det
ailNames[i], {'value': undefined})) | 384 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det
ailNames[i], {'value': undefined})) |
324 }], | 385 }], |
325 ]); | 386 ]); |
326 } | 387 } |
327 </script> | 388 </script> |
OLD | NEW |