| 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 "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
| 12 #include "modules/payments/CurrencyAmount.h" | 12 #include "modules/payments/CurrencyAmount.h" |
| 13 #include "modules/payments/PaymentDetailsTestHelper.h" | |
| 14 #include "modules/payments/PaymentItem.h" | 13 #include "modules/payments/PaymentItem.h" |
| 14 #include "modules/payments/PaymentTestHelper.h" |
| 15 #include "modules/payments/ShippingOption.h" | 15 #include "modules/payments/ShippingOption.h" |
| 16 #include "platform/heap/HeapAllocator.h" | 16 #include "platform/heap/HeapAllocator.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "wtf/OwnPtr.h" | 19 #include "wtf/OwnPtr.h" |
| 20 #include <utility> | 20 #include <utility> |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | 40 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 OwnPtr<DummyPageHolder> m_page; | 44 OwnPtr<DummyPageHolder> m_page; |
| 45 TrackExceptionState m_exceptionState; | 45 TrackExceptionState m_exceptionState; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 48 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 49 { | 49 { |
| 50 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 50 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 51 | 51 |
| 52 EXPECT_FALSE(getExceptionState().hadException()); | 52 EXPECT_FALSE(getExceptionState().hadException()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST_F(PaymentRequestTest, SecureContextRequired) | 55 TEST_F(PaymentRequestTest, SecureContextRequired) |
| 56 { | 56 { |
| 57 setSecurityOrigin("http://www.example.com"); | 57 setSecurityOrigin("http://www.example.com"); |
| 58 | 58 |
| 59 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 59 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 60 | 60 |
| 61 EXPECT_TRUE(getExceptionState().hadException()); | 61 EXPECT_TRUE(getExceptionState().hadException()); |
| 62 EXPECT_EQ(SecurityError, getExceptionState().code()); | 62 EXPECT_EQ(SecurityError, getExceptionState().code()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST_F(PaymentRequestTest, SupportedMethodListRequired) | 65 TEST_F(PaymentRequestTest, SupportedMethodListRequired) |
| 66 { | 66 { |
| 67 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai
lsForTest(), getExceptionState()); | 67 PaymentRequest::create(getScriptState(), HeapVector<PaymentMethodData>(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 68 | 68 |
| 69 EXPECT_TRUE(getExceptionState().hadException()); | 69 EXPECT_TRUE(getExceptionState().hadException()); |
| 70 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 70 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST_F(PaymentRequestTest, ItemListRequired) | 73 TEST_F(PaymentRequestTest, ItemListRequired) |
| 74 { | 74 { |
| 75 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe
tails(), getExceptionState()); | 75 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), Pa
ymentDetails(), getExceptionState()); |
| 76 | 76 |
| 77 EXPECT_TRUE(getExceptionState().hadException()); | 77 EXPECT_TRUE(getExceptionState().hadException()); |
| 78 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 78 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST_F(PaymentRequestTest, ItemListIsNotEmpty) | 81 TEST_F(PaymentRequestTest, ItemListIsNotEmpty) |
| 82 { | 82 { |
| 83 PaymentDetails details; | 83 PaymentDetails details; |
| 84 details.setItems(HeapVector<PaymentItem>()); | 84 details.setItems(HeapVector<PaymentItem>()); |
| 85 | 85 |
| 86 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details,
getExceptionState()); | 86 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), de
tails, getExceptionState()); |
| 87 | 87 |
| 88 EXPECT_TRUE(getExceptionState().hadException()); | 88 EXPECT_TRUE(getExceptionState().hadException()); |
| 89 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 89 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) | 92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) |
| 93 { | 93 { |
| 94 PaymentDetails details; | 94 PaymentDetails details; |
| 95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
| 96 | 96 |
| 97 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details,
getExceptionState()); | 97 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), de
tails, getExceptionState()); |
| 98 | 98 |
| 99 EXPECT_TRUE(getExceptionState().hadException()); | 99 EXPECT_TRUE(getExceptionState().hadException()); |
| 100 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 100 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) | 103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) |
| 104 { | 104 { |
| 105 PaymentDetails details; | 105 PaymentDetails details; |
| 106 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 106 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 107 PaymentOptions options; | 107 PaymentOptions options; |
| 108 options.setRequestShipping(true); | 108 options.setRequestShipping(true); |
| 109 | 109 |
| 110 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 110 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 111 | 111 |
| 112 EXPECT_TRUE(request->shippingOption().isNull()); | 112 EXPECT_TRUE(request->shippingOption().isNull()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) | 115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) |
| 116 { | 116 { |
| 117 PaymentDetails details; | 117 PaymentDetails details; |
| 118 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 118 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
| 120 PaymentOptions options; | 120 PaymentOptions options; |
| 121 options.setRequestShipping(true); | 121 options.setRequestShipping(true); |
| 122 | 122 |
| 123 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 123 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 124 | 124 |
| 125 EXPECT_TRUE(request->shippingOption().isNull()); | 125 EXPECT_TRUE(request->shippingOption().isNull()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
ted) | 128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
ted) |
| 129 { | 129 { |
| 130 PaymentDetails details; | 130 PaymentDetails details; |
| 131 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 131 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 133 PaymentOptions options; | 133 PaymentOptions options; |
| 134 options.setRequestShipping(true); | 134 options.setRequestShipping(true); |
| 135 | 135 |
| 136 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 136 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 137 | 137 |
| 138 EXPECT_EQ("standard", request->shippingOption()); | 138 EXPECT_EQ("standard", request->shippingOption()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) | 141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) |
| 142 { | 142 { |
| 143 PaymentDetails details; | 143 PaymentDetails details; |
| 144 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 144 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 146 | 146 |
| 147 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 147 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, getExceptionState()); |
| 148 | 148 |
| 149 EXPECT_TRUE(request->shippingOption().isNull()); | 149 EXPECT_TRUE(request->shippingOption().isNull()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) | 152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) |
| 153 { | 153 { |
| 154 PaymentDetails details; | 154 PaymentDetails details; |
| 155 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 155 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
| 157 PaymentOptions options; | 157 PaymentOptions options; |
| 158 options.setRequestShipping(false); | 158 options.setRequestShipping(false); |
| 159 | 159 |
| 160 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 160 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 161 | 161 |
| 162 EXPECT_TRUE(request->shippingOption().isNull()); | 162 EXPECT_TRUE(request->shippingOption().isNull()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | 165 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) |
| 166 { | 166 { |
| 167 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 167 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 168 EXPECT_FALSE(getExceptionState().hadException()); | 168 EXPECT_FALSE(getExceptionState().hadException()); |
| 169 | 169 |
| 170 request->abort(getExceptionState()); | 170 request->abort(getExceptionState()); |
| 171 EXPECT_TRUE(getExceptionState().hadException()); | 171 EXPECT_TRUE(getExceptionState().hadException()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 class MockFunction : public ScriptFunction { | 174 class MockFunction : public ScriptFunction { |
| 175 public: | 175 public: |
| 176 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) | 176 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) |
| 177 { | 177 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 199 { | 199 { |
| 200 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); | 200 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 MOCK_METHOD1(call, ScriptValue(ScriptValue)); | 203 MOCK_METHOD1(call, ScriptValue(ScriptValue)); |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 TEST_F(PaymentRequestTest, CanAbortAfterShow) | 206 TEST_F(PaymentRequestTest, CanAbortAfterShow) |
| 207 { | 207 { |
| 208 ScriptState::Scope scope(getScriptState()); | 208 ScriptState::Scope scope(getScriptState()); |
| 209 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 209 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 210 EXPECT_FALSE(getExceptionState().hadException()); | 210 EXPECT_FALSE(getExceptionState().hadException()); |
| 211 | 211 |
| 212 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); | 212 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); |
| 213 request->abort(getExceptionState()); | 213 request->abort(getExceptionState()); |
| 214 | 214 |
| 215 EXPECT_FALSE(getExceptionState().hadException()); | 215 EXPECT_FALSE(getExceptionState().hadException()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) | 218 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) |
| 219 { | 219 { |
| 220 ScriptState::Scope scope(getScriptState()); | 220 ScriptState::Scope scope(getScriptState()); |
| 221 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 221 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 222 EXPECT_FALSE(getExceptionState().hadException()); | 222 EXPECT_FALSE(getExceptionState().hadException()); |
| 223 | 223 |
| 224 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 224 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 225 | 225 |
| 226 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); | 226 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); |
| 227 } | 227 } |
| 228 | 228 |
| 229 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddressInResponse) | 229 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddressInResponse) |
| 230 { | 230 { |
| 231 ScriptState::Scope scope(getScriptState()); | 231 ScriptState::Scope scope(getScriptState()); |
| 232 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 232 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 233 EXPECT_FALSE(getExceptionState().hadException()); | 233 EXPECT_FALSE(getExceptionState().hadException()); |
| 234 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 234 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 235 response->shipping_address = mojom::blink::PaymentAddress::New(); | 235 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 236 | 236 |
| 237 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 237 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 238 | 238 |
| 239 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 239 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) | 242 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) |
| 243 { | 243 { |
| 244 ScriptState::Scope scope(getScriptState()); | 244 ScriptState::Scope scope(getScriptState()); |
| 245 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 245 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 246 EXPECT_FALSE(getExceptionState().hadException()); | 246 EXPECT_FALSE(getExceptionState().hadException()); |
| 247 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); | 247 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); |
| 248 shippingAddress->region_code = "US"; | 248 shippingAddress->region_code = "US"; |
| 249 shippingAddress->language_code = "en"; | 249 shippingAddress->language_code = "en"; |
| 250 shippingAddress->script_code = "Latn"; | 250 shippingAddress->script_code = "Latn"; |
| 251 | 251 |
| 252 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 252 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 253 | 253 |
| 254 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); | 254 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) | 257 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) |
| 258 { | 258 { |
| 259 ScriptState::Scope scope(getScriptState()); | 259 ScriptState::Scope scope(getScriptState()); |
| 260 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 260 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 261 EXPECT_FALSE(getExceptionState().hadException()); | 261 EXPECT_FALSE(getExceptionState().hadException()); |
| 262 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 262 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 263 response->shipping_address = mojom::blink::PaymentAddress::New(); | 263 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 264 response->shipping_address->region_code = "US"; | 264 response->shipping_address->region_code = "US"; |
| 265 response->shipping_address->language_code = "en"; | 265 response->shipping_address->language_code = "en"; |
| 266 response->shipping_address->script_code = "Latn"; | 266 response->shipping_address->script_code = "Latn"; |
| 267 | 267 |
| 268 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 268 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 269 | 269 |
| 270 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 270 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) | 273 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) |
| 274 { | 274 { |
| 275 ScriptState::Scope scope(getScriptState()); | 275 ScriptState::Scope scope(getScriptState()); |
| 276 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 276 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 277 EXPECT_FALSE(getExceptionState().hadException()); | 277 EXPECT_FALSE(getExceptionState().hadException()); |
| 278 | 278 |
| 279 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 279 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 280 | 280 |
| 281 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 281 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(PaymentRequestTest, OnShippingOptionChange) | 284 TEST_F(PaymentRequestTest, OnShippingOptionChange) |
| 285 { | 285 { |
| 286 ScriptState::Scope scope(getScriptState()); | 286 ScriptState::Scope scope(getScriptState()); |
| 287 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 287 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 288 EXPECT_FALSE(getExceptionState().hadException()); | 288 EXPECT_FALSE(getExceptionState().hadException()); |
| 289 | 289 |
| 290 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 290 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 291 | 291 |
| 292 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); | 292 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); |
| 293 } | 293 } |
| 294 | 294 |
| 295 TEST_F(PaymentRequestTest, CannotCallShowTwice) | 295 TEST_F(PaymentRequestTest, CannotCallShowTwice) |
| 296 { | 296 { |
| 297 ScriptState::Scope scope(getScriptState()); | 297 ScriptState::Scope scope(getScriptState()); |
| 298 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 298 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 299 EXPECT_FALSE(getExceptionState().hadException()); | 299 EXPECT_FALSE(getExceptionState().hadException()); |
| 300 request->show(getScriptState()); | 300 request->show(getScriptState()); |
| 301 | 301 |
| 302 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 302 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 303 } | 303 } |
| 304 | 304 |
| 305 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) | 305 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) |
| 306 { | 306 { |
| 307 ScriptState::Scope scope(getScriptState()); | 307 ScriptState::Scope scope(getScriptState()); |
| 308 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 308 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 309 EXPECT_FALSE(getExceptionState().hadException()); | 309 EXPECT_FALSE(getExceptionState().hadException()); |
| 310 request->show(getScriptState()); | 310 request->show(getScriptState()); |
| 311 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 311 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 312 request->complete(getScriptState(), false); | 312 request->complete(getScriptState(), false); |
| 313 | 313 |
| 314 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 314 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 315 } | 315 } |
| 316 | 316 |
| 317 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) | 317 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) |
| 318 { | 318 { |
| 319 ScriptState::Scope scope(getScriptState()); | 319 ScriptState::Scope scope(getScriptState()); |
| 320 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 320 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 321 EXPECT_FALSE(getExceptionState().hadException()); | 321 EXPECT_FALSE(getExceptionState().hadException()); |
| 322 | 322 |
| 323 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 323 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 324 | 324 |
| 325 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 325 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) | 328 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) |
| 329 { | 329 { |
| 330 ScriptState::Scope scope(getScriptState()); | 330 ScriptState::Scope scope(getScriptState()); |
| 331 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 331 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 332 EXPECT_FALSE(getExceptionState().hadException()); | 332 EXPECT_FALSE(getExceptionState().hadException()); |
| 333 request->show(getScriptState()); | 333 request->show(getScriptState()); |
| 334 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 334 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 335 | 335 |
| 336 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 336 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 337 | 337 |
| 338 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 338 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) | 341 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) |
| 342 { | 342 { |
| 343 ScriptState::Scope scope(getScriptState()); | 343 ScriptState::Scope scope(getScriptState()); |
| 344 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 344 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 345 EXPECT_FALSE(getExceptionState().hadException()); | 345 EXPECT_FALSE(getExceptionState().hadException()); |
| 346 request->show(getScriptState()); | 346 request->show(getScriptState()); |
| 347 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 347 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 348 | 348 |
| 349 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); | 349 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); |
| 350 | 350 |
| 351 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 351 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 354 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
| 355 { | 355 { |
| 356 ScriptState::Scope scope(getScriptState()); | 356 ScriptState::Scope scope(getScriptState()); |
| 357 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 357 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 358 EXPECT_FALSE(getExceptionState().hadException()); | 358 EXPECT_FALSE(getExceptionState().hadException()); |
| 359 | 359 |
| 360 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 360 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 361 | 361 |
| 362 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 362 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 365 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
| 366 { | 366 { |
| 367 ScriptState::Scope scope(getScriptState()); | 367 ScriptState::Scope scope(getScriptState()); |
| 368 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 368 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 369 EXPECT_FALSE(getExceptionState().hadException()); | 369 EXPECT_FALSE(getExceptionState().hadException()); |
| 370 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 370 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 371 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 371 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 372 | 372 |
| 373 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 373 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 374 | 374 |
| 375 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 375 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 376 } | 376 } |
| 377 | 377 |
| 378 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 378 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
| 379 { | 379 { |
| 380 ScriptState::Scope scope(getScriptState()); | 380 ScriptState::Scope scope(getScriptState()); |
| 381 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 381 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 382 EXPECT_FALSE(getExceptionState().hadException()); | 382 EXPECT_FALSE(getExceptionState().hadException()); |
| 383 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 383 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 384 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 384 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 385 | 385 |
| 386 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); | 386 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); |
| 387 } | 387 } |
| 388 | 388 |
| 389 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) | 389 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) |
| 390 { | 390 { |
| 391 ScriptState::Scope scope(getScriptState()); | 391 ScriptState::Scope scope(getScriptState()); |
| 392 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 392 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 393 EXPECT_FALSE(getExceptionState().hadException()); | 393 EXPECT_FALSE(getExceptionState().hadException()); |
| 394 | 394 |
| 395 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 395 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 396 | 396 |
| 397 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); | 397 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); |
| 398 } | 398 } |
| 399 | 399 |
| 400 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) | 400 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) |
| 401 { | 401 { |
| 402 ScriptState::Scope scope(getScriptState()); | 402 ScriptState::Scope scope(getScriptState()); |
| 403 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 403 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 404 EXPECT_FALSE(getExceptionState().hadException()); | 404 EXPECT_FALSE(getExceptionState().hadException()); |
| 405 | 405 |
| 406 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 406 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 407 | 407 |
| 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); | 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); |
| 409 EXPECT_FALSE(getExceptionState().hadException()); | 409 EXPECT_FALSE(getExceptionState().hadException()); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) | 412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) |
| 413 { | 413 { |
| 414 ScriptState::Scope scope(getScriptState()); | 414 ScriptState::Scope scope(getScriptState()); |
| 415 PaymentDetails details; | 415 PaymentDetails details; |
| 416 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 416 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 417 PaymentOptions options; | 417 PaymentOptions options; |
| 418 options.setRequestShipping(true); | 418 options.setRequestShipping(true); |
| 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 420 EXPECT_FALSE(getExceptionState().hadException()); | 420 EXPECT_FALSE(getExceptionState().hadException()); |
| 421 EXPECT_TRUE(request->shippingOption().isNull()); | 421 EXPECT_TRUE(request->shippingOption().isNull()); |
| 422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 423 String detailWithShippingOptions = "{\"items\": [{\"id\": \"total\", \"label
\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 423 String detailWithShippingOptions = "{\"items\": [{\"id\": \"total\", \"label
\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; |
| 425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); | 425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); |
| 426 EXPECT_FALSE(getExceptionState().hadException()); | 426 EXPECT_FALSE(getExceptionState().hadException()); |
| 427 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 427 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 428 String detailWithoutShippingOptions = "{\"items\": [{\"id\": \"total\", \"la
bel\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}"; | 428 String detailWithoutShippingOptions = "{\"items\": [{\"id\": \"total\", \"la
bel\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}"; |
| 429 | 429 |
| 430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); | 430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); |
| 431 | 431 |
| 432 EXPECT_FALSE(getExceptionState().hadException()); | 432 EXPECT_FALSE(getExceptionState().hadException()); |
| 433 EXPECT_TRUE(request->shippingOption().isNull()); | 433 EXPECT_TRUE(request->shippingOption().isNull()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
ShippingOptions) | 436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
ShippingOptions) |
| 437 { | 437 { |
| 438 ScriptState::Scope scope(getScriptState()); | 438 ScriptState::Scope scope(getScriptState()); |
| 439 PaymentOptions options; | 439 PaymentOptions options; |
| 440 options.setRequestShipping(true); | 440 options.setRequestShipping(true); |
| 441 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 441 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 442 EXPECT_FALSE(getExceptionState().hadException()); | 442 EXPECT_FALSE(getExceptionState().hadException()); |
| 443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 444 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 444 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; | 446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; |
| 447 | 447 |
| 448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 449 EXPECT_FALSE(getExceptionState().hadException()); | 449 EXPECT_FALSE(getExceptionState().hadException()); |
| 450 | 450 |
| 451 EXPECT_TRUE(request->shippingOption().isNull()); | 451 EXPECT_TRUE(request->shippingOption().isNull()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) | 454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) |
| 455 { | 455 { |
| 456 ScriptState::Scope scope(getScriptState()); | 456 ScriptState::Scope scope(getScriptState()); |
| 457 PaymentOptions options; | 457 PaymentOptions options; |
| 458 options.setRequestShipping(true); | 458 options.setRequestShipping(true); |
| 459 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 459 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 460 EXPECT_FALSE(getExceptionState().hadException()); | 460 EXPECT_FALSE(getExceptionState().hadException()); |
| 461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 462 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 462 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; |
| 464 | 464 |
| 465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 466 EXPECT_FALSE(getExceptionState().hadException()); | 466 EXPECT_FALSE(getExceptionState().hadException()); |
| 467 | 467 |
| 468 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 468 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 469 } | 469 } |
| 470 | 470 |
| 471 } // namespace | 471 } // namespace |
| 472 } // namespace blink | 472 } // namespace blink |
| OLD | NEW |