Chromium Code Reviews| 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'}); | |
|
please use gerrit instead
2016/09/18 16:54:56
Add a test for 'shippingType' being:
null
undefin
zino
2016/09/18 18:57:40
Done.
| |
| 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': 'shipping'}); | |
|
please use gerrit instead
2016/09/18 16:54:56
Change 'shipping' to 'invalid'.
zino
2016/09/18 18:57:40
Done.
| |
| 190 assert_equals('shipping', request.shippingType); | |
| 191 }, 'Shipping type should be \'shipping\' if shipping type is invalid.'); | |
| 192 | |
| 193 test(function() { | |
| 158 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), ' displayItems': undefined}); | 194 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), ' displayItems': undefined}); |
| 159 }, 'Undefined display items should not throw.'); | 195 }, 'Undefined display items should not throw.'); |
| 160 | 196 |
| 161 test(function() { | 197 test(function() { |
| 162 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), ' displayItems': []}); | 198 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), ' displayItems': []}); |
| 163 }, 'Empty display items should not throw.'); | 199 }, 'Empty display items should not throw.'); |
| 164 | 200 |
| 165 test(function() { | 201 test(function() { |
| 166 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails('total', {' value': '0'})); | 202 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails('total', {' value': '0'})); |
| 167 }, 'Non-negative total value should not throw.'); | 203 }, 'Non-negative total value should not throw.'); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 }], | 354 }], |
| 319 ['Null amount should throw', null, function() { | 355 ['Null amount should throw', null, function() { |
| 320 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null})) | 356 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null})) |
| 321 }], | 357 }], |
| 322 ['Undefined amount should throw', null, function() { | 358 ['Undefined amount should throw', null, function() { |
| 323 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined})) | 359 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined})) |
| 324 }], | 360 }], |
| 325 ]); | 361 ]); |
| 326 } | 362 } |
| 327 </script> | 363 </script> |
| OLD | NEW |