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