| 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/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "bindings/modules/v8/V8PaymentResponse.h" | 10 #include "bindings/modules/v8/V8PaymentResponse.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 EXPECT_TRUE(request->shippingOption().isNull()); | 75 EXPECT_TRUE(request->shippingOption().isNull()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) | 78 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) |
| 79 { | 79 { |
| 80 V8TestingScope scope; | 80 V8TestingScope scope; |
| 81 makePaymentRequestOriginSecure(scope.document()); | 81 makePaymentRequestOriginSecure(scope.document()); |
| 82 PaymentDetails details; | 82 PaymentDetails details; |
| 83 details.setTotal(buildPaymentItemForTest()); | 83 details.setTotal(buildPaymentItemForTest()); |
| 84 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 84 details.setShippingOptions(HeapVector<PaymentShippingOption>(2, buildShippin
gOptionForTest())); |
| 85 PaymentOptions options; | 85 PaymentOptions options; |
| 86 options.setRequestShipping(true); | 86 options.setRequestShipping(true); |
| 87 | 87 |
| 88 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 88 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 89 | 89 |
| 90 EXPECT_TRUE(request->shippingOption().isNull()); | 90 EXPECT_TRUE(request->shippingOption().isNull()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) | 93 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) |
| 94 { | 94 { |
| 95 V8TestingScope scope; | 95 V8TestingScope scope; |
| 96 makePaymentRequestOriginSecure(scope.document()); | 96 makePaymentRequestOriginSecure(scope.document()); |
| 97 PaymentDetails details; | 97 PaymentDetails details; |
| 98 details.setTotal(buildPaymentItemForTest()); | 98 details.setTotal(buildPaymentItemForTest()); |
| 99 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 99 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin
gOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 100 | 100 |
| 101 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, scope.getExceptionState()); | 101 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, scope.getExceptionState()); |
| 102 | 102 |
| 103 EXPECT_TRUE(request->shippingOption().isNull()); | 103 EXPECT_TRUE(request->shippingOption().isNull()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNotR
equested) | 106 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNotR
equested) |
| 107 { | 107 { |
| 108 V8TestingScope scope; | 108 V8TestingScope scope; |
| 109 makePaymentRequestOriginSecure(scope.document()); | 109 makePaymentRequestOriginSecure(scope.document()); |
| 110 PaymentDetails details; | 110 PaymentDetails details; |
| 111 details.setTotal(buildPaymentItemForTest()); | 111 details.setTotal(buildPaymentItemForTest()); |
| 112 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 112 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin
gOptionForTest())); |
| 113 PaymentOptions options; | 113 PaymentOptions options; |
| 114 options.setRequestShipping(false); | 114 options.setRequestShipping(false); |
| 115 | 115 |
| 116 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 116 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 117 | 117 |
| 118 EXPECT_TRUE(request->shippingOption().isNull()); | 118 EXPECT_TRUE(request->shippingOption().isNull()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingReq
uested) | 121 TEST(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingReq
uested) |
| 122 { | 122 { |
| 123 V8TestingScope scope; | 123 V8TestingScope scope; |
| 124 makePaymentRequestOriginSecure(scope.document()); | 124 makePaymentRequestOriginSecure(scope.document()); |
| 125 PaymentDetails details; | 125 PaymentDetails details; |
| 126 details.setTotal(buildPaymentItemForTest()); | 126 details.setTotal(buildPaymentItemForTest()); |
| 127 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 127 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin
gOptionForTest())); |
| 128 PaymentOptions options; | 128 PaymentOptions options; |
| 129 options.setRequestShipping(true); | 129 options.setRequestShipping(true); |
| 130 | 130 |
| 131 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 131 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 132 | 132 |
| 133 EXPECT_TRUE(request->shippingOption().isNull()); | 133 EXPECT_TRUE(request->shippingOption().isNull()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequested
) | 136 TEST(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequested
) |
| 137 { | 137 { |
| 138 V8TestingScope scope; | 138 V8TestingScope scope; |
| 139 makePaymentRequestOriginSecure(scope.document()); | 139 makePaymentRequestOriginSecure(scope.document()); |
| 140 PaymentDetails details; | 140 PaymentDetails details; |
| 141 details.setTotal(buildPaymentItemForTest()); | 141 details.setTotal(buildPaymentItemForTest()); |
| 142 HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(Pay
mentTestDataId, PaymentTestOverwriteValue, "standard")); | 142 HeapVector<PaymentShippingOption> shippingOptions(1, buildShippingOptionForT
est(PaymentTestDataId, PaymentTestOverwriteValue, "standard")); |
| 143 shippingOptions[0].setSelected(true); | 143 shippingOptions[0].setSelected(true); |
| 144 details.setShippingOptions(shippingOptions); | 144 details.setShippingOptions(shippingOptions); |
| 145 PaymentOptions options; | 145 PaymentOptions options; |
| 146 options.setRequestShipping(true); | 146 options.setRequestShipping(true); |
| 147 | 147 |
| 148 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 148 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 149 | 149 |
| 150 EXPECT_EQ("standard", request->shippingOption()); | 150 EXPECT_EQ("standard", request->shippingOption()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested) | 153 TEST(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested) |
| 154 { | 154 { |
| 155 V8TestingScope scope; | 155 V8TestingScope scope; |
| 156 makePaymentRequestOriginSecure(scope.document()); | 156 makePaymentRequestOriginSecure(scope.document()); |
| 157 PaymentDetails details; | 157 PaymentDetails details; |
| 158 details.setTotal(buildPaymentItemForTest()); | 158 details.setTotal(buildPaymentItemForTest()); |
| 159 HeapVector<ShippingOption> shippingOptions(2); | 159 HeapVector<PaymentShippingOption> shippingOptions(2); |
| 160 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); | 160 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
| 161 shippingOptions[0].setSelected(true); | 161 shippingOptions[0].setSelected(true); |
| 162 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); | 162 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
| 163 details.setShippingOptions(shippingOptions); | 163 details.setShippingOptions(shippingOptions); |
| 164 PaymentOptions options; | 164 PaymentOptions options; |
| 165 options.setRequestShipping(true); | 165 options.setRequestShipping(true); |
| 166 | 166 |
| 167 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 167 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 168 | 168 |
| 169 EXPECT_EQ("standard", request->shippingOption()); | 169 EXPECT_EQ("standard", request->shippingOption()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 TEST(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested) | 172 TEST(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested) |
| 173 { | 173 { |
| 174 V8TestingScope scope; | 174 V8TestingScope scope; |
| 175 makePaymentRequestOriginSecure(scope.document()); | 175 makePaymentRequestOriginSecure(scope.document()); |
| 176 PaymentDetails details; | 176 PaymentDetails details; |
| 177 details.setTotal(buildPaymentItemForTest()); | 177 details.setTotal(buildPaymentItemForTest()); |
| 178 HeapVector<ShippingOption> shippingOptions(2); | 178 HeapVector<PaymentShippingOption> shippingOptions(2); |
| 179 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); | 179 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
| 180 shippingOptions[0].setSelected(true); | 180 shippingOptions[0].setSelected(true); |
| 181 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); | 181 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
| 182 shippingOptions[1].setSelected(true); | 182 shippingOptions[1].setSelected(true); |
| 183 details.setShippingOptions(shippingOptions); | 183 details.setShippingOptions(shippingOptions); |
| 184 PaymentOptions options; | 184 PaymentOptions options; |
| 185 options.setRequestShipping(true); | 185 options.setRequestShipping(true); |
| 186 | 186 |
| 187 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 187 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 188 | 188 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPaye
rEmailInResponse) | 546 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPaye
rEmailInResponse) |
| 547 { | 547 { |
| 548 V8TestingScope scope; | 548 V8TestingScope scope; |
| 549 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 549 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 550 makePaymentRequestOriginSecure(scope.document()); | 550 makePaymentRequestOriginSecure(scope.document()); |
| 551 PaymentOptions options; | 551 PaymentOptions options; |
| 552 options.setRequestPayerEmail(true); | 552 options.setRequestPayerEmail(true); |
| 553 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 553 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 554 EXPECT_FALSE(scope.getExceptionState().hadException()); | 554 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 555 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 555 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 556 response->total_amount = mojom::blink::CurrencyAmount::New(); | 556 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 557 response->payer_email = "abc@gmail.com"; | 557 response->payer_email = "abc@gmail.com"; |
| 558 | 558 |
| 559 ScriptValue outValue; | 559 ScriptValue outValue; |
| 560 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 560 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 561 | 561 |
| 562 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 562 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 563 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 563 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 564 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 564 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 565 | 565 |
| 566 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | 566 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayer
EmailInResponse) | 569 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayer
EmailInResponse) |
| 570 { | 570 { |
| 571 V8TestingScope scope; | 571 V8TestingScope scope; |
| 572 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 572 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 573 makePaymentRequestOriginSecure(scope.document()); | 573 makePaymentRequestOriginSecure(scope.document()); |
| 574 PaymentOptions options; | 574 PaymentOptions options; |
| 575 options.setRequestPayerEmail(true); | 575 options.setRequestPayerEmail(true); |
| 576 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 576 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 577 EXPECT_FALSE(scope.getExceptionState().hadException()); | 577 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 578 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 578 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 579 response->total_amount = mojom::blink::CurrencyAmount::New(); | 579 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 580 response->payer_email = ""; | 580 response->payer_email = ""; |
| 581 | 581 |
| 582 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 582 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 583 | 583 |
| 584 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 584 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 585 } | 585 } |
| 586 | 586 |
| 587 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerE
mailInResponse) | 587 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerE
mailInResponse) |
| 588 { | 588 { |
| 589 V8TestingScope scope; | 589 V8TestingScope scope; |
| 590 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 590 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 591 makePaymentRequestOriginSecure(scope.document()); | 591 makePaymentRequestOriginSecure(scope.document()); |
| 592 PaymentOptions options; | 592 PaymentOptions options; |
| 593 options.setRequestPayerEmail(true); | 593 options.setRequestPayerEmail(true); |
| 594 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 594 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 595 EXPECT_FALSE(scope.getExceptionState().hadException()); | 595 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 596 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 596 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 597 response->total_amount = mojom::blink::CurrencyAmount::New(); | 597 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 598 response->payer_email = String(); | 598 response->payer_email = String(); |
| 599 | 599 |
| 600 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 600 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 601 | 601 |
| 602 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 602 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 603 } | 603 } |
| 604 | 604 |
| 605 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNullPa
yerEmailInResponse) | 605 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNullPa
yerEmailInResponse) |
| 606 { | 606 { |
| 607 V8TestingScope scope; | 607 V8TestingScope scope; |
| 608 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 608 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 609 makePaymentRequestOriginSecure(scope.document()); | 609 makePaymentRequestOriginSecure(scope.document()); |
| 610 PaymentOptions options; | 610 PaymentOptions options; |
| 611 options.setRequestPayerEmail(false); | 611 options.setRequestPayerEmail(false); |
| 612 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 612 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 613 EXPECT_FALSE(scope.getExceptionState().hadException()); | 613 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 614 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 614 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 615 response->total_amount = mojom::blink::CurrencyAmount::New(); | 615 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 616 response->payer_email = ""; | 616 response->payer_email = ""; |
| 617 | 617 |
| 618 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 618 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 619 | 619 |
| 620 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 620 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 621 } | 621 } |
| 622 | 622 |
| 623 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPaye
rEmailInResponse) | 623 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPaye
rEmailInResponse) |
| 624 { | 624 { |
| 625 V8TestingScope scope; | 625 V8TestingScope scope; |
| 626 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 626 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 627 makePaymentRequestOriginSecure(scope.document()); | 627 makePaymentRequestOriginSecure(scope.document()); |
| 628 PaymentOptions options; | 628 PaymentOptions options; |
| 629 options.setRequestPayerEmail(false); | 629 options.setRequestPayerEmail(false); |
| 630 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 630 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 631 EXPECT_FALSE(scope.getExceptionState().hadException()); | 631 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 632 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 632 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 633 response->total_amount = mojom::blink::CurrencyAmount::New(); | 633 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 634 response->payer_email = String(); | 634 response->payer_email = String(); |
| 635 | 635 |
| 636 ScriptValue outValue; | 636 ScriptValue outValue; |
| 637 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 637 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 638 | 638 |
| 639 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 639 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 640 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 640 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 641 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 641 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 642 | 642 |
| 643 EXPECT_TRUE(pr->payerEmail().isNull()); | 643 EXPECT_TRUE(pr->payerEmail().isNull()); |
| 644 } | 644 } |
| 645 | 645 |
| 646 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPaye
rPhoneInResponse) | 646 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPaye
rPhoneInResponse) |
| 647 { | 647 { |
| 648 V8TestingScope scope; | 648 V8TestingScope scope; |
| 649 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 649 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 650 makePaymentRequestOriginSecure(scope.document()); | 650 makePaymentRequestOriginSecure(scope.document()); |
| 651 PaymentOptions options; | 651 PaymentOptions options; |
| 652 options.setRequestPayerPhone(true); | 652 options.setRequestPayerPhone(true); |
| 653 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 653 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 654 EXPECT_FALSE(scope.getExceptionState().hadException()); | 654 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 655 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 655 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 656 response->total_amount = mojom::blink::CurrencyAmount::New(); | 656 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 657 response->payer_phone = "0123"; | 657 response->payer_phone = "0123"; |
| 658 | 658 |
| 659 ScriptValue outValue; | 659 ScriptValue outValue; |
| 660 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 660 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 661 | 661 |
| 662 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 662 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 663 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 663 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 664 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 664 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 665 | 665 |
| 666 EXPECT_EQ("0123", pr->payerPhone()); | 666 EXPECT_EQ("0123", pr->payerPhone()); |
| 667 } | 667 } |
| 668 | 668 |
| 669 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayer
PhoneInResponse) | 669 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayer
PhoneInResponse) |
| 670 { | 670 { |
| 671 V8TestingScope scope; | 671 V8TestingScope scope; |
| 672 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 672 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 673 makePaymentRequestOriginSecure(scope.document()); | 673 makePaymentRequestOriginSecure(scope.document()); |
| 674 PaymentOptions options; | 674 PaymentOptions options; |
| 675 options.setRequestPayerPhone(true); | 675 options.setRequestPayerPhone(true); |
| 676 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 676 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 677 EXPECT_FALSE(scope.getExceptionState().hadException()); | 677 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 678 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 678 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 679 response->total_amount = mojom::blink::CurrencyAmount::New(); | 679 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 680 response->payer_phone = ""; | 680 response->payer_phone = ""; |
| 681 | 681 |
| 682 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 682 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 683 | 683 |
| 684 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 684 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 685 } | 685 } |
| 686 | 686 |
| 687 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerP
honeInResponse) | 687 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerP
honeInResponse) |
| 688 { | 688 { |
| 689 V8TestingScope scope; | 689 V8TestingScope scope; |
| 690 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 690 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 691 makePaymentRequestOriginSecure(scope.document()); | 691 makePaymentRequestOriginSecure(scope.document()); |
| 692 PaymentOptions options; | 692 PaymentOptions options; |
| 693 options.setRequestPayerPhone(true); | 693 options.setRequestPayerPhone(true); |
| 694 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 694 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 695 EXPECT_FALSE(scope.getExceptionState().hadException()); | 695 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 696 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 696 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 697 response->total_amount = mojom::blink::CurrencyAmount::New(); | 697 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 698 response->payer_phone = String(); | 698 response->payer_phone = String(); |
| 699 | 699 |
| 700 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 700 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 701 | 701 |
| 702 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 702 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 703 } | 703 } |
| 704 | 704 |
| 705 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulPay
erPhoneInResponse) | 705 TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulPay
erPhoneInResponse) |
| 706 { | 706 { |
| 707 V8TestingScope scope; | 707 V8TestingScope scope; |
| 708 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 708 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 709 makePaymentRequestOriginSecure(scope.document()); | 709 makePaymentRequestOriginSecure(scope.document()); |
| 710 PaymentOptions options; | 710 PaymentOptions options; |
| 711 options.setRequestPayerPhone(false); | 711 options.setRequestPayerPhone(false); |
| 712 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 712 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 713 EXPECT_FALSE(scope.getExceptionState().hadException()); | 713 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 714 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 714 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 715 response->total_amount = mojom::blink::CurrencyAmount::New(); | 715 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 716 response->payer_phone = ""; | 716 response->payer_phone = ""; |
| 717 | 717 |
| 718 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 718 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 719 | 719 |
| 720 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 720 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 721 } | 721 } |
| 722 | 722 |
| 723 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPaye
rPhoneInResponse) | 723 TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPaye
rPhoneInResponse) |
| 724 { | 724 { |
| 725 V8TestingScope scope; | 725 V8TestingScope scope; |
| 726 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 726 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 727 makePaymentRequestOriginSecure(scope.document()); | 727 makePaymentRequestOriginSecure(scope.document()); |
| 728 PaymentOptions options; | 728 PaymentOptions options; |
| 729 options.setRequestPayerPhone(false); | 729 options.setRequestPayerPhone(false); |
| 730 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 730 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 731 EXPECT_FALSE(scope.getExceptionState().hadException()); | 731 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 732 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 732 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 733 response->total_amount = mojom::blink::CurrencyAmount::New(); | 733 response->total_amount = mojom::blink::PaymentCurrencyAmount::New(); |
| 734 response->payer_phone = String(); | 734 response->payer_phone = String(); |
| 735 | 735 |
| 736 ScriptValue outValue; | 736 ScriptValue outValue; |
| 737 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 737 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 738 | 738 |
| 739 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 739 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 740 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 740 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 741 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 741 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 742 | 742 |
| 743 EXPECT_TRUE(pr->payerPhone().isNull()); | 743 EXPECT_TRUE(pr->payerPhone().isNull()); |
| 744 } | 744 } |
| 745 | 745 |
| 746 } // namespace | 746 } // namespace |
| 747 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |