Chromium Code Reviews| 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(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 556 response->payer_email = "abc@gmail.com"; | |
| 557 | |
| 558 ScriptValue outValue; | |
| 559 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 560 | |
| 561 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 562 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 563 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate() , outValue.v8Value()); | |
| 564 | |
| 565 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | |
| 566 } | |
| 567 | |
| 568 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayer EmailInResponse) | |
| 569 { | |
| 570 V8TestingScope scope; | |
| 571 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 572 makePaymentRequestOriginSecure(scope.document()); | |
| 573 PaymentOptions options; | |
| 574 options.setRequestPayerEmail(true); | |
| 575 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 576 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 577 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 578 response->payer_email = ""; | |
| 579 | |
| 580 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 581 | |
| 582 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 583 } | |
| 584 | |
| 585 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerE mailInResponse) | |
| 586 { | |
| 587 V8TestingScope scope; | |
| 588 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 589 makePaymentRequestOriginSecure(scope.document()); | |
| 590 PaymentOptions options; | |
| 591 options.setRequestPayerEmail(true); | |
| 592 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 593 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 594 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 595 response->payer_email = String(); | |
| 596 | |
| 597 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 598 | |
| 599 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 600 } | |
| 601 | |
| 602 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNullPa yerEmailInResponse) | |
| 603 { | |
| 604 V8TestingScope scope; | |
| 605 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 606 makePaymentRequestOriginSecure(scope.document()); | |
| 607 PaymentOptions options; | |
| 608 options.setRequestPayerEmail(false); | |
| 609 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 610 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 611 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 612 response->payer_email = ""; | |
| 613 | |
| 614 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 615 | |
| 616 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 617 } | |
| 618 | |
| 619 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPaye rEmailInResponse) | |
| 620 { | |
| 621 V8TestingScope scope; | |
| 622 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 623 makePaymentRequestOriginSecure(scope.document()); | |
| 624 PaymentOptions options; | |
| 625 options.setRequestPayerEmail(false); | |
| 626 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 627 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 628 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 629 response->payer_email = String(); | |
| 630 | |
| 631 ScriptValue outValue; | |
| 632 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 633 | |
| 634 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 635 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 636 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate() , outValue.v8Value()); | |
| 637 | |
| 638 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 639 } | |
| 640 | |
| 641 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPaye rPhoneInResponse) | |
| 642 { | |
| 643 V8TestingScope scope; | |
| 644 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 645 makePaymentRequestOriginSecure(scope.document()); | |
| 646 PaymentOptions options; | |
| 647 options.setRequestPayerPhone(true); | |
| 648 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 649 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 650 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 651 response->payer_phone = "0123"; | |
| 652 | |
| 653 ScriptValue outValue; | |
| 654 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 655 | |
| 656 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 657 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 658 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate() , outValue.v8Value()); | |
| 659 | |
| 660 EXPECT_EQ("0123", pr->payerPhone()); | |
| 661 } | |
| 662 | |
| 663 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayer PhoneInResponse) | |
| 664 { | |
| 665 V8TestingScope scope; | |
| 666 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 667 makePaymentRequestOriginSecure(scope.document()); | |
| 668 PaymentOptions options; | |
| 669 options.setRequestPayerPhone(true); | |
| 670 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 671 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 672 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 673 response->payer_phone = ""; | |
| 674 | |
| 675 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 676 | |
| 677 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 678 } | |
| 679 | |
| 680 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerP honeInResponse) | |
| 681 { | |
| 682 V8TestingScope scope; | |
| 683 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 684 makePaymentRequestOriginSecure(scope.document()); | |
| 685 PaymentOptions options; | |
| 686 options.setRequestPayerPhone(true); | |
| 687 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 688 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 689 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 690 response->payer_phone = String(); | |
| 691 | |
| 692 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 693 | |
| 694 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 695 } | |
| 696 | |
| 697 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulPay erPhoneInResponse) | |
| 698 { | |
| 699 V8TestingScope scope; | |
| 700 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 701 makePaymentRequestOriginSecure(scope.document()); | |
| 702 PaymentOptions options; | |
| 703 options.setRequestPayerPhone(false); | |
| 704 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 705 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 706 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 707 response->payer_phone = ""; | |
| 708 | |
| 709 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 710 | |
| 711 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 712 } | |
| 713 | |
| 714 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPaye rPhoneInResponse) | |
| 715 { | |
| 716 V8TestingScope scope; | |
| 717 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 718 makePaymentRequestOriginSecure(scope.document()); | |
| 719 PaymentOptions options; | |
| 720 options.setRequestPayerPhone(false); | |
| 721 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx ceptionState()); | |
| 722 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 723 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
|
please use gerrit instead
2016/06/16 16:17:56
response->total_amount = mojom::blink::CurrencyAmo
| |
| 724 response->payer_phone = String(); | |
| 725 | |
| 726 ScriptValue outValue; | |
| 727 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s cope.getScriptState(), &outValue), funcs.expectNoCall()); | |
| 728 | |
| 729 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 730 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | |
| 731 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate() , outValue.v8Value()); | |
| 732 | |
| 733 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 734 } | |
| 735 | |
| 546 } // namespace | 736 } // namespace |
| 547 } // namespace blink | 737 } // namespace blink |
| OLD | NEW |