Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/test/data/payments/shipping_address_change.js

Issue 2828913002: [Payments] Normalize Shipping Address Change on Android. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 /* 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.
8
9 /**
10 * Launches the PaymentRequest UI that prints the shipping address received
11 * on shippingAddressChange events at the end of the transaction.
12 */
13 function buy() { // eslint-disable-line no-unused-vars
14 try {
15 var details = {
16 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}},
17 displayItems: [
18 {
19 label: 'Pending shipping price',
20 amount: {currency: 'USD', value: '0.00'},
21 pending: true
22 },
23 {
24 label: 'Subtotal',
25 amount: {currency: 'USD', value: '5.00'}
26 }
27 ]
28 };
29
30 var request = new PaymentRequest(
31 [{supportedMethods: ['visa']}], details, {requestShipping: true});
32
33 var shippingAddressChange;
34
35 request.addEventListener('shippingaddresschange', function(evt) {
36 evt.updateWith(new Promise(function(resolve) {
37 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.
38 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.
39 }));
40 });
41
42 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.
43 .then(function(resp) {
44 resp.complete('success')
45 .then(function() {
46 print(JSON.stringify(shippingAddressChange, undefined, 2));
47 })
48 .catch(function(error) {
49 print(error);
50 });
51 })
52 .catch(function(error) {
53 print(error);
54 });
55 } catch (error) {
56 print(error.message);
57 }
58 }
59
60 /**
61 * Updates the shopping cart with the appropriate shipping prices according to
62 * the shipping address.
63 * @param {object} details - The shopping cart.
64 * @param {ShippingAddress} addr - The shipping address.
65 * @return {object} The updated shopping cart.
66 */
67 function updateDetails(details, addr) {
68 if (addr.country === 'US') {
69 var shippingOption = {
70 id: '',
71 label: '',
72 amount: {currency: 'USD', value: '0.00'},
73 selected: true
74 };
75 if (addr.region === 'CA') {
76 shippingOption.id = 'californiaShippingOption';
77 shippingOption.label = 'Free shipping in California';
78 details.total.amount.value = '5.00';
79 } else {
80 shippingOption.id = 'usShippingOption';
81 shippingOption.label = 'Standard shipping in US';
82 shippingOption.amount.value = '5.00';
83 details.total.amount.value = '10.00';
84 }
85 details.displayItems.splice(0, 1, shippingOption);
86 details.shippingOptions = [shippingOption];
87 } else {
88 delete details.shippingOptions;
89 }
90 return details;
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698