| 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/PaymentResponse.h" | 5 #include "modules/payments/PaymentResponse.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 ScriptPromise m_dummyPromise; | 40 ScriptPromise m_dummyPromise; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 TEST(PaymentResponseTest, DataCopiedOver) | 43 TEST(PaymentResponseTest, DataCopiedOver) |
| 44 { | 44 { |
| 45 V8TestingScope scope; | 45 V8TestingScope scope; |
| 46 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest(); | 46 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest(); |
| 47 input->method_name = "foo"; | 47 input->method_name = "foo"; |
| 48 input->total_amount->currency = "USD"; | |
| 49 input->total_amount->value = "5.00"; | |
| 50 input->stringified_details = "{\"transactionId\": 123}"; | 48 input->stringified_details = "{\"transactionId\": 123}"; |
| 51 input->shipping_option = "standardShippingOption"; | 49 input->shipping_option = "standardShippingOption"; |
| 52 input->payer_email = "abc@gmail.com"; | 50 input->payer_email = "abc@gmail.com"; |
| 53 input->payer_phone = "0123"; | 51 input->payer_phone = "0123"; |
| 54 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; | 52 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| 55 | 53 |
| 56 PaymentResponse output(std::move(input), completeCallback); | 54 PaymentResponse output(std::move(input), completeCallback); |
| 57 | 55 |
| 58 EXPECT_EQ("foo", output.methodName()); | 56 EXPECT_EQ("foo", output.methodName()); |
| 59 EXPECT_EQ("standardShippingOption", output.shippingOption()); | 57 EXPECT_EQ("standardShippingOption", output.shippingOption()); |
| 60 EXPECT_EQ("abc@gmail.com", output.payerEmail()); | 58 EXPECT_EQ("abc@gmail.com", output.payerEmail()); |
| 61 EXPECT_EQ("0123", output.payerPhone()); | 59 EXPECT_EQ("0123", output.payerPhone()); |
| 62 | 60 |
| 63 PaymentCurrencyAmount totalAmount; | |
| 64 output.totalAmount(totalAmount); | |
| 65 EXPECT_EQ("USD", totalAmount.currency()); | |
| 66 EXPECT_EQ("5.00", totalAmount.value()); | |
| 67 | |
| 68 ScriptValue details = output.details(scope.getScriptState(), scope.getExcept
ionState()); | 61 ScriptValue details = output.details(scope.getScriptState(), scope.getExcept
ionState()); |
| 69 | 62 |
| 70 ASSERT_FALSE(scope.getExceptionState().hadException()); | 63 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 71 ASSERT_TRUE(details.v8Value()->IsObject()); | 64 ASSERT_TRUE(details.v8Value()->IsObject()); |
| 72 | 65 |
| 73 ScriptValue transactionId(scope.getScriptState(), details.v8Value().As<v8::O
bject>()->Get(v8String(scope.getScriptState()->isolate(), "transactionId"))); | 66 ScriptValue transactionId(scope.getScriptState(), details.v8Value().As<v8::O
bject>()->Get(v8String(scope.getScriptState()->isolate(), "transactionId"))); |
| 74 | 67 |
| 75 ASSERT_TRUE(transactionId.v8Value()->IsNumber()); | 68 ASSERT_TRUE(transactionId.v8Value()->IsNumber()); |
| 76 EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value()); | 69 EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value()); |
| 77 } | 70 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; | 92 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| 100 PaymentResponse output(std::move(input), completeCallback); | 93 PaymentResponse output(std::move(input), completeCallback); |
| 101 | 94 |
| 102 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Fail)); | 95 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Fail)); |
| 103 | 96 |
| 104 output.complete(scope.getScriptState(), "fail"); | 97 output.complete(scope.getScriptState(), "fail"); |
| 105 } | 98 } |
| 106 | 99 |
| 107 } // namespace | 100 } // namespace |
| 108 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |