blob: 9e979e92c14f43f43e5c3cf489afe4e27d168691 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/js-test-resources/ui-helper.js"></script>
<script src="/resources/js-test-pre.js"></script>
<script src="/resources/payment-request.js"></script>
</head>
<body>
<script>
description("Test basic creation of a PaymentRequest object with an Apple Pay payment method.");
window.jsTestIsAsync = true;
function validPaymentMethod() {
return {
supportedMethods: 'https://apple.com/apple-pay',
data: {
version: 2,
merchantIdentifier: '',
countryCode: 'US',
supportedNetworks: ['visa', 'masterCard'],
merchantCapabilities: ['supports3DS'],
},
}
}
function validPaymentDetails() {
return {
total: { label: 'Your label', amount: { currency: 'USD', value: '10.00' } },
}
}
function logAndShouldThrow(setup, test) {
return activateThen(() => {
debug("SETUP: " + setup);
eval(setup);
shouldThrow(test);
debug("");
});
}
function logAndShouldReject(setup, test) {
return activateThen(() => {
debug("SETUP: " + setup)
eval(setup)
return shouldReject(test)
});
}
async function go() {
debug("Testing PaymentRequest")
debug("")
shouldThrow("new PaymentRequest(null, null)")
shouldNotThrow("new PaymentRequest([validPaymentMethod()], validPaymentDetails())")
debug("")
debug("Testing ApplePayRequest.version")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 0;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 1000;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.countryCode")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); delete paymentMethod.data.countryCode;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 'invalid';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = undefined;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.supportedNetworks")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); delete paymentMethod.data.supportedNetworks;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = undefined;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = [];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork', 'visa'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.merchantCapabilities")
debug("");
await logAndShouldReject("paymentMethod = validPaymentMethod(); delete paymentMethod.data.merchantCapabilities;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = undefined;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = [];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability', 'supports3DS'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.requiredBillingContactFields")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = { };", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [''];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [null];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [undefined];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [{}];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = ['invalid'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.billingContact")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = '';", "new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.requiredShippingContactFields")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = { };", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [''];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [null];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [undefined];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [{}];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = ['invalid'];", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.shippingContact")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = '';", "new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing ApplePayRequest.applicationData")
debug("")
await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.applicationData = { toString: function() { throw '\"Error in toString\"'; } };", "new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")
debug("")
debug("Testing PaymentDetails.total")
debug("")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); delete paymentDetails.total;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = '';", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = null;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = undefined;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = 7;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = [];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label' };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: 'amount' };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: '', value: '0' } };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
debug("")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value:'-10.00'} };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value: '10000000000.00' } };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
debug("")
debug("Testing PaymentDetails.displayItems")
debug("");
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = '';", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = null;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = 7;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = { };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [''];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [null];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [undefined];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{}];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '10.00', type: 'invalid' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: { currency: 'EUR', value: '10.00' } }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
debug("Testing PaymentDetails.shippingOptions")
debug("");
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = '';", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 'invalid';", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = null;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 7;", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = { };", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()")
debug("Testing PaymentOptions")
debug("");
await logAndShouldThrow("paymentOptions = {}; paymentOptions.shippingType = '';", "new PaymentRequest([validPaymentMethod()], validPaymentDetails(), paymentOptions); request.show()")
await logAndShouldThrow("paymentOptions = {}; paymentOptions.shippingType = 'invalid';", "new PaymentRequest([validPaymentMethod()], validPaymentDetails(), paymentOptions); request.show()")
await logAndShouldThrow("paymentOptions = {}; paymentOptions.shippingType = null;", "new PaymentRequest([validPaymentMethod()], validPaymentDetails(), paymentOptions); request.show()")
await logAndShouldThrow("paymentOptions = {}; paymentOptions.shippingType = 7;", "new PaymentRequest([validPaymentMethod()], validPaymentDetails(), paymentOptions); request.show()")
await logAndShouldThrow("paymentOptions = {}; paymentOptions.shippingType = { };", "new PaymentRequest([validPaymentMethod()], validPaymentDetails(), paymentOptions); request.show()")
document.querySelector("button").remove();
finishJSTest();
}
function clickElement(element) {
let x = element.offsetLeft + 2;
let y = element.offsetTop + 2;
var supportsTouchEvents = "TouchEvent" in window;
if (supportsTouchEvents && window.testRunner && testRunner.runUIScript) {
testRunner.runUIScript(`(function() { uiController.singleTapAtPoint(${x}, ${y}, function() { }); })();`, function () { });
} else if (window.eventSender) {
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
}
}
window.onload = function() {
clickElement(document.querySelector("button"));
}
</script>
<button onclick='go()'>Go</button>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>