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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, ResolveShowPromiseWithRequestPayerEmailFalseAndEmptyP ayerEmailInResponse) | |
| 531 { | |
| 532 ScriptState::Scope scope(getScriptState()); | |
| 533 PaymentOptions options; | |
| 534 options.setRequestPayerEmail(false); | |
| 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 | |
| 539 ScriptValue outValue; | |
| 540 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 541 | |
| 542 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 543 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 544 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 545 | |
| 546 EXPECT_TRUE(pr->payerEmail().isNull()); | |
| 547 } | |
|
zino
2016/06/06 14:19:32
nit: blank line.
| |
| 548 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPa yerPhoneInResponse) | |
| 549 { | |
| 550 ScriptState::Scope scope(getScriptState()); | |
| 551 PaymentOptions options; | |
| 552 options.setRequestPayerPhone(true); | |
| 553 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 554 EXPECT_FALSE(getExceptionState().hadException()); | |
| 555 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 556 response->payer_phone = "0123"; | |
| 557 | |
| 558 ScriptValue outValue; | |
| 559 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 560 | |
| 561 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 562 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 563 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 564 | |
| 565 EXPECT_EQ("0123", pr->payerPhone()); | |
| 566 } | |
| 567 | |
| 568 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndEmptyP ayerPhoneInResponse) | |
| 569 { | |
| 570 ScriptState::Scope scope(getScriptState()); | |
| 571 PaymentOptions options; | |
| 572 options.setRequestPayerPhone(false); | |
| 573 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | |
| 574 EXPECT_FALSE(getExceptionState().hadException()); | |
| 575 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); | |
| 576 | |
| 577 ScriptValue outValue; | |
| 578 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | |
| 579 | |
| 580 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); | |
| 581 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | |
| 582 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); | |
| 583 | |
| 584 EXPECT_TRUE(pr->payerPhone().isNull()); | |
| 585 } | |
| 586 | |
| 510 } // namespace | 587 } // namespace |
| 511 } // namespace blink | 588 } // namespace blink |
| OLD | NEW |