| 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/JSONValuesForV8.h" | 7 #include "bindings/core/v8/JSONValuesForV8.h" |
| 8 #include "bindings/core/v8/ScriptFunction.h" | |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "bindings/modules/v8/V8PaymentResponse.h" | |
| 11 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| 13 #include "modules/payments/PaymentAddress.h" | 11 #include "modules/payments/PaymentAddress.h" |
| 14 #include "modules/payments/PaymentResponse.h" | |
| 15 #include "modules/payments/PaymentTestHelper.h" | 12 #include "modules/payments/PaymentTestHelper.h" |
| 16 #include "platform/heap/HeapAllocator.h" | 13 #include "platform/heap/HeapAllocator.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include <utility> | |
| 19 | 15 |
| 20 namespace blink { | 16 namespace blink { |
| 21 namespace { | 17 namespace { |
| 22 | 18 |
| 23 TEST(PaymentRequestTest, SecureContextRequired) | 19 TEST(PaymentRequestTest, SecureContextRequired) |
| 24 { | 20 { |
| 25 V8TestingScope scope; | 21 V8TestingScope scope; |
| 26 scope.document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "http
://www.example.com/"))); | 22 scope.document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "http
://www.example.com/"))); |
| 27 | 23 |
| 28 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest
(), buildPaymentDetailsForTest(), scope.getExceptionState()); | 24 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest
(), buildPaymentDetailsForTest(), scope.getExceptionState()); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 191 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 196 makePaymentRequestOriginSecure(scope.document()); | 192 makePaymentRequestOriginSecure(scope.document()); |
| 197 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 193 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 198 EXPECT_FALSE(scope.getExceptionState().hadException()); | 194 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 199 | 195 |
| 200 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 196 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 201 | 197 |
| 202 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); | 198 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); |
| 203 } | 199 } |
| 204 | 200 |
| 205 TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShippin
gAddressInResponse) | |
| 206 { | |
| 207 V8TestingScope scope; | |
| 208 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 209 makePaymentRequestOriginSecure(scope.document()); | |
| 210 PaymentOptions options; | |
| 211 options.setRequestShipping(true); | |
| 212 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 213 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 214 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | |
| 215 | |
| 216 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 217 | |
| 218 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 219 } | |
| 220 | |
| 221 TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShipp
ingAddressInResponse) | |
| 222 { | |
| 223 V8TestingScope scope; | |
| 224 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 225 makePaymentRequestOriginSecure(scope.document()); | |
| 226 PaymentOptions options; | |
| 227 options.setRequestShipping(true); | |
| 228 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 229 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 230 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | |
| 231 response->shipping_address = mojom::blink::PaymentAddress::New(); | |
| 232 | |
| 233 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 234 | |
| 235 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 236 } | |
| 237 | |
| 238 TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingAdd
ressExistsInResponse) | |
| 239 { | |
| 240 V8TestingScope scope; | |
| 241 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 242 makePaymentRequestOriginSecure(scope.document()); | |
| 243 PaymentOptions options; | |
| 244 options.setRequestShipping(false); | |
| 245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 246 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 247 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 248 response->shipping_address = mojom::blink::PaymentAddress::New(); | |
| 249 response->shipping_address->country = "US"; | |
| 250 response->shipping_address->language_code = "en"; | |
| 251 response->shipping_address->script_code = "Latn"; | |
| 252 | |
| 253 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 254 | |
| 255 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 256 } | |
| 257 | |
| 258 class PaymentResponseFunction : public ScriptFunction { | |
| 259 public: | |
| 260 static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptValue*
outValue) | |
| 261 { | |
| 262 PaymentResponseFunction* self = new PaymentResponseFunction(scriptState,
outValue); | |
| 263 return self->bindToV8Function(); | |
| 264 } | |
| 265 | |
| 266 ScriptValue call(ScriptValue value) override | |
| 267 { | |
| 268 DCHECK(!value.isEmpty()); | |
| 269 *m_value = value; | |
| 270 return value; | |
| 271 } | |
| 272 | |
| 273 private: | |
| 274 PaymentResponseFunction(ScriptState* scriptState, ScriptValue* outValue) | |
| 275 : ScriptFunction(scriptState) | |
| 276 , m_value(outValue) | |
| 277 { | |
| 278 DCHECK(m_value); | |
| 279 } | |
| 280 | |
| 281 ScriptValue* m_value; | |
| 282 }; | |
| 283 | |
| 284 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShippi
ngAddressInResponse) | |
| 285 { | |
| 286 V8TestingScope scope; | |
| 287 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 288 makePaymentRequestOriginSecure(scope.document()); | |
| 289 PaymentOptions options; | |
| 290 options.setRequestShipping(true); | |
| 291 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 292 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 293 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | |
| 294 response->shipping_address = mojom::blink::PaymentAddress::New(); | |
| 295 response->shipping_address->country = "US"; | |
| 296 response->shipping_address->language_code = "en"; | |
| 297 response->shipping_address->script_code = "Latn"; | |
| 298 | |
| 299 ScriptValue outValue; | |
| 300 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 301 | |
| 302 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 303 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 304 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 305 | |
| 306 EXPECT_EQ("US", pr->shippingAddress()->country()); | |
| 307 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); | |
| 308 } | |
| 309 | |
| 310 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShipp
ingAddressInResponse) | |
| 311 { | |
| 312 V8TestingScope scope; | |
| 313 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 314 makePaymentRequestOriginSecure(scope.document()); | |
| 315 PaymentOptions options; | |
| 316 options.setRequestShipping(false); | |
| 317 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 318 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 319 | |
| 320 ScriptValue outValue; | |
| 321 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 322 | |
| 323 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | |
| 324 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 325 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 326 | |
| 327 EXPECT_EQ(nullptr, pr->shippingAddress()); | |
| 328 } | |
| 329 | |
| 330 TEST(PaymentRequestTest, OnShippingOptionChange) | 201 TEST(PaymentRequestTest, OnShippingOptionChange) |
| 331 { | 202 { |
| 332 V8TestingScope scope; | 203 V8TestingScope scope; |
| 333 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 204 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 334 makePaymentRequestOriginSecure(scope.document()); | 205 makePaymentRequestOriginSecure(scope.document()); |
| 335 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 206 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 336 EXPECT_FALSE(scope.getExceptionState().hadException()); | 207 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 337 | 208 |
| 338 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tNoCall()); | 209 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tNoCall()); |
| 339 | 210 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 407 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 537 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 408 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 538 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 409 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 539 | 410 |
| 540 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 411 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
| 541 EXPECT_FALSE(scope.getExceptionState().hadException()); | 412 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 542 | 413 |
| 543 EXPECT_EQ("fast", request->shippingOption()); | 414 EXPECT_EQ("fast", request->shippingOption()); |
| 544 } | 415 } |
| 545 | 416 |
| 546 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPaye
rEmailInResponse) | |
| 547 { | |
| 548 V8TestingScope scope; | |
| 549 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 550 makePaymentRequestOriginSecure(scope.document()); | |
| 551 PaymentOptions options; | |
| 552 options.setRequestPayerEmail(true); | |
| 553 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 554 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 555 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 556 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 557 response->payer_email = "abc@gmail.com"; | |
| 558 | |
| 559 ScriptValue outValue; | |
| 560 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 561 | |
| 562 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 563 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 564 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 565 | |
| 566 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | |
| 567 } | |
| 568 | |
| 569 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayer
EmailInResponse) | |
| 570 { | |
| 571 V8TestingScope scope; | |
| 572 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 573 makePaymentRequestOriginSecure(scope.document()); | |
| 574 PaymentOptions options; | |
| 575 options.setRequestPayerEmail(true); | |
| 576 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 577 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 578 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 579 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 580 response->payer_email = ""; | |
| 581 | |
| 582 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 583 | |
| 584 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 585 } | |
| 586 | |
| 587 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerE
mailInResponse) | |
| 588 { | |
| 589 V8TestingScope scope; | |
| 590 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 591 makePaymentRequestOriginSecure(scope.document()); | |
| 592 PaymentOptions options; | |
| 593 options.setRequestPayerEmail(true); | |
| 594 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 595 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 596 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 597 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 598 response->payer_email = String(); | |
| 599 | |
| 600 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 601 | |
| 602 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 603 } | |
| 604 | |
| 605 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNullPa
yerEmailInResponse) | |
| 606 { | |
| 607 V8TestingScope scope; | |
| 608 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 609 makePaymentRequestOriginSecure(scope.document()); | |
| 610 PaymentOptions options; | |
| 611 options.setRequestPayerEmail(false); | |
| 612 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 613 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 614 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 615 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 616 response->payer_email = ""; | |
| 617 | |
| 618 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 619 | |
| 620 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 621 } | |
| 622 | |
| 623 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPaye
rEmailInResponse) | |
| 624 { | |
| 625 V8TestingScope scope; | |
| 626 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 627 makePaymentRequestOriginSecure(scope.document()); | |
| 628 PaymentOptions options; | |
| 629 options.setRequestPayerEmail(false); | |
| 630 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 631 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 632 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 633 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 634 response->payer_email = String(); | |
| 635 | |
| 636 ScriptValue outValue; | |
| 637 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 638 | |
| 639 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 640 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 641 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 642 | |
| 643 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 644 } | |
| 645 | |
| 646 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPaye
rPhoneInResponse) | |
| 647 { | |
| 648 V8TestingScope scope; | |
| 649 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 650 makePaymentRequestOriginSecure(scope.document()); | |
| 651 PaymentOptions options; | |
| 652 options.setRequestPayerPhone(true); | |
| 653 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 654 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 655 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 656 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 657 response->payer_phone = "0123"; | |
| 658 | |
| 659 ScriptValue outValue; | |
| 660 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 661 | |
| 662 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 663 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 664 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 665 | |
| 666 EXPECT_EQ("0123", pr->payerPhone()); | |
| 667 } | |
| 668 | |
| 669 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayer
PhoneInResponse) | |
| 670 { | |
| 671 V8TestingScope scope; | |
| 672 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 673 makePaymentRequestOriginSecure(scope.document()); | |
| 674 PaymentOptions options; | |
| 675 options.setRequestPayerPhone(true); | |
| 676 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 677 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 678 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 679 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 680 response->payer_phone = ""; | |
| 681 | |
| 682 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 683 | |
| 684 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 685 } | |
| 686 | |
| 687 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerP
honeInResponse) | |
| 688 { | |
| 689 V8TestingScope scope; | |
| 690 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 691 makePaymentRequestOriginSecure(scope.document()); | |
| 692 PaymentOptions options; | |
| 693 options.setRequestPayerPhone(true); | |
| 694 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 695 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 696 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 697 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 698 response->payer_phone = String(); | |
| 699 | |
| 700 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 701 | |
| 702 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 703 } | |
| 704 | |
| 705 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulPay
erPhoneInResponse) | |
| 706 { | |
| 707 V8TestingScope scope; | |
| 708 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 709 makePaymentRequestOriginSecure(scope.document()); | |
| 710 PaymentOptions options; | |
| 711 options.setRequestPayerPhone(false); | |
| 712 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 713 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 714 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 715 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 716 response->payer_phone = ""; | |
| 717 | |
| 718 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | |
| 719 | |
| 720 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 721 } | |
| 722 | |
| 723 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPaye
rPhoneInResponse) | |
| 724 { | |
| 725 V8TestingScope scope; | |
| 726 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 727 makePaymentRequestOriginSecure(scope.document()); | |
| 728 PaymentOptions options; | |
| 729 options.setRequestPayerPhone(false); | |
| 730 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | |
| 731 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 732 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | |
| 733 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); | |
| 734 response->payer_phone = String(); | |
| 735 | |
| 736 ScriptValue outValue; | |
| 737 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 738 | |
| 739 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | |
| 740 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 741 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | |
| 742 | |
| 743 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 744 } | |
| 745 | |
| 746 } // namespace | 417 } // namespace |
| 747 } // namespace blink | 418 } // namespace blink |
| OLD | NEW |