blob: 5e4c469104e270b056c226afa99e13cc8b14629a [file] [log] [blame]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests for providing `displayItems` to `PaymentRequestUpdateEvent.prototype.updateWith`.</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 });
const method = validPaymentMethod();
const detailsInit = validPaymentDetails();
const detailsUpdate = {
displayItems: [
{
label: 'Item 1',
amount: {
currency: 'USD',
value: '5.00',
},
},
{
label: 'Item 2',
amount: {
currency: 'USD',
value: '15.00',
},
},
],
};
user_activation_test(async (test) => {
let request = new PaymentRequest([method], detailsInit);
request.addEventListener("merchantvalidation", (event) => {
event.complete({ });
});
request.addEventListener("shippingaddresschange", (event) => {
event.updateWith(detailsUpdate);
internals.mockPaymentCoordinator.acceptPayment();
});
let response = await request.show();
assert_equals(internals.mockPaymentCoordinator.total.label, detailsInit.total.label, "label of total should not change");
assert_equals(internals.mockPaymentCoordinator.total.amount, detailsInit.total.amount.value, "value of total should not change");
assert_equals(internals.mockPaymentCoordinator.lineItems.length, detailsUpdate.displayItems.length, "number of display items should change");
for (let i = 0; i < detailsUpdate.displayItems.length; ++i) {
assert_equals(internals.mockPaymentCoordinator.lineItems[i].label, detailsUpdate.displayItems[i].label, `display item ${i} label should change`);
assert_equals(internals.mockPaymentCoordinator.lineItems[i].amount, detailsUpdate.displayItems[i].amount.value, `display item ${i} value should change`);
}
await response.complete("success");
}, "Calling `updateWith` with a new `displayItems` should not update any other values.");
done();
</script>