| 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/PaymentRequest.h" | 5 #include "modules/payments/PaymentRequest.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/modules/v8/V8PaymentResponse.h" | 10 #include "bindings/modules/v8/V8PaymentResponse.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 13 #include "modules/payments/CurrencyAmount.h" | 13 #include "modules/payments/CurrencyAmount.h" |
| 14 #include "modules/payments/PaymentAddress.h" | 14 #include "modules/payments/PaymentAddress.h" |
| 15 #include "modules/payments/PaymentItem.h" | 15 #include "modules/payments/PaymentItem.h" |
| 16 #include "modules/payments/PaymentTestHelper.h" | 16 #include "modules/payments/PaymentTestHelper.h" |
| 17 #include "modules/payments/ShippingOption.h" | 17 #include "modules/payments/ShippingOption.h" |
| 18 #include "platform/heap/HeapAllocator.h" | 18 #include "platform/heap/HeapAllocator.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "wtf/OwnPtr.h" | 21 #include <memory> |
| 22 #include <utility> | 22 #include <utility> |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class PaymentRequestTest : public testing::Test { | 27 class PaymentRequestTest : public testing::Test { |
| 28 public: | 28 public: |
| 29 PaymentRequestTest() | 29 PaymentRequestTest() |
| 30 : m_page(DummyPageHolder::create()) | 30 : m_page(DummyPageHolder::create()) |
| 31 { | 31 { |
| 32 setSecurityOrigin("https://www.example.com/"); | 32 setSecurityOrigin("https://www.example.com/"); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ~PaymentRequestTest() override {} | 35 ~PaymentRequestTest() override {} |
| 36 | 36 |
| 37 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } | 37 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
| 38 ExceptionState& getExceptionState() { return m_exceptionState; } | 38 ExceptionState& getExceptionState() { return m_exceptionState; } |
| 39 | 39 |
| 40 void setSecurityOrigin(const String& securityOrigin) | 40 void setSecurityOrigin(const String& securityOrigin) |
| 41 { | 41 { |
| 42 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | 42 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 OwnPtr<DummyPageHolder> m_page; | 46 std::unique_ptr<DummyPageHolder> m_page; |
| 47 TrackExceptionState m_exceptionState; | 47 TrackExceptionState m_exceptionState; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 50 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 51 { | 51 { |
| 52 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); | 52 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 53 | 53 |
| 54 EXPECT_FALSE(getExceptionState().hadException()); | 54 EXPECT_FALSE(getExceptionState().hadException()); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 554 | 554 |
| 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 556 EXPECT_FALSE(getExceptionState().hadException()); | 556 EXPECT_FALSE(getExceptionState().hadException()); |
| 557 | 557 |
| 558 EXPECT_EQ("fast", request->shippingOption()); | 558 EXPECT_EQ("fast", request->shippingOption()); |
| 559 } | 559 } |
| 560 | 560 |
| 561 } // namespace | 561 } // namespace |
| 562 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |