| 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/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | 38 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); |
| 39 } | 39 } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 OwnPtr<DummyPageHolder> m_page; | 42 OwnPtr<DummyPageHolder> m_page; |
| 43 TrackExceptionState m_exceptionState; | 43 TrackExceptionState m_exceptionState; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 46 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 47 { | 47 { |
| 48 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 48 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(true), getExceptionState()); |
| 49 | 49 |
| 50 EXPECT_FALSE(getExceptionState().hadException()); | 50 EXPECT_FALSE(getExceptionState().hadException()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST_F(PaymentRequestTest, SecureContextRequired) | 53 TEST_F(PaymentRequestTest, SecureContextRequired) |
| 54 { | 54 { |
| 55 setSecurityOrigin("http://www.example.com"); | 55 setSecurityOrigin("http://www.example.com"); |
| 56 | 56 |
| 57 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 57 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(true), getExceptionState()); |
| 58 | 58 |
| 59 EXPECT_TRUE(getExceptionState().hadException()); | 59 EXPECT_TRUE(getExceptionState().hadException()); |
| 60 EXPECT_EQ(SecurityError, getExceptionState().code()); | 60 EXPECT_EQ(SecurityError, getExceptionState().code()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(PaymentRequestTest, SupportedMethodListRequired) | 63 TEST_F(PaymentRequestTest, SupportedMethodListRequired) |
| 64 { | 64 { |
| 65 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai
lsForTest(), getExceptionState()); | 65 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai
lsForTest(true), getExceptionState()); |
| 66 | 66 |
| 67 EXPECT_TRUE(getExceptionState().hadException()); | 67 EXPECT_TRUE(getExceptionState().hadException()); |
| 68 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 68 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(PaymentRequestTest, ItemListRequired) | 71 TEST_F(PaymentRequestTest, ItemListRequired) |
| 72 { | 72 { |
| 73 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe
tails(), getExceptionState()); | 73 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe
tails(), getExceptionState()); |
| 74 | 74 |
| 75 EXPECT_TRUE(getExceptionState().hadException()); | 75 EXPECT_TRUE(getExceptionState().hadException()); |
| 76 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 76 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) | 79 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) |
| 80 { | 80 { |
| 81 PaymentDetails emptyItems; | 81 PaymentDetails emptyItems; |
| 82 emptyItems.setItems(HeapVector<PaymentItem>()); | 82 emptyItems.setItems(HeapVector<PaymentItem>()); |
| 83 | 83 |
| 84 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), emptyItem
s, getExceptionState()); | 84 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), emptyItem
s, getExceptionState()); |
| 85 | 85 |
| 86 EXPECT_TRUE(getExceptionState().hadException()); | 86 EXPECT_TRUE(getExceptionState().hadException()); |
| 87 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 87 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) | 90 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) |
| 91 { | 91 { |
| 92 PaymentDetails details = buildPaymentDetailsForTest(); | 92 PaymentDetails details = buildPaymentDetailsForTest(false); |
| 93 details.setShippingOptions(HeapVector<ShippingOption>()); | 93 details.setShippingOptions(HeapVector<ShippingOption>()); |
| 94 | 94 |
| 95 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 95 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); |
| 96 | 96 |
| 97 EXPECT_TRUE(request->shippingOption().isNull()); | 97 EXPECT_TRUE(request->shippingOption().isNull()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) | 100 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) |
| 101 { | 101 { |
| 102 PaymentDetails details = buildPaymentDetailsForTest(); | 102 PaymentDetails details = buildPaymentDetailsForTest(true); |
| 103 EXPECT_LE(2U, details.shippingOptions().size()); | 103 EXPECT_LE(2U, details.shippingOptions().size()); |
| 104 | 104 |
| 105 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 105 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); |
| 106 | 106 |
| 107 EXPECT_TRUE(request->shippingOption().isNull()); | 107 EXPECT_TRUE(request->shippingOption().isNull()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOption) | 110 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOption) |
| 111 { | 111 { |
| 112 CurrencyAmount amount; | 112 CurrencyAmount amount; |
| 113 amount.setCurrencyCode("USD"); | 113 amount.setCurrencyCode("USD"); |
| 114 amount.setValue("10.00"); | 114 amount.setValue("10.00"); |
| 115 ShippingOption option; | 115 ShippingOption option; |
| 116 option.setAmount(amount); | 116 option.setAmount(amount); |
| 117 option.setId("standard"); | 117 option.setId("standard"); |
| 118 option.setLabel("Standard shipping"); | 118 option.setLabel("Standard shipping"); |
| 119 PaymentDetails details = buildPaymentDetailsForTest(); | 119 PaymentDetails details = buildPaymentDetailsForTest(true); |
| 120 details.setShippingOptions(HeapVector<ShippingOption>(1, option)); | 120 details.setShippingOptions(HeapVector<ShippingOption>(1, option)); |
| 121 | 121 |
| 122 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 122 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); |
| 123 | 123 |
| 124 EXPECT_EQ("standard", request->shippingOption()); | 124 EXPECT_EQ("standard", request->shippingOption()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | 127 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) |
| 128 { | 128 { |
| 129 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 129 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(true), getExceptionState()); |
| 130 EXPECT_FALSE(getExceptionState().hadException()); | 130 EXPECT_FALSE(getExceptionState().hadException()); |
| 131 | 131 |
| 132 request->abort(getExceptionState()); | 132 request->abort(getExceptionState()); |
| 133 EXPECT_TRUE(getExceptionState().hadException()); | 133 EXPECT_TRUE(getExceptionState().hadException()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 } // namespace blink | 137 } // namespace blink |
| OLD | NEW |