| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 391 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) | 394 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) |
| 395 { | 395 { |
| 396 ScriptState::Scope scope(getScriptState()); | 396 ScriptState::Scope scope(getScriptState()); |
| 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 398 EXPECT_FALSE(getExceptionState().hadException()); | 398 EXPECT_FALSE(getExceptionState().hadException()); |
| 399 request->show(getScriptState()); | 399 request->show(getScriptState()); |
| 400 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 400 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 401 request->complete(getScriptState(), false); | 401 request->complete(getScriptState(), Fail); |
| 402 | 402 |
| 403 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 403 request->complete(getScriptState(), Success).then(MockFunction::expectNoCall
(getScriptState()), MockFunction::expectCall(getScriptState())); |
| 404 } | 404 } |
| 405 | 405 |
| 406 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) | 406 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) |
| 407 { | 407 { |
| 408 ScriptState::Scope scope(getScriptState()); | 408 ScriptState::Scope scope(getScriptState()); |
| 409 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 409 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 410 EXPECT_FALSE(getExceptionState().hadException()); | 410 EXPECT_FALSE(getExceptionState().hadException()); |
| 411 | 411 |
| 412 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 412 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 413 | 413 |
| 414 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 414 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) | 417 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) |
| 418 { | 418 { |
| 419 ScriptState::Scope scope(getScriptState()); | 419 ScriptState::Scope scope(getScriptState()); |
| 420 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 420 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 421 EXPECT_FALSE(getExceptionState().hadException()); | 421 EXPECT_FALSE(getExceptionState().hadException()); |
| 422 request->show(getScriptState()); | 422 request->show(getScriptState()); |
| 423 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 423 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 424 | 424 |
| 425 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 425 request->complete(getScriptState(), Success).then(MockFunction::expectNoCall
(getScriptState()), MockFunction::expectCall(getScriptState())); |
| 426 | 426 |
| 427 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 427 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 428 } | 428 } |
| 429 | 429 |
| 430 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) | 430 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) |
| 431 { | 431 { |
| 432 ScriptState::Scope scope(getScriptState()); | 432 ScriptState::Scope scope(getScriptState()); |
| 433 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 433 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 434 EXPECT_FALSE(getExceptionState().hadException()); | 434 EXPECT_FALSE(getExceptionState().hadException()); |
| 435 request->show(getScriptState()); | 435 request->show(getScriptState()); |
| 436 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 436 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 437 | 437 |
| 438 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); | 438 request->complete(getScriptState(), Success).then(MockFunction::expectCall(g
etScriptState()), MockFunction::expectNoCall(getScriptState())); |
| 439 | 439 |
| 440 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 440 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
| 441 } | 441 } |
| 442 | 442 |
| 443 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 443 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
| 444 { | 444 { |
| 445 ScriptState::Scope scope(getScriptState()); | 445 ScriptState::Scope scope(getScriptState()); |
| 446 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 446 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 447 EXPECT_FALSE(getExceptionState().hadException()); | 447 EXPECT_FALSE(getExceptionState().hadException()); |
| 448 | 448 |
| 449 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 449 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 450 | 450 |
| 451 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 451 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 454 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
| 455 { | 455 { |
| 456 ScriptState::Scope scope(getScriptState()); | 456 ScriptState::Scope scope(getScriptState()); |
| 457 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 457 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 458 EXPECT_FALSE(getExceptionState().hadException()); | 458 EXPECT_FALSE(getExceptionState().hadException()); |
| 459 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 459 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 460 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 460 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 461 | 461 |
| 462 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 462 request->complete(getScriptState(), Success).then(MockFunction::expectNoCall
(getScriptState()), MockFunction::expectCall(getScriptState())); |
| 463 | 463 |
| 464 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 464 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 465 } | 465 } |
| 466 | 466 |
| 467 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 467 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
| 468 { | 468 { |
| 469 ScriptState::Scope scope(getScriptState()); | 469 ScriptState::Scope scope(getScriptState()); |
| 470 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 470 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 471 EXPECT_FALSE(getExceptionState().hadException()); | 471 EXPECT_FALSE(getExceptionState().hadException()); |
| 472 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 472 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } // namespace | 561 } // namespace |
| 562 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |