<!DOCTYPE html>
<!-- Copyright © 2017 Mozilla and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<title>Test for PaymentRequest's shippingType attribute</title>
<link rel="help" href="https://w3c.github.io/payment-request/#shippingtype-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
const paymentShipingTypes = Object.freeze(["delivery", "pickup", "shipping"]);
const applePay = Object.freeze({
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 3,
merchantIdentifier: "merchant.com.example",
countryCode: "US",
merchantCapabilities: ["supports3DS"],
supportedNetworks: ["visa"],
}
});
const basicCard = Object.freeze({ supportedMethods: "basic-card" });
const defaultMethods = Object.freeze([basicCard, applePay]);
const defaultDetails = Object.freeze({
total: {
label: "",
amount: {
currency: "USD",
value: "1.00",
},
},
});
test(() => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
assert_idl_attribute(request, "shippingType");
}, "Must have a shippingType IDL attribute");
test(() => {
const request1 = new PaymentRequest(defaultMethods, defaultDetails, {});
assert_equals(request1.shippingType, null, "must be null");
const request2 = new PaymentRequest(defaultMethods, defaultDetails, {
requestShipping: false,
});
assert_equals(request2.shippingType, null, "must be null");
for (const shippingType of paymentShipingTypes) {
const request = new PaymentRequest(defaultMethods, defaultDetails, {
requestShipping: false,
shippingType,
});
assert_equals(request.shippingType, null, "must be null");
}
}, "If options.requestShipping is false, then request.shippingType attribute is null.");
test(() => {
// option.shippingType defaults to 'shipping'
const defaultRequest = new PaymentRequest(defaultMethods, defaultDetails, {
requestShipping: true,
});
assert_equals(defaultRequest.shippingType, "shipping", "must be shipping");
for (const shippingType of paymentShipingTypes) {
const request = new PaymentRequest(defaultMethods, defaultDetails, {
requestShipping: true,
shippingType,
});
assert_equals(
request.shippingType,
shippingType,
`must be ${shippingType}`
);
}
}, "If options.requestShipping is true, request.shippingType will be options.shippingType.");
</script>