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/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" |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," | 551 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," |
| 552 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 552 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 554 | 554 |
| 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); | 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); |
| 556 EXPECT_FALSE(getExceptionState().hadException()); | 556 EXPECT_FALSE(getExceptionState().hadException()); |
| 557 | 557 |
| 558 EXPECT_EQ("fast", request->shippingOption()); | 558 EXPECT_EQ("fast", request->shippingOption()); |
| 559 } | 559 } |
| 560 | 560 |
| 561 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPa yerEmailInResponse) | |
| 562 { | |
| 563 ScriptState::Scope scope(getScriptState()); | |
| 564 PaymentOptions options; | |
| 565 options.setRequestPayerEmail(true); | |
| 566 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 567 EXPECT_FALSE(getExceptionState().hadException()); | |
| 568 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 569 response->payer_email = "abc@gmail.com"; | |
| 570 | |
| 571 ScriptValue outValue; | |
| 572 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 573 | |
| 574 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 575 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 576 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 577 | |
| 578 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | |
| 579 } | |
| 580 | |
| 581 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPay erEmailInResponse) | |
| 582 { | |
| 583 ScriptState::Scope scope(getScriptState()); | |
| 584 PaymentOptions options; | |
| 585 options.setRequestPayerEmail(true); | |
| 586 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 587 EXPECT_FALSE(getExceptionState().hadException()); | |
| 588 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 589 response->payer_email = ""; | |
| 590 | |
| 591 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 592 | |
| 593 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 594 } | |
| 595 | |
| 596 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPaye rEmailInResponse) | |
| 597 { | |
| 598 ScriptState::Scope scope(getScriptState()); | |
| 599 PaymentOptions options; | |
| 600 options.setRequestPayerEmail(true); | |
| 601 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 602 EXPECT_FALSE(getExceptionState().hadException()); | |
| 603 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 604 response->payer_email = String(); | |
| 605 | |
| 606 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 607 | |
| 608 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 609 } | |
| 610 | |
| 611 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNull PayerEmailInResponse) | |
| 612 { | |
| 613 ScriptState::Scope scope(getScriptState()); | |
| 614 PaymentOptions options; | |
| 615 options.setRequestPayerEmail(false); | |
| 616 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 617 EXPECT_FALSE(getExceptionState().hadException()); | |
| 618 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 619 response->payer_email = ""; | |
| 620 | |
| 621 ScriptValue outValue; | |
| 622 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectCall(getScriptState())); | |
| 623 | |
| 624 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 625 } | |
| 626 | |
| 627 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPa yerEmailInResponse) | |
| 628 { | |
| 629 ScriptState::Scope scope(getScriptState()); | |
| 630 PaymentOptions options; | |
| 631 options.setRequestPayerEmail(false); | |
| 632 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 633 EXPECT_FALSE(getExceptionState().hadException()); | |
| 634 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 635 response->payer_email = String(); | |
| 636 | |
| 637 ScriptValue outValue; | |
| 638 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 639 | |
| 640 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 641 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 642 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 643 | |
| 644 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 645 } | |
| 646 | |
| 647 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPa yerPhoneInResponse) | |
| 648 { | |
| 649 ScriptState::Scope scope(getScriptState()); | |
| 650 PaymentOptions options; | |
| 651 options.setRequestPayerPhone(true); | |
| 652 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 653 EXPECT_FALSE(getExceptionState().hadException()); | |
| 654 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 655 response->payer_phone = "0123"; | |
| 656 | |
| 657 ScriptValue outValue; | |
| 658 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 659 | |
| 660 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 661 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 662 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 663 | |
| 664 EXPECT_EQ("0123", pr->payerPhone()); | |
| 665 } | |
| 666 | |
| 667 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPay erPhoneInResponse) | |
| 668 { | |
| 669 ScriptState::Scope scope(getScriptState()); | |
| 670 PaymentOptions options; | |
| 671 options.setRequestPayerPhone(true); | |
| 672 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 673 EXPECT_FALSE(getExceptionState().hadException()); | |
| 674 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 675 response->payer_phone = ""; | |
| 676 | |
| 677 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 678 | |
| 679 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 680 } | |
| 681 | |
| 682 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPaye rPhoneInResponse) | |
| 683 { | |
| 684 ScriptState::Scope scope(getScriptState()); | |
| 685 PaymentOptions options; | |
| 686 options.setRequestPayerPhone(true); | |
| 687 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 688 EXPECT_FALSE(getExceptionState().hadException()); | |
| 689 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 690 response->payer_phone = String(); | |
| 691 | |
| 692 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 693 | |
| 694 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 695 } | |
| 696 | |
| 697 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulP ayerPhoneInResponse) | |
| 698 { | |
| 699 ScriptState::Scope scope(getScriptState()); | |
| 700 PaymentOptions options; | |
| 701 options.setRequestPayerPhone(false); | |
| 702 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 703 EXPECT_FALSE(getExceptionState().hadException()); | |
| 704 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 705 response->payer_phone = ""; | |
| 706 | |
| 707 ScriptValue outValue; | |
| 708 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectCall(getScriptState())); | |
|
please use gerrit instead
2016/06/13 15:14:21
When you're rejecting a promise, PaymentResponseFu
| |
| 709 | |
| 710 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 711 } | |
| 712 | |
| 713 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPa yerPhoneInResponse) | |
| 714 { | |
| 715 ScriptState::Scope scope(getScriptState()); | |
| 716 PaymentOptions options; | |
| 717 options.setRequestPayerPhone(false); | |
| 718 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 719 EXPECT_FALSE(getExceptionState().hadException()); | |
| 720 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 721 response->payer_phone = String(); | |
| 722 | |
| 723 ScriptValue outValue; | |
| 724 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 725 | |
| 726 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 727 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 728 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 729 | |
| 730 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 731 } | |
| 732 | |
| 561 } // namespace | 733 } // namespace |
| 562 } // namespace blink | 734 } // namespace blink |
| OLD | NEW |