| 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" | 8 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "bindings/modules/v8/V8PaymentResponse.h" | 10 #include "bindings/modules/v8/V8PaymentResponse.h" |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 536 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 537 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 537 "\"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}]}"; | 538 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 539 | 539 |
| 540 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 540 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
| 541 EXPECT_FALSE(scope.getExceptionState().hadException()); | 541 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 542 | 542 |
| 543 EXPECT_EQ("fast", request->shippingOption()); | 543 EXPECT_EQ("fast", request->shippingOption()); |
| 544 } | 544 } |
| 545 | 545 |
| 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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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::CurrencyAmount::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 |
| 546 } // namespace | 746 } // namespace |
| 547 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |