| 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" | |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 10 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 11 #include "modules/payments/PaymentTestHelper.h" | 10 #include "modules/payments/PaymentTestHelper.h" |
| 12 #include "platform/heap/HeapAllocator.h" | 11 #include "platform/heap/HeapAllocator.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 makePaymentRequestOriginSecure(scope.document()); | 463 makePaymentRequestOriginSecure(scope.document()); |
| 465 PaymentRequest* request = PaymentRequest::create( | 464 PaymentRequest* request = PaymentRequest::create( |
| 466 scope.getScriptState(), buildPaymentMethodDataForTest(), | 465 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 467 buildPaymentDetailsForTest(), scope.getExceptionState()); | 466 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 468 EXPECT_FALSE(scope.getExceptionState().hadException()); | 467 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 469 | 468 |
| 470 request->show(scope.getScriptState()) | 469 request->show(scope.getScriptState()) |
| 471 .then(funcs.expectNoCall(), funcs.expectCall()); | 470 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 472 | 471 |
| 473 request->onUpdatePaymentDetails(ScriptValue::from( | 472 request->onUpdatePaymentDetails(ScriptValue::from( |
| 474 scope.getScriptState(), | 473 scope.getScriptState(), fromJSONString(scope.getScriptState()->isolate(), |
| 475 fromJSONString(scope.getScriptState(), "{}", scope.getExceptionState()))); | 474 "{}", scope.getExceptionState()))); |
| 476 EXPECT_FALSE(scope.getExceptionState().hadException()); | 475 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 477 } | 476 } |
| 478 | 477 |
| 479 TEST(PaymentRequestTest, | 478 TEST(PaymentRequestTest, |
| 480 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { | 479 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { |
| 481 V8TestingScope scope; | 480 V8TestingScope scope; |
| 482 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 481 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 483 makePaymentRequestOriginSecure(scope.document()); | 482 makePaymentRequestOriginSecure(scope.document()); |
| 484 PaymentDetails details; | 483 PaymentDetails details; |
| 485 details.setTotal(buildPaymentItemForTest()); | 484 details.setTotal(buildPaymentItemForTest()); |
| 486 PaymentOptions options; | 485 PaymentOptions options; |
| 487 options.setRequestShipping(true); | 486 options.setRequestShipping(true); |
| 488 PaymentRequest* request = PaymentRequest::create( | 487 PaymentRequest* request = PaymentRequest::create( |
| 489 scope.getScriptState(), buildPaymentMethodDataForTest(), details, options, | 488 scope.getScriptState(), buildPaymentMethodDataForTest(), details, options, |
| 490 scope.getExceptionState()); | 489 scope.getExceptionState()); |
| 491 EXPECT_FALSE(scope.getExceptionState().hadException()); | 490 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 492 EXPECT_TRUE(request->shippingOption().isNull()); | 491 EXPECT_TRUE(request->shippingOption().isNull()); |
| 493 request->show(scope.getScriptState()) | 492 request->show(scope.getScriptState()) |
| 494 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 493 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 495 String detailWithShippingOptions = | 494 String detailWithShippingOptions = |
| 496 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 495 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 497 "\"value\": \"5.00\"}}," | 496 "\"value\": \"5.00\"}}," |
| 498 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": " | 497 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": " |
| 499 "\"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": " | 498 "\"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": " |
| 500 "\"5.00\"}, \"selected\": true}]}"; | 499 "\"5.00\"}, \"selected\": true}]}"; |
| 501 request->onUpdatePaymentDetails(ScriptValue::from( | 500 request->onUpdatePaymentDetails(ScriptValue::from( |
| 502 scope.getScriptState(), | 501 scope.getScriptState(), |
| 503 fromJSONString(scope.getScriptState(), detailWithShippingOptions, | 502 fromJSONString(scope.getScriptState()->isolate(), |
| 504 scope.getExceptionState()))); | 503 detailWithShippingOptions, scope.getExceptionState()))); |
| 505 EXPECT_FALSE(scope.getExceptionState().hadException()); | 504 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 506 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 505 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 507 String detailWithoutShippingOptions = | 506 String detailWithoutShippingOptions = |
| 508 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 507 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 509 "\"value\": \"5.00\"}}}"; | 508 "\"value\": \"5.00\"}}}"; |
| 510 | 509 |
| 511 request->onUpdatePaymentDetails(ScriptValue::from( | 510 request->onUpdatePaymentDetails(ScriptValue::from( |
| 512 scope.getScriptState(), | 511 scope.getScriptState(), |
| 513 fromJSONString(scope.getScriptState(), detailWithoutShippingOptions, | 512 fromJSONString(scope.getScriptState()->isolate(), |
| 514 scope.getExceptionState()))); | 513 detailWithoutShippingOptions, scope.getExceptionState()))); |
| 515 | 514 |
| 516 EXPECT_FALSE(scope.getExceptionState().hadException()); | 515 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 517 EXPECT_TRUE(request->shippingOption().isNull()); | 516 EXPECT_TRUE(request->shippingOption().isNull()); |
| 518 } | 517 } |
| 519 | 518 |
| 520 TEST( | 519 TEST( |
| 521 PaymentRequestTest, | 520 PaymentRequestTest, |
| 522 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { | 521 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { |
| 523 V8TestingScope scope; | 522 V8TestingScope scope; |
| 524 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 523 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 525 makePaymentRequestOriginSecure(scope.document()); | 524 makePaymentRequestOriginSecure(scope.document()); |
| 526 PaymentOptions options; | 525 PaymentOptions options; |
| 527 options.setRequestShipping(true); | 526 options.setRequestShipping(true); |
| 528 PaymentRequest* request = PaymentRequest::create( | 527 PaymentRequest* request = PaymentRequest::create( |
| 529 scope.getScriptState(), buildPaymentMethodDataForTest(), | 528 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 530 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 529 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 531 EXPECT_FALSE(scope.getExceptionState().hadException()); | 530 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 532 request->show(scope.getScriptState()) | 531 request->show(scope.getScriptState()) |
| 533 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 532 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 534 String detail = | 533 String detail = |
| 535 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 534 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 536 "\"value\": \"5.00\"}}," | 535 "\"value\": \"5.00\"}}," |
| 537 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 536 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
| 538 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 537 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 539 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 538 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
| 540 "\"USD\", \"value\": \"50.00\"}}]}"; | 539 "\"USD\", \"value\": \"50.00\"}}]}"; |
| 541 | 540 |
| 542 request->onUpdatePaymentDetails(ScriptValue::from( | 541 request->onUpdatePaymentDetails( |
| 543 scope.getScriptState(), fromJSONString(scope.getScriptState(), detail, | 542 ScriptValue::from(scope.getScriptState(), |
| 544 scope.getExceptionState()))); | 543 fromJSONString(scope.getScriptState()->isolate(), |
| 544 detail, scope.getExceptionState()))); |
| 545 EXPECT_FALSE(scope.getExceptionState().hadException()); | 545 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 546 | 546 |
| 547 EXPECT_TRUE(request->shippingOption().isNull()); | 547 EXPECT_TRUE(request->shippingOption().isNull()); |
| 548 } | 548 } |
| 549 | 549 |
| 550 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { | 550 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { |
| 551 V8TestingScope scope; | 551 V8TestingScope scope; |
| 552 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 552 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 553 makePaymentRequestOriginSecure(scope.document()); | 553 makePaymentRequestOriginSecure(scope.document()); |
| 554 PaymentOptions options; | 554 PaymentOptions options; |
| 555 options.setRequestShipping(true); | 555 options.setRequestShipping(true); |
| 556 PaymentRequest* request = PaymentRequest::create( | 556 PaymentRequest* request = PaymentRequest::create( |
| 557 scope.getScriptState(), buildPaymentMethodDataForTest(), | 557 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 558 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 558 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 559 EXPECT_FALSE(scope.getExceptionState().hadException()); | 559 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 560 request->show(scope.getScriptState()) | 560 request->show(scope.getScriptState()) |
| 561 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 561 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 562 String detail = | 562 String detail = |
| 563 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 563 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 564 "\"value\": \"5.00\"}}," | 564 "\"value\": \"5.00\"}}," |
| 565 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 565 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
| 566 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 566 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 567 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 567 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
| 568 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 568 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 569 | 569 |
| 570 request->onUpdatePaymentDetails(ScriptValue::from( | 570 request->onUpdatePaymentDetails( |
| 571 scope.getScriptState(), fromJSONString(scope.getScriptState(), detail, | 571 ScriptValue::from(scope.getScriptState(), |
| 572 scope.getExceptionState()))); | 572 fromJSONString(scope.getScriptState()->isolate(), |
| 573 detail, scope.getExceptionState()))); |
| 573 EXPECT_FALSE(scope.getExceptionState().hadException()); | 574 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 574 | 575 |
| 575 EXPECT_EQ("fast", request->shippingOption()); | 576 EXPECT_EQ("fast", request->shippingOption()); |
| 576 } | 577 } |
| 577 | 578 |
| 578 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { | 579 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { |
| 579 V8TestingScope scope; | 580 V8TestingScope scope; |
| 580 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 581 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 581 makePaymentRequestOriginSecure(scope.document()); | 582 makePaymentRequestOriginSecure(scope.document()); |
| 582 PaymentRequest* request = PaymentRequest::create( | 583 PaymentRequest* request = PaymentRequest::create( |
| 583 scope.getScriptState(), buildPaymentMethodDataForTest(), | 584 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 584 buildPaymentDetailsForTest(), scope.getExceptionState()); | 585 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 585 EXPECT_FALSE(scope.getExceptionState().hadException()); | 586 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 586 | 587 |
| 587 request->show(scope.getScriptState()) | 588 request->show(scope.getScriptState()) |
| 588 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 589 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 589 String detailWithErrorMsg = | 590 String detailWithErrorMsg = |
| 590 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 591 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 591 "\"value\": \"5.00\"}}," | 592 "\"value\": \"5.00\"}}," |
| 592 "\"error\": \"This is an error message.\"}"; | 593 "\"error\": \"This is an error message.\"}"; |
| 593 | 594 |
| 594 request->onUpdatePaymentDetails(ScriptValue::from( | 595 request->onUpdatePaymentDetails(ScriptValue::from( |
| 595 scope.getScriptState(), | 596 scope.getScriptState(), |
| 596 fromJSONString(scope.getScriptState(), detailWithErrorMsg, | 597 fromJSONString(scope.getScriptState()->isolate(), detailWithErrorMsg, |
| 597 scope.getExceptionState()))); | 598 scope.getExceptionState()))); |
| 598 EXPECT_FALSE(scope.getExceptionState().hadException()); | 599 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 599 } | 600 } |
| 600 | 601 |
| 601 TEST(PaymentRequestTest, | 602 TEST(PaymentRequestTest, |
| 602 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { | 603 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { |
| 603 V8TestingScope scope; | 604 V8TestingScope scope; |
| 604 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 605 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 605 makePaymentRequestOriginSecure(scope.document()); | 606 makePaymentRequestOriginSecure(scope.document()); |
| 606 PaymentDetails details; | 607 PaymentDetails details; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 625 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 626 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 626 "\"value\": \"5.00\"}}," | 627 "\"value\": \"5.00\"}}," |
| 627 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": " | 628 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": " |
| 628 "\"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": " | 629 "\"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": " |
| 629 "\"5.00\"}, \"selected\": true}, {\"id\": \"standardShippingOption\", " | 630 "\"5.00\"}, \"selected\": true}, {\"id\": \"standardShippingOption\", " |
| 630 "\"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", " | 631 "\"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", " |
| 631 "\"value\": \"5.00\"}, \"selected\": true}]}"; | 632 "\"value\": \"5.00\"}, \"selected\": true}]}"; |
| 632 | 633 |
| 633 request->onUpdatePaymentDetails(ScriptValue::from( | 634 request->onUpdatePaymentDetails(ScriptValue::from( |
| 634 scope.getScriptState(), | 635 scope.getScriptState(), |
| 635 fromJSONString(scope.getScriptState(), detailWithShippingOptions, | 636 fromJSONString(scope.getScriptState()->isolate(), |
| 636 scope.getExceptionState()))); | 637 detailWithShippingOptions, scope.getExceptionState()))); |
| 637 | 638 |
| 638 EXPECT_FALSE(scope.getExceptionState().hadException()); | 639 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 639 EXPECT_TRUE(request->shippingOption().isNull()); | 640 EXPECT_TRUE(request->shippingOption().isNull()); |
| 640 } | 641 } |
| 641 | 642 |
| 642 } // namespace | 643 } // namespace |
| 643 } // namespace blink | 644 } // namespace blink |
| OLD | NEW |