Chromium Code Reviews| Index: chrome/test/data/payments/shipping_address_change.js |
| diff --git a/chrome/test/data/payments/shipping_address_change.js b/chrome/test/data/payments/shipping_address_change.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ceb5f5a54ea9f922c8f277ab72f25bf7da98bf18 |
| --- /dev/null |
| +++ b/chrome/test/data/payments/shipping_address_change.js |
| @@ -0,0 +1,91 @@ |
| +/* |
| + * Copyright 2017 The Chromium Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +/* global PaymentRequest:false */ |
|
please use gerrit instead
2017/04/20 15:41:44
This line is no longer necessary in new tests. The
sebsg
2017/04/20 21:16:40
Done.
|
| + |
| +/** |
| + * Launches the PaymentRequest UI that prints the shipping address received |
| + * on shippingAddressChange events at the end of the transaction. |
| + */ |
| +function buy() { // eslint-disable-line no-unused-vars |
| + try { |
| + var details = { |
| + total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| + displayItems: [ |
| + { |
| + label: 'Pending shipping price', |
| + amount: {currency: 'USD', value: '0.00'}, |
| + pending: true |
| + }, |
| + { |
| + label: 'Subtotal', |
| + amount: {currency: 'USD', value: '5.00'} |
| + } |
| + ] |
| + }; |
| + |
| + var request = new PaymentRequest( |
| + [{supportedMethods: ['visa']}], details, {requestShipping: true}); |
| + |
| + var shippingAddressChange; |
| + |
| + request.addEventListener('shippingaddresschange', function(evt) { |
| + evt.updateWith(new Promise(function(resolve) { |
| + shippingAddressChange = request.shippingAddress; |
|
please use gerrit instead
2017/04/20 15:41:44
Print the address from here instead:
print(JSON.s
sebsg
2017/04/20 21:16:39
Done.
|
| + resolve(updateDetails(details, request.shippingAddress)); |
|
please use gerrit instead
2017/04/20 15:41:44
Technically this test does not require updating pr
sebsg
2017/04/20 21:16:40
Done.
|
| + })); |
| + }); |
| + |
| + request.show() |
|
please use gerrit instead
2017/04/20 15:41:44
"request.show()" is sufficient. Important print()
sebsg
2017/04/20 21:16:40
Done.
|
| + .then(function(resp) { |
| + resp.complete('success') |
| + .then(function() { |
| + print(JSON.stringify(shippingAddressChange, undefined, 2)); |
| + }) |
| + .catch(function(error) { |
| + print(error); |
| + }); |
| + }) |
| + .catch(function(error) { |
| + print(error); |
| + }); |
| + } catch (error) { |
| + print(error.message); |
| + } |
| +} |
| + |
| +/** |
| + * Updates the shopping cart with the appropriate shipping prices according to |
| + * the shipping address. |
| + * @param {object} details - The shopping cart. |
| + * @param {ShippingAddress} addr - The shipping address. |
| + * @return {object} The updated shopping cart. |
| + */ |
| +function updateDetails(details, addr) { |
| + if (addr.country === 'US') { |
| + var shippingOption = { |
| + id: '', |
| + label: '', |
| + amount: {currency: 'USD', value: '0.00'}, |
| + selected: true |
| + }; |
| + if (addr.region === 'CA') { |
| + shippingOption.id = 'californiaShippingOption'; |
| + shippingOption.label = 'Free shipping in California'; |
| + details.total.amount.value = '5.00'; |
| + } else { |
| + shippingOption.id = 'usShippingOption'; |
| + shippingOption.label = 'Standard shipping in US'; |
| + shippingOption.amount.value = '5.00'; |
| + details.total.amount.value = '10.00'; |
| + } |
| + details.displayItems.splice(0, 1, shippingOption); |
| + details.shippingOptions = [shippingOption]; |
| + } else { |
| + delete details.shippingOptions; |
| + } |
| + return details; |
| +} |