blob: c4dfd58a6593882a0dc490f57a6c7072e0a9b44e [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests for PaymentRequest::OnPaymentResponse().
#include "bindings/core/v8/ScriptFunction.h"
#include "bindings/core/v8/V8BindingForTesting.h"
#include "bindings/modules/v8/V8PaymentResponse.h"
#include "modules/payments/PaymentAddress.h"
#include "modules/payments/PaymentRequest.h"
#include "modules/payments/PaymentTestHelper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <utility>
namespace blink {
namespace {
// If the merchant requests shipping information, but the browser does not
// provide the shipping option, reject the show() promise.
TEST(OnPaymentResponseTest, RejectMissingShippingOption) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
response->shipping_address->country = "US";
response->shipping_address->language_code = "en";
response->shipping_address->script_code = "Latn";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests shipping information, but the browser does not
// provide a shipping address, reject the show() promise.
TEST(OnPaymentResponseTest, RejectMissingAddress) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_option = "standardShipping";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests a payer name, but the browser does not provide it,
// reject the show() promise.
TEST(OnPaymentResponseTest, RejectMissingName) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerName(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests an email address, but the browser does not provide
// it, reject the show() promise.
TEST(OnPaymentResponseTest, RejectMissingEmail) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerEmail(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests a phone number, but the browser does not provide it,
// reject the show() promise.
TEST(OnPaymentResponseTest, RejectMissingPhone) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerPhone(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests shipping information, but the browser provides an
// empty string for shipping option, reject the show() promise.
TEST(OnPaymentResponseTest, RejectEmptyShippingOption) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_option = "";
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
response->shipping_address->country = "US";
response->shipping_address->language_code = "en";
response->shipping_address->script_code = "Latn";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests shipping information, but the browser provides an
// empty shipping address, reject the show() promise.
TEST(OnPaymentResponseTest, RejectEmptyAddress) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_option = "standardShipping";
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests a payer name, but the browser provides an empty
// string for name, reject the show() promise.
TEST(OnPaymentResponseTest, RejectEmptyName) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerName(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_name = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests an email, but the browser provides an empty string
// for email, reject the show() promise.
TEST(OnPaymentResponseTest, RejectEmptyEmail) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerEmail(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_email = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests a phone number, but the browser provides an empty
// string for the phone number, reject the show() promise.
TEST(OnPaymentResponseTest, RejectEmptyPhone) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerPhone(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_phone = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant does not request shipping information, but the browser
// provides a shipping address, reject the show() promise.
TEST(OnPaymentResponseTest, RejectNotRequestedAddress) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
response->shipping_address->country = "US";
response->shipping_address->language_code = "en";
response->shipping_address->script_code = "Latn";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant does not request shipping information, but the browser
// provides a shipping option, reject the show() promise.
TEST(OnPaymentResponseTest, RejectNotRequestedShippingOption) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->shipping_option = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant does not request a payer name, but the browser provides it,
// reject the show() promise.
TEST(OnPaymentResponseTest, RejectNotRequestedName) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerName(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_name = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant does not request an email, but the browser provides it,
// reject the show() promise.
TEST(OnPaymentResponseTest, RejectNotRequestedEmail) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerEmail(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_email = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant does not request a phone number, but the browser provides it,
// reject the show() promise.
TEST(OnPaymentResponseTest, RejectNotRequestedPhone) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerPhone(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_phone = "";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
// If the merchant requests shipping information, but the browser provides an
// invalid shipping address, reject the show() promise.
TEST(OnPaymentResponseTest, RejectInvalidAddress) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_option = "standardShipping";
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
response->shipping_address->country = "Atlantis";
request->show(scope.getScriptState())
.then(funcs.expectNoCall(), funcs.expectCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
}
class PaymentResponseFunction : public ScriptFunction {
public:
static v8::Local<v8::Function> create(ScriptState* scriptState,
ScriptValue* outValue) {
PaymentResponseFunction* self =
new PaymentResponseFunction(scriptState, outValue);
return self->bindToV8Function();
}
private:
PaymentResponseFunction(ScriptState* scriptState, ScriptValue* outValue)
: ScriptFunction(scriptState), m_value(outValue) {
DCHECK(m_value);
}
ScriptValue call(ScriptValue value) override {
DCHECK(!value.isEmpty());
*m_value = value;
return value;
}
ScriptValue* const m_value;
};
// If the merchant requests shipping information, the resolved show() promise
// should contain a shipping option and an address.
TEST(OnPaymentResponseTest, CanRequestShippingInformation) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
buildPaymentResponseForTest();
response->shipping_option = "standardShipping";
response->shipping_address = payments::mojom::blink::PaymentAddress::New();
response->shipping_address->country = "US";
response->shipping_address->language_code = "en";
response->shipping_address->script_code = "Latn";
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_EQ("standardShipping", resp->shippingOption());
EXPECT_EQ("US", resp->shippingAddress()->country());
EXPECT_EQ("en-Latn", resp->shippingAddress()->languageCode());
}
// If the merchant requests a payer name, the resolved show() promise should
// contain a payer name.
TEST(OnPaymentResponseTest, CanRequestName) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerName(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_name = "Jon Doe";
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_EQ("Jon Doe", pr->payerName());
}
// If the merchant requests an email address, the resolved show() promise should
// contain an email address.
TEST(OnPaymentResponseTest, CanRequestEmail) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerEmail(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_email = "abc@gmail.com";
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_EQ("abc@gmail.com", pr->payerEmail());
}
// If the merchant requests a phone number, the resolved show() promise should
// contain a phone number.
TEST(OnPaymentResponseTest, CanRequestPhone) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerPhone(true);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_phone = "0123";
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_EQ("0123", pr->payerPhone());
}
// If the merchant does not request shipping information, the resolved show()
// promise should contain null shipping option and address.
TEST(OnPaymentResponseTest, ShippingInformationNotRequired) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestShipping(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
ASSERT_FALSE(scope.getExceptionState().hadException());
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(buildPaymentResponseForTest());
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_TRUE(resp->shippingOption().isNull());
EXPECT_EQ(nullptr, resp->shippingAddress());
}
// If the merchant does not request a phone number, the resolved show() promise
// should contain null phone number.
TEST(OnPaymentResponseTest, PhoneNotRequred) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerPhone(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_phone = String();
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_TRUE(pr->payerPhone().isNull());
}
// If the merchant does not request a payer name, the resolved show() promise
// should contain null payer name.
TEST(OnPaymentResponseTest, NameNotRequired) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerName(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_name = String();
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_TRUE(pr->payerName().isNull());
}
// If the merchant does not request an email address, the resolved show()
// promise should contain null email address.
TEST(OnPaymentResponseTest, EmailNotRequired) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.getScriptState());
makePaymentRequestOriginSecure(scope.document());
PaymentOptions options;
options.setRequestPayerEmail(false);
PaymentRequest* request = PaymentRequest::create(
scope.getScriptState(), buildPaymentMethodDataForTest(),
buildPaymentDetailsForTest(), options, scope.getExceptionState());
EXPECT_FALSE(scope.getExceptionState().hadException());
payments::mojom::blink::PaymentResponsePtr response =
payments::mojom::blink::PaymentResponse::New();
response->payer_email = String();
ScriptValue outValue;
request->show(scope.getScriptState())
.then(PaymentResponseFunction::create(scope.getScriptState(), &outValue),
funcs.expectNoCall());
static_cast<payments::mojom::blink::PaymentRequestClient*>(request)
->OnPaymentResponse(std::move(response));
v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(
scope.isolate(), outValue.v8Value());
EXPECT_TRUE(pr->payerEmail().isNull());
}
} // namespace
} // namespace blink