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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp

Issue 1994913002: PaymentRequest: Remove id attribute from PaymentItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/payments/PaymentDetailsTestHelper.h" 5 #include "modules/payments/PaymentDetailsTestHelper.h"
6 6
7 #include "modules/payments/CurrencyAmount.h" 7 #include "modules/payments/CurrencyAmount.h"
8 #include "platform/heap/HeapAllocator.h" 8 #include "platform/heap/HeapAllocator.h"
9 9
10 namespace blink { 10 namespace blink {
11 namespace { 11 namespace {
12 12
13 // PaymentItem and ShippingOption have identical structure. 13 // PaymentItem and ShippingOption have identical structure
14 // except for the "id" field, which is present only in ShippingOption.
14 template <typename PaymentItemOrShippingOption> 15 template <typename PaymentItemOrShippingOption>
15 void setValues(PaymentItemOrShippingOption& original, PaymentTestDataToChange da ta, PaymentTestModificationType modificationType, const String& valueToUse) 16 void setValues(PaymentItemOrShippingOption& original, PaymentTestDataToChange da ta, PaymentTestModificationType modificationType, const String& valueToUse)
16 { 17 {
17 CurrencyAmount itemAmount; 18 CurrencyAmount itemAmount;
18 if (data == PaymentTestDataCurrencyCode) { 19 if (data == PaymentTestDataCurrencyCode) {
19 if (modificationType == PaymentTestOverwriteValue) 20 if (modificationType == PaymentTestOverwriteValue)
20 itemAmount.setCurrencyCode(valueToUse); 21 itemAmount.setCurrencyCode(valueToUse);
21 } else { 22 } else {
22 itemAmount.setCurrencyCode("USD"); 23 itemAmount.setCurrencyCode("USD");
23 } 24 }
24 if (data == PaymentTestDataValue) { 25 if (data == PaymentTestDataValue) {
25 if (modificationType == PaymentTestOverwriteValue) 26 if (modificationType == PaymentTestOverwriteValue)
26 itemAmount.setValue(valueToUse); 27 itemAmount.setValue(valueToUse);
27 } else { 28 } else {
28 itemAmount.setValue("9.99"); 29 itemAmount.setValue("9.99");
29 } 30 }
30 31
31 if (data != PaymentTestDataAmount || modificationType != PaymentTestRemoveKe y) 32 if (data != PaymentTestDataAmount || modificationType != PaymentTestRemoveKe y)
32 original.setAmount(itemAmount); 33 original.setAmount(itemAmount);
33 34
34 if (data == PaymentTestDataId) {
35 if (modificationType == PaymentTestOverwriteValue)
36 original.setId(valueToUse);
37 } else {
38 original.setId("id");
39 }
40 if (data == PaymentTestDataLabel) { 35 if (data == PaymentTestDataLabel) {
41 if (modificationType == PaymentTestOverwriteValue) 36 if (modificationType == PaymentTestOverwriteValue)
42 original.setLabel(valueToUse); 37 original.setLabel(valueToUse);
43 } else { 38 } else {
44 original.setLabel("Label"); 39 original.setLabel("Label");
45 } 40 }
46 } 41 }
47 42
48 } // namespace 43 } // namespace
49 44
50 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod ificationType modificationType, const String& valueToUse) 45 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod ificationType modificationType, const String& valueToUse)
51 { 46 {
47 DCHECK_NE(data, PaymentTestDataId);
52 PaymentItem item; 48 PaymentItem item;
53 setValues(item, data, modificationType, valueToUse); 49 setValues(item, data, modificationType, valueToUse);
54 return item; 50 return item;
55 } 51 }
56 52
57 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT estModificationType modificationType, const String& valueToUse) 53 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT estModificationType modificationType, const String& valueToUse)
58 { 54 {
59 ShippingOption shippingOption; 55 ShippingOption shippingOption;
56 if (data == PaymentTestDataId) {
57 if (modificationType == PaymentTestOverwriteValue)
58 shippingOption.setId(valueToUse);
59 } else {
60 shippingOption.setId("id");
61 }
60 setValues(shippingOption, data, modificationType, valueToUse); 62 setValues(shippingOption, data, modificationType, valueToUse);
61 return shippingOption; 63 return shippingOption;
62 } 64 }
63 65
64 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym entTestDataToChange data, PaymentTestModificationType modificationType, const St ring& valueToUse) 66 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym entTestDataToChange data, PaymentTestModificationType modificationType, const St ring& valueToUse)
65 { 67 {
66 PaymentItem item; 68 PaymentItem item;
67 if (detail == PaymentTestDetailItem) 69 if (detail == PaymentTestDetailItem)
68 item = buildPaymentItemForTest(data, modificationType, valueToUse); 70 item = buildPaymentItemForTest(data, modificationType, valueToUse);
69 else 71 else
70 item = buildPaymentItemForTest(); 72 item = buildPaymentItemForTest();
71 73
72 ShippingOption shippingOption; 74 ShippingOption shippingOption;
73 if (detail == PaymentTestDetailShippingOption) 75 if (detail == PaymentTestDetailShippingOption)
74 shippingOption = buildShippingOptionForTest(data, modificationType, valu eToUse); 76 shippingOption = buildShippingOptionForTest(data, modificationType, valu eToUse);
75 else 77 else
76 shippingOption = buildShippingOptionForTest(); 78 shippingOption = buildShippingOptionForTest();
77 79
78 PaymentDetails result; 80 PaymentDetails result;
79 result.setItems(HeapVector<PaymentItem>(1, item)); 81 result.setItems(HeapVector<PaymentItem>(1, item));
80 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); 82 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption));
81 83
82 return result; 84 return result;
83 } 85 }
84 86
85 } // namespace blink 87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698