DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (491b05117886)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<!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>