| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <script> |
| |
| description("Test basic creation of an ApplePaySession object."); |
| |
| window.jsTestIsAsync = true; |
| |
| function validRequest() { |
| return { |
| countryCode: 'US', |
| currencyCode: 'USD', |
| supportedNetworks: ['visa', 'masterCard', 'carteBancaire'], |
| merchantCapabilities: ['supports3DS'], |
| total: { label: 'Your Label', amount: '10.00' }, |
| } |
| } |
| |
| function logAndShouldThrow(setup, test) { |
| debug("SETUP: " + setup) |
| eval(setup); |
| shouldThrow(test); |
| debug("") |
| } |
| |
| function logAndShouldNotThrow(setup, test) { |
| debug("SETUP: " + setup) |
| eval(setup); |
| shouldNotThrow(test); |
| debug("") |
| } |
| |
| function go() { |
| debug("Testing supportsVersion"); |
| debug(""); |
| shouldThrow("ApplePaySession.supportsVersion(0)"); |
| shouldBeTrue("ApplePaySession.supportsVersion(1)"); |
| shouldBeTrue("ApplePaySession.supportsVersion(2)"); |
| shouldBeTrue("ApplePaySession.supportsVersion(3)"); |
| debug(""); |
| |
| debug("Testing PaymentRequest (v3)") |
| debug(""); |
| shouldThrow("new ApplePaySession(3, { })"); |
| shouldNotThrow("new ApplePaySession(3, validRequest())"); |
| debug(""); |
| |
| debug("Testing PaymentRequest.supportedCountries"); |
| debug(""); |
| |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = ['invalid'];", "new ApplePaySession(3, request)"); |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = ['US', 'invalid'];", "new ApplePaySession(3, request)"); |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = ['US', 7];", "new ApplePaySession(3, request)"); |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = '';", "new ApplePaySession(3, request)"); |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = 7;", "new ApplePaySession(3, request)"); |
| logAndShouldThrow("request = validRequest(); request.supportedCountries = null;", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); delete request.supportedCountries;", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); request.supportedCountries = undefined;", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); request.supportedCountries = [];", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); request.supportedCountries = ['US'];", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); request.supportedCountries = ['US', 'US'];", "new ApplePaySession(3, request)"); |
| logAndShouldNotThrow("request = validRequest(); request.requiredBillingContactFields = ['phoneticName'];", "new ApplePaySession(3, request)") |
| logAndShouldNotThrow("request = validRequest(); request.requiredShippingContactFields = ['phoneticName'];", "new ApplePaySession(3, request)") |
| debug(""); |
| |
| 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> |