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(), Vector<St ring>(1, "foo"), 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(), Vector<St ring>(1, "foo"), 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(), Vector<St ring>(1, "foo"), 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, ResolveShowPromiseWithRequestPayerEmailFalseAndEmptyP ayerEmailInResponse) | |
| 612 { | |
| 613 ScriptState::Scope scope(getScriptState()); | |
| 614 PaymentOptions options; | |
| 615 options.setRequestPayerEmail(false); | |
| 616 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), 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::expectNoCall(getScriptState())); | |
| 623 | |
| 624 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 625 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 626 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 627 | |
| 628 EXPECT_TRUE(pr->payerEmail().isNull()); | |
|
zino
2016/06/09 17:56:08
Hmm...
I'm not sure if it's possible to pass this
please use gerrit instead
2016/06/09 20:41:15
Because options.setRequestPayerEmail(false) is cal
| |
| 629 } | |
| 630 | |
| 631 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPa yerEmailInResponse) | |
| 632 { | |
| 633 ScriptState::Scope scope(getScriptState()); | |
| 634 PaymentOptions options; | |
| 635 options.setRequestPayerEmail(false); | |
| 636 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 637 EXPECT_FALSE(getExceptionState().hadException()); | |
| 638 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 639 response->payer_email = String(); | |
| 640 | |
| 641 ScriptValue outValue; | |
| 642 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 643 | |
| 644 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 645 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 646 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 647 | |
| 648 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 649 } | |
| 650 | |
| 651 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPa yerPhoneInResponse) | |
| 652 { | |
| 653 ScriptState::Scope scope(getScriptState()); | |
| 654 PaymentOptions options; | |
| 655 options.setRequestPayerPhone(true); | |
| 656 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 657 EXPECT_FALSE(getExceptionState().hadException()); | |
| 658 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 659 response->payer_phone = "0123"; | |
| 660 | |
| 661 ScriptValue outValue; | |
| 662 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 663 | |
| 664 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 665 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 666 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 667 | |
| 668 EXPECT_EQ("0123", pr->payerPhone()); | |
| 669 } | |
| 670 | |
| 671 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPay erPhoneInResponse) | |
| 672 { | |
| 673 ScriptState::Scope scope(getScriptState()); | |
| 674 PaymentOptions options; | |
| 675 options.setRequestPayerPhone(true); | |
| 676 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 677 EXPECT_FALSE(getExceptionState().hadException()); | |
| 678 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 679 response->payer_phone = ""; | |
| 680 | |
| 681 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 682 | |
| 683 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 684 } | |
| 685 | |
| 686 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPaye rPhoneInResponse) | |
| 687 { | |
| 688 ScriptState::Scope scope(getScriptState()); | |
| 689 PaymentOptions options; | |
| 690 options.setRequestPayerPhone(true); | |
| 691 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 692 EXPECT_FALSE(getExceptionState().hadException()); | |
| 693 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 694 response->payer_phone = String(); | |
| 695 | |
| 696 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); | |
| 697 | |
| 698 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 699 } | |
| 700 | |
| 701 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndEmptyP ayerPhoneInResponse) | |
| 702 { | |
| 703 ScriptState::Scope scope(getScriptState()); | |
| 704 PaymentOptions options; | |
| 705 options.setRequestPayerPhone(false); | |
| 706 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 707 EXPECT_FALSE(getExceptionState().hadException()); | |
| 708 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 709 response->payer_phone = ""; | |
| 710 | |
| 711 ScriptValue outValue; | |
| 712 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 713 | |
| 714 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 715 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 716 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 717 | |
| 718 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 719 } | |
| 720 | |
| 721 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPa yerPhoneInResponse) | |
| 722 { | |
| 723 ScriptState::Scope scope(getScriptState()); | |
| 724 PaymentOptions options; | |
| 725 options.setRequestPayerPhone(false); | |
| 726 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 727 EXPECT_FALSE(getExceptionState().hadException()); | |
| 728 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 729 | |
| 730 ScriptValue outValue; | |
| 731 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 732 | |
| 733 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 734 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 735 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 736 | |
| 737 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 738 } | |
| 739 | |
| 561 } // namespace | 740 } // namespace |
| 562 } // namespace blink | 741 } // namespace blink |
| OLD | NEW |