blob: 52dcc2cca0d20934fd701d6e378f8309f0a312cd [file] [log] [blame] [edit]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests for providing `applePayLaterMode` in `data` as part of `PaymentMethodData`.</title>
<script src="/js-test-resources/ui-helper.js"></script>
<script src="/resources/payment-request.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
setup({ explicit_done: true, explicit_timeout: true });
test((test) => {
const method = validPaymentMethod();
method.data.features = ["applePayLaterMode"];
new PaymentRequest([method], validPaymentDetails());
}, "Should have a feature for `applePayLaterMode`.");
test((test) => {
const method = validPaymentMethod();
method.data.applePayLaterMode = "invalid";
assert_throws_js(
TypeError,
() => {
new PaymentRequest([method], validPaymentDetails());
},
);
}, "Should throw `TypeError` when invalid `applePayLaterMode` is set.");
user_activation_test(async (test) => {
let request = new PaymentRequest([validPaymentMethod()], validPaymentDetails());
request.addEventListener("merchantvalidation", (event) => {
event.complete({ });
});
request.addEventListener("shippingaddresschange", (event) => {
assert_equals(internals.mockPaymentCoordinator.applePayLaterMode, null, "check that the `applePayLaterMode` is still `null` after an update");
event.updateWith({ });
internals.mockPaymentCoordinator.acceptPayment();
});
let response = await request.show();
assert_equals(internals.mockPaymentCoordinator.applePayLaterMode, null, "check that the `applePayLaterMode` is still `null` after the payment is accepted");
await response.complete("success");
}, "Should not have a default value for `applePayLaterMode`.");
user_activation_test(async (test) => {
const method = validPaymentMethod();
method.data.applePayLaterMode = "disabledMerchantIneligible";
let request = new PaymentRequest([method], validPaymentDetails());
request.addEventListener("merchantvalidation", (event) => {
event.complete({ });
});
request.addEventListener("shippingaddresschange", (event) => {
assert_equals(internals.mockPaymentCoordinator.applePayLaterMode, method.data.applePayLaterMode, "check that the `applePayLaterMode` still matches after an update");
event.updateWith({ });
internals.mockPaymentCoordinator.acceptPayment();
});
let response = await request.show();
assert_equals(internals.mockPaymentCoordinator.applePayLaterMode, method.data.applePayLaterMode, "check that the `applePayLaterMode` still matches after the payment is accepted");
await response.complete("success");
}, "Should propagate `applePayLaterMode` if provided.");
done();
</script>