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 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_TEST_HELPER_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_TEST_HELPER_H_ 7 8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "third_party/blink/public/mojom/payments/payment_request.mojom-blink.h" 10 #include "third_party/blink/renderer/bindings/core/v8/script_function.h" 11 #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" 12 #include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h" 13 #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_init.h" 14 #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_update.h" 15 #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h" 16 #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" 17 #include "third_party/blink/renderer/platform/heap/heap_allocator.h" 18 #include "third_party/blink/renderer/platform/heap/persistent.h" 19 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" 20 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 21 #include "third_party/blink/renderer/platform/wtf/vector.h" 22 23 namespace blink { 24 25 class PaymentMethodData; 26 class ScriptState; 27 class ScriptValue; 28 class V8TestingScope; 29 30 enum PaymentTestDetailToChange { 31 kPaymentTestDetailNone, 32 kPaymentTestDetailTotal, 33 kPaymentTestDetailItem, 34 kPaymentTestDetailShippingOption, 35 kPaymentTestDetailModifierTotal, 36 kPaymentTestDetailModifierItem, 37 kPaymentTestDetailError 38 }; 39 40 enum PaymentTestDataToChange { 41 kPaymentTestDataNone, 42 kPaymentTestDataId, 43 kPaymentTestDataLabel, 44 kPaymentTestDataAmount, 45 kPaymentTestDataCurrencyCode, 46 kPaymentTestDataValue, 47 }; 48 49 enum PaymentTestModificationType { 50 kPaymentTestOverwriteValue, 51 kPaymentTestRemoveKey 52 }; 53 54 PaymentItem* BuildPaymentItemForTest( 55 PaymentTestDataToChange = kPaymentTestDataNone, 56 PaymentTestModificationType = kPaymentTestOverwriteValue, 57 const String& value_to_use = String()); 58 59 PaymentShippingOption* BuildShippingOptionForTest( 60 PaymentTestDataToChange = kPaymentTestDataNone, 61 PaymentTestModificationType = kPaymentTestOverwriteValue, 62 const String& value_to_use = String()); 63 64 PaymentDetailsModifier* BuildPaymentDetailsModifierForTest( 65 PaymentTestDetailToChange = kPaymentTestDetailNone, 66 PaymentTestDataToChange = kPaymentTestDataNone, 67 PaymentTestModificationType = kPaymentTestOverwriteValue, 68 const String& value_to_use = String()); 69 70 PaymentDetailsInit* BuildPaymentDetailsInitForTest( 71 PaymentTestDetailToChange = kPaymentTestDetailNone, 72 PaymentTestDataToChange = kPaymentTestDataNone, 73 PaymentTestModificationType = kPaymentTestOverwriteValue, 74 const String& value_to_use = String()); 75 76 PaymentDetailsUpdate* BuildPaymentDetailsUpdateForTest( 77 PaymentTestDetailToChange = kPaymentTestDetailNone, 78 PaymentTestDataToChange = kPaymentTestDataNone, 79 PaymentTestModificationType = kPaymentTestOverwriteValue, 80 const String& value_to_use = String()); 81 82 PaymentDetailsUpdate* BuildPaymentDetailsErrorMsgForTest( 83 const String& value_to_use = String()); 84 85 HeapVector<Member<PaymentMethodData>> BuildPaymentMethodDataForTest(); 86 87 payments::mojom::blink::PaymentResponsePtr BuildPaymentResponseForTest(); 88 89 payments::mojom::blink::PaymentAddressPtr BuildPaymentAddressForTest(); 90 91 class PaymentRequestV8TestingScope : public V8TestingScope { 92 STACK_ALLOCATED(); 93 94 public: 95 PaymentRequestV8TestingScope(); 96 }; 97 98 class PaymentRequestMockFunctionScope { 99 STACK_ALLOCATED(); 100 101 public: 102 explicit PaymentRequestMockFunctionScope(ScriptState*); 103 ~PaymentRequestMockFunctionScope(); 104 105 v8::Local<v8::Function> ExpectCall(); 106 v8::Local<v8::Function> ExpectCall(String* captor); 107 v8::Local<v8::Function> ExpectNoCall(); 108 109 private: 110 class MockFunction : public ScriptFunction { 111 public: 112 explicit MockFunction(ScriptState*); 113 MockFunction(ScriptState*, String* captor); 114 v8::Local<v8::Function> Bind(); 115 MOCK_METHOD1(Call, ScriptValue(ScriptValue)); 116 String* value_; 117 }; 118 119 ScriptState* script_state_; 120 Vector<Persistent<MockFunction>> mock_functions_; 121 }; 122 123 } // namespace blink 124 125 #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_TEST_HELPER_H_ 126