Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp

Issue 2038423002: Adding support for phone and email. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 500 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
501 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," 501 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}},"
502 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 502 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
503 503
504 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 504 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
505 EXPECT_FALSE(getExceptionState().hadException()); 505 EXPECT_FALSE(getExceptionState().hadException());
506 506
507 EXPECT_EQ("standardShippingOption", request->shippingOption()); 507 EXPECT_EQ("standardShippingOption", request->shippingOption());
508 } 508 }
509 509
510 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPa yerEmailInResponse)
511 {
512 ScriptState::Scope scope(getScriptState());
513 PaymentOptions options;
514 options.setRequestPayerEmail(true);
515 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
516 EXPECT_FALSE(getExceptionState().hadException());
517 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
518 response->payer_email = "abc@gmail.com";
519
520 ScriptValue outValue;
521 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
522
523 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
524 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
525 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
526
527 EXPECT_EQ("abc@gmail.com", pr->payerEmail());
528 }
529
530 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPay erEmailInResponse)
531 {
532 ScriptState::Scope scope(getScriptState());
533 PaymentOptions options;
534 options.setRequestPayerEmail(true);
535 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
536 EXPECT_FALSE(getExceptionState().hadException());
537 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
538 response->payer_email = "";
539
540 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
541
542 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
543 }
544
545 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPaye rEmailInResponse)
546 {
547 ScriptState::Scope scope(getScriptState());
548 PaymentOptions options;
549 options.setRequestPayerEmail(true);
550 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
551 EXPECT_FALSE(getExceptionState().hadException());
552 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
553
zino 2016/06/07 16:40:08 response->payer_email = String(); // null string
554 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
555
556 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
557 }
558
559 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndEmptyP ayerEmailInResponse)
560 {
561 ScriptState::Scope scope(getScriptState());
562 PaymentOptions options;
563 options.setRequestPayerEmail(false);
564 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
565 EXPECT_FALSE(getExceptionState().hadException());
566 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
567 response->payer_email = "";
568
569 ScriptValue outValue;
570 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
571
572 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
573 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
574 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
575
576 EXPECT_TRUE(pr->payerEmail().isEmpty());
zino 2016/06/07 16:40:08 You should use isNull() instead of isEmpty(). (If
577 }
578
579 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPa yerEmailInResponse)
580 {
581 ScriptState::Scope scope(getScriptState());
582 PaymentOptions options;
583 options.setRequestPayerEmail(false);
584 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
585 EXPECT_FALSE(getExceptionState().hadException());
586 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
587
588 ScriptValue outValue;
589 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
590
591 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
592 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
593 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
594
595 EXPECT_TRUE(pr->payerEmail().isNull());
596 }
597
598 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndPayerEm ailExistsInResponse)
zino 2016/06/07 16:40:08 Do we really need this? If we want this, we should
please use gerrit instead 2016/06/07 17:04:24 OK to remove.
599 {
600 ScriptState::Scope scope(getScriptState());
601 PaymentOptions options;
602 options.setRequestPayerEmail(false);
603 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
604 EXPECT_FALSE(getExceptionState().hadException());
605 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
606 response->payer_email = "abc@gmail.com";
607
608 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
609
610 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
611 }
612
613 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPa yerPhoneInResponse)
614 {
615 ScriptState::Scope scope(getScriptState());
616 PaymentOptions options;
617 options.setRequestPayerPhone(true);
618 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
619 EXPECT_FALSE(getExceptionState().hadException());
620 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
621 response->payer_phone = "0123";
622
623 ScriptValue outValue;
624 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
625
626 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
627 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
628 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
629
630 EXPECT_EQ("0123", pr->payerPhone());
631 }
632
633 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPay erPhoneInResponse)
634 {
635 ScriptState::Scope scope(getScriptState());
636 PaymentOptions options;
637 options.setRequestPayerPhone(true);
638 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
639 EXPECT_FALSE(getExceptionState().hadException());
640 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
641 response->payer_phone = "";
642
643 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
644
645 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
646 }
647
648 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPaye rPhoneInResponse)
649 {
650 ScriptState::Scope scope(getScriptState());
651 PaymentOptions options;
652 options.setRequestPayerPhone(true);
653 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
654 EXPECT_FALSE(getExceptionState().hadException());
655 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
656
657 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
658
659 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
660 }
661
662 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndEmptyP ayerPhoneInResponse)
663 {
664 ScriptState::Scope scope(getScriptState());
665 PaymentOptions options;
666 options.setRequestPayerPhone(false);
667 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
668 EXPECT_FALSE(getExceptionState().hadException());
669 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
670 response->payer_phone = "";
671
672 ScriptValue outValue;
673 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
674
675 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
676 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
677 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
678
679 EXPECT_TRUE(pr->payerPhone().isEmpty());
zino 2016/06/07 16:40:08 isNull
680 }
681
682 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPa yerPhoneInResponse)
683 {
684 ScriptState::Scope scope(getScriptState());
685 PaymentOptions options;
686 options.setRequestPayerPhone(false);
687 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
688 EXPECT_FALSE(getExceptionState().hadException());
689 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
690
691 ScriptValue outValue;
692 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
693
694 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
695 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
696 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
697
698 EXPECT_TRUE(pr->payerPhone().isNull());
699 }
700
701 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndPayerPh oneExistsInResponse)
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 = "0123";
710
711 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
712
713 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
714 }
715
510 } // namespace 716 } // namespace
511 } // namespace blink 717 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698