| OLD | NEW |
| 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/PaymentTestHelper.h" | 5 #include "modules/payments/PaymentTestHelper.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "modules/payments/CurrencyAmount.h" | 9 #include "modules/payments/PaymentCurrencyAmount.h" |
| 10 #include "modules/payments/PaymentMethodData.h" | 10 #include "modules/payments/PaymentMethodData.h" |
| 11 #include "platform/heap/HeapAllocator.h" | 11 #include "platform/heap/HeapAllocator.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // PaymentItem and ShippingOption have identical structure | 16 // PaymentItem and PaymentShippingOption have identical structure |
| 17 // except for the "id" field, which is present only in ShippingOption. | 17 // except for the "id" field, which is present only in PaymentShippingOption. |
| 18 template <typename PaymentItemOrShippingOption> | 18 template <typename PaymentItemOrPaymentShippingOption> |
| 19 void setValues(PaymentItemOrShippingOption& original, PaymentTestDataToChange da
ta, PaymentTestModificationType modificationType, const String& valueToUse) | 19 void setValues(PaymentItemOrPaymentShippingOption& original, PaymentTestDataToCh
ange data, PaymentTestModificationType modificationType, const String& valueToUs
e) |
| 20 { | 20 { |
| 21 CurrencyAmount itemAmount; | 21 PaymentCurrencyAmount itemAmount; |
| 22 if (data == PaymentTestDataCurrencyCode) { | 22 if (data == PaymentTestDataCurrencyCode) { |
| 23 if (modificationType == PaymentTestOverwriteValue) | 23 if (modificationType == PaymentTestOverwriteValue) |
| 24 itemAmount.setCurrency(valueToUse); | 24 itemAmount.setCurrency(valueToUse); |
| 25 } else { | 25 } else { |
| 26 itemAmount.setCurrency("USD"); | 26 itemAmount.setCurrency("USD"); |
| 27 } | 27 } |
| 28 if (data == PaymentTestDataValue) { | 28 if (data == PaymentTestDataValue) { |
| 29 if (modificationType == PaymentTestOverwriteValue) | 29 if (modificationType == PaymentTestOverwriteValue) |
| 30 itemAmount.setValue(valueToUse); | 30 itemAmount.setValue(valueToUse); |
| 31 } else { | 31 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) | 48 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) |
| 49 { | 49 { |
| 50 DCHECK_NE(data, PaymentTestDataId); | 50 DCHECK_NE(data, PaymentTestDataId); |
| 51 PaymentItem item; | 51 PaymentItem item; |
| 52 setValues(item, data, modificationType, valueToUse); | 52 setValues(item, data, modificationType, valueToUse); |
| 53 return item; | 53 return item; |
| 54 } | 54 } |
| 55 | 55 |
| 56 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT
estModificationType modificationType, const String& valueToUse) | 56 PaymentShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, P
aymentTestModificationType modificationType, const String& valueToUse) |
| 57 { | 57 { |
| 58 ShippingOption shippingOption; | 58 PaymentShippingOption shippingOption; |
| 59 if (data == PaymentTestDataId) { | 59 if (data == PaymentTestDataId) { |
| 60 if (modificationType == PaymentTestOverwriteValue) | 60 if (modificationType == PaymentTestOverwriteValue) |
| 61 shippingOption.setId(valueToUse); | 61 shippingOption.setId(valueToUse); |
| 62 } else { | 62 } else { |
| 63 shippingOption.setId("id"); | 63 shippingOption.setId("id"); |
| 64 } | 64 } |
| 65 setValues(shippingOption, data, modificationType, valueToUse); | 65 setValues(shippingOption, data, modificationType, valueToUse); |
| 66 return shippingOption; | 66 return shippingOption; |
| 67 } | 67 } |
| 68 | 68 |
| 69 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) | 69 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) |
| 70 { | 70 { |
| 71 PaymentItem total; | 71 PaymentItem total; |
| 72 if (detail == PaymentTestDetailTotal) | 72 if (detail == PaymentTestDetailTotal) |
| 73 total = buildPaymentItemForTest(data, modificationType, valueToUse); | 73 total = buildPaymentItemForTest(data, modificationType, valueToUse); |
| 74 else | 74 else |
| 75 total = buildPaymentItemForTest(); | 75 total = buildPaymentItemForTest(); |
| 76 | 76 |
| 77 PaymentItem item; | 77 PaymentItem item; |
| 78 if (detail == PaymentTestDetailItem) | 78 if (detail == PaymentTestDetailItem) |
| 79 item = buildPaymentItemForTest(data, modificationType, valueToUse); | 79 item = buildPaymentItemForTest(data, modificationType, valueToUse); |
| 80 else | 80 else |
| 81 item = buildPaymentItemForTest(); | 81 item = buildPaymentItemForTest(); |
| 82 | 82 |
| 83 ShippingOption shippingOption; | 83 PaymentShippingOption shippingOption; |
| 84 if (detail == PaymentTestDetailShippingOption) | 84 if (detail == PaymentTestDetailShippingOption) |
| 85 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); | 85 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); |
| 86 else | 86 else |
| 87 shippingOption = buildShippingOptionForTest(); | 87 shippingOption = buildShippingOptionForTest(); |
| 88 | 88 |
| 89 PaymentDetails result; | 89 PaymentDetails result; |
| 90 result.setTotal(total); | 90 result.setTotal(total); |
| 91 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); | 91 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); |
| 92 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); | 92 result.setShippingOptions(HeapVector<PaymentShippingOption>(2, shippingOptio
n)); |
| 93 | 93 |
| 94 return result; | 94 return result; |
| 95 } | 95 } |
| 96 | 96 |
| 97 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() | 97 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() |
| 98 { | 98 { |
| 99 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); | 99 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); |
| 100 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); | 100 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); |
| 101 return methodData; | 101 return methodData; |
| 102 } | 102 } |
| 103 | 103 |
| 104 mojom::blink::PaymentResponsePtr buildPaymentResponseForTest() | 104 mojom::blink::PaymentResponsePtr buildPaymentResponseForTest() |
| 105 { | 105 { |
| 106 mojom::blink::PaymentResponsePtr result = mojom::blink::PaymentResponse::New
(); | 106 mojom::blink::PaymentResponsePtr result = mojom::blink::PaymentResponse::New
(); |
| 107 result->total_amount = mojom::blink::CurrencyAmount::New(); | 107 result->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 108 return result; | 108 return result; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void makePaymentRequestOriginSecure(Document& document) | 111 void makePaymentRequestOriginSecure(Document& document) |
| 112 { | 112 { |
| 113 document.setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://www.
example.com/"))); | 113 document.setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://www.
example.com/"))); |
| 114 } | 114 } |
| 115 | 115 |
| 116 PaymentRequestMockFunctionScope::PaymentRequestMockFunctionScope(ScriptState* sc
riptState) | 116 PaymentRequestMockFunctionScope::PaymentRequestMockFunctionScope(ScriptState* sc
riptState) |
| 117 : m_scriptState(scriptState) | 117 : m_scriptState(scriptState) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 145 { | 145 { |
| 146 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); | 146 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() | 149 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() |
| 150 { | 150 { |
| 151 return bindToV8Function(); | 151 return bindToV8Function(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |