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/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
| 11 #include "bindings/modules/v8/V8PaymentResponse.h" | 11 #include "bindings/modules/v8/V8PaymentResponse.h" |
| 12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "modules/payments/PaymentAddress.h" | 14 #include "modules/payments/PaymentAddress.h" |
| 15 #include "modules/payments/PaymentRequestTestBase.h" | 15 #include "modules/payments/PaymentRequestTestBase.h" |
| 16 #include "modules/payments/PaymentResponse.h" | 16 #include "modules/payments/PaymentResponse.h" |
| 17 #include "modules/payments/PaymentTestHelper.h" | 17 #include "modules/payments/PaymentTestHelper.h" |
| 18 #include "platform/heap/HeapAllocator.h" | 18 #include "platform/heap/HeapAllocator.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include <utility> | 20 #include <utility> |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class PaymentRequestTest : public PaymentRequestTestBase {}; | 25 class PaymentRequestTest : public PaymentRequestTestBase {}; |
|
please use gerrit instead
2016/06/16 00:52:22
Looks like you need to rebase, because PaymentRequ
| |
| 26 | 26 |
| 27 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 27 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 28 { | 28 { |
| 29 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu ildPaymentDetailsForTest(), getExceptionState()); | 29 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu ildPaymentDetailsForTest(), getExceptionState()); |
| 30 | 30 |
| 31 EXPECT_FALSE(getExceptionState().hadException()); | 31 EXPECT_FALSE(getExceptionState().hadException()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 TEST_F(PaymentRequestTest, SecureContextRequired) | 34 TEST_F(PaymentRequestTest, SecureContextRequired) |
| 35 { | 35 { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," | 456 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," |
| 457 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 457 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 458 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 458 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 459 | 459 |
| 460 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); | 460 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); |
| 461 EXPECT_FALSE(getExceptionState().hadException()); | 461 EXPECT_FALSE(getExceptionState().hadException()); |
| 462 | 462 |
| 463 EXPECT_EQ("fast", request->shippingOption()); | 463 EXPECT_EQ("fast", request->shippingOption()); |
| 464 } | 464 } |
| 465 | 465 |
| 466 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPa yerEmailInResponse) | |
| 467 { | |
| 468 ScriptState::Scope scope(getScriptState()); | |
| 469 PaymentOptions options; | |
| 470 options.setRequestPayerEmail(true); | |
| 471 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 472 EXPECT_FALSE(getExceptionState().hadException()); | |
| 473 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 474 response->payer_email = "abc@gmail.com"; | |
| 475 | |
| 476 ScriptValue outValue; | |
| 477 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), expectNoCall()); | |
| 478 | |
| 479 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 480 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 481 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 482 | |
| 483 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | |
| 484 } | |
| 485 | |
| 486 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPay erEmailInResponse) | |
| 487 { | |
| 488 ScriptState::Scope scope(getScriptState()); | |
| 489 PaymentOptions options; | |
| 490 options.setRequestPayerEmail(true); | |
| 491 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 492 EXPECT_FALSE(getExceptionState().hadException()); | |
| 493 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 494 response->payer_email = ""; | |
| 495 | |
| 496 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 497 | |
| 498 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 499 } | |
| 500 | |
| 501 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPaye rEmailInResponse) | |
| 502 { | |
| 503 ScriptState::Scope scope(getScriptState()); | |
| 504 PaymentOptions options; | |
| 505 options.setRequestPayerEmail(true); | |
| 506 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 507 EXPECT_FALSE(getExceptionState().hadException()); | |
| 508 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 509 response->payer_email = String(); | |
| 510 | |
| 511 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 512 | |
| 513 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 514 } | |
| 515 | |
| 516 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNull PayerEmailInResponse) | |
| 517 { | |
| 518 ScriptState::Scope scope(getScriptState()); | |
| 519 PaymentOptions options; | |
| 520 options.setRequestPayerEmail(false); | |
| 521 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 522 EXPECT_FALSE(getExceptionState().hadException()); | |
| 523 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 524 response->payer_email = ""; | |
| 525 | |
| 526 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 527 | |
| 528 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 529 } | |
| 530 | |
| 531 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPa yerEmailInResponse) | |
| 532 { | |
| 533 ScriptState::Scope scope(getScriptState()); | |
| 534 PaymentOptions options; | |
| 535 options.setRequestPayerEmail(false); | |
| 536 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 537 EXPECT_FALSE(getExceptionState().hadException()); | |
| 538 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 539 response->payer_email = String(); | |
| 540 | |
| 541 ScriptValue outValue; | |
| 542 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), expectNoCall()); | |
| 543 | |
| 544 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 545 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 546 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 547 | |
| 548 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 549 } | |
| 550 | |
| 551 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPa yerPhoneInResponse) | |
| 552 { | |
| 553 ScriptState::Scope scope(getScriptState()); | |
| 554 PaymentOptions options; | |
| 555 options.setRequestPayerPhone(true); | |
| 556 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 557 EXPECT_FALSE(getExceptionState().hadException()); | |
| 558 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 559 response->payer_phone = "0123"; | |
| 560 | |
| 561 ScriptValue outValue; | |
| 562 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), expectNoCall()); | |
| 563 | |
| 564 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 565 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 566 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 567 | |
| 568 EXPECT_EQ("0123", pr->payerPhone()); | |
| 569 } | |
| 570 | |
| 571 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPay erPhoneInResponse) | |
| 572 { | |
| 573 ScriptState::Scope scope(getScriptState()); | |
| 574 PaymentOptions options; | |
| 575 options.setRequestPayerPhone(true); | |
| 576 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 577 EXPECT_FALSE(getExceptionState().hadException()); | |
| 578 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 579 response->payer_phone = ""; | |
| 580 | |
| 581 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 582 | |
| 583 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 584 } | |
| 585 | |
| 586 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPaye rPhoneInResponse) | |
| 587 { | |
| 588 ScriptState::Scope scope(getScriptState()); | |
| 589 PaymentOptions options; | |
| 590 options.setRequestPayerPhone(true); | |
| 591 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 592 EXPECT_FALSE(getExceptionState().hadException()); | |
| 593 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 594 response->payer_phone = String(); | |
| 595 | |
| 596 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 597 | |
| 598 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 599 } | |
| 600 | |
| 601 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulP ayerPhoneInResponse) | |
| 602 { | |
| 603 ScriptState::Scope scope(getScriptState()); | |
| 604 PaymentOptions options; | |
| 605 options.setRequestPayerPhone(false); | |
| 606 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 607 EXPECT_FALSE(getExceptionState().hadException()); | |
| 608 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 609 response->payer_phone = ""; | |
| 610 | |
| 611 request->show(getScriptState()).then(expectNoCall(), expectCall()); | |
| 612 | |
| 613 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 614 } | |
| 615 | |
| 616 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPa yerPhoneInResponse) | |
| 617 { | |
| 618 ScriptState::Scope scope(getScriptState()); | |
| 619 PaymentOptions options; | |
| 620 options.setRequestPayerPhone(false); | |
| 621 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState ()); | |
| 622 EXPECT_FALSE(getExceptionState().hadException()); | |
| 623 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 624 response->payer_phone = String(); | |
| 625 | |
| 626 ScriptValue outValue; | |
| 627 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), expectNoCall()); | |
| 628 | |
| 629 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 630 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 631 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 632 | |
| 633 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 634 } | |
| 635 | |
| 466 } // namespace | 636 } // namespace |
| 467 } // namespace blink | 637 } // namespace blink |
| OLD | NEW |