summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html')
-rw-r--r--testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html222
1 files changed, 221 insertions, 1 deletions
diff --git a/testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html b/testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html
index c1ecc22583..9b0ad06454 100644
--- a/testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html
+++ b/testing/web-platform/tests/payment-request/payment-request-constructor.https.sub.html
@@ -240,7 +240,7 @@ test(() => {
test(() => {
smokeTest();
- for (const prop in ["displayItems", "modifiers"]) {
+ for (const prop in ["displayItems", "shippingOptions", "modifiers"]) {
try {
const details = Object.assign({}, defaultDetails, { [prop]: [] });
new PaymentRequest(defaultMethods, details);
@@ -361,6 +361,186 @@ test(() => {
}
}, "it handles high precision currency values without throwing");
+// Process shipping options:
+
+const defaultShippingOption = Object.freeze({
+ id: "default",
+ label: "",
+ amount: defaultAmount,
+ selected: false,
+});
+const defaultShippingOptions = Object.freeze([
+ Object.assign({}, defaultShippingOption),
+]);
+
+test(() => {
+ smokeTest();
+ for (const amount of invalidAmounts) {
+ const invalidAmount = Object.assign({}, defaultAmount, {
+ value: amount,
+ });
+ const invalidShippingOption = Object.assign({}, defaultShippingOption, {
+ amount: invalidAmount,
+ });
+ const details = Object.assign({}, defaultDetails, {
+ shippingOptions: [invalidShippingOption],
+ });
+ assert_throws_js(
+ TypeError,
+ () => {
+ new PaymentRequest(defaultMethods, details, { requestShipping: true });
+ },
+ `Expected TypeError for option.amount.value: "${amount}"`
+ );
+ }
+}, `For each option in details.shippingOptions: if option.amount.value is not a valid decimal monetary value, then throw a TypeError`);
+
+test(() => {
+ smokeTest();
+ const shippingOptions = [defaultShippingOption];
+ const details = Object.assign({}, defaultDetails, { shippingOptions });
+ const request = new PaymentRequest(defaultMethods, details);
+ assert_equals(
+ request.shippingOption,
+ null,
+ "shippingOption must be null, as requestShipping is missing"
+ );
+ // defaultDetails lacks shipping options
+ const request2 = new PaymentRequest(defaultMethods, defaultDetails, {
+ requestShipping: true,
+ });
+ assert_equals(
+ request2.shippingOption,
+ null,
+ `request2.shippingOption must be null`
+ );
+}, "If there is no selected shipping option, then PaymentRequest.shippingOption remains null");
+
+test(() => {
+ smokeTest();
+ const selectedOption = Object.assign({}, defaultShippingOption, {
+ selected: true,
+ id: "the-id",
+ });
+ const shippingOptions = [selectedOption];
+ const details = Object.assign({}, defaultDetails, { shippingOptions });
+ const requestNoShippingRequested1 = new PaymentRequest(
+ defaultMethods,
+ details
+ );
+ assert_equals(
+ requestNoShippingRequested1.shippingOption,
+ null,
+ "Must be null when no shipping is requested (defaults to false)"
+ );
+ const requestNoShippingRequested2 = new PaymentRequest(
+ defaultMethods,
+ details,
+ { requestShipping: false }
+ );
+ assert_equals(
+ requestNoShippingRequested2.shippingOption,
+ null,
+ "Must be null when requestShipping is false"
+ );
+ const requestWithShipping = new PaymentRequest(defaultMethods, details, {
+ requestShipping: "truthy value",
+ });
+ assert_equals(
+ requestWithShipping.shippingOption,
+ "the-id",
+ "Selected option must be 'the-id'"
+ );
+}, "If there is a selected shipping option, and requestShipping is set, then that option becomes synchronously selected");
+
+test(() => {
+ smokeTest();
+ const failOption1 = Object.assign({}, defaultShippingOption, {
+ selected: true,
+ id: "FAIL1",
+ });
+ const failOption2 = Object.assign({}, defaultShippingOption, {
+ selected: false,
+ id: "FAIL2",
+ });
+ const passOption = Object.assign({}, defaultShippingOption, {
+ selected: true,
+ id: "the-id",
+ });
+ const shippingOptions = [failOption1, failOption2, passOption];
+ const details = Object.assign({}, defaultDetails, { shippingOptions });
+ const requestNoShipping = new PaymentRequest(defaultMethods, details, {
+ requestShipping: false,
+ });
+ assert_equals(
+ requestNoShipping.shippingOption,
+ null,
+ "shippingOption must be null, as requestShipping is false"
+ );
+ const requestWithShipping = new PaymentRequest(defaultMethods, details, {
+ requestShipping: true,
+ });
+ assert_equals(
+ requestWithShipping.shippingOption,
+ "the-id",
+ "selected option must 'the-id"
+ );
+}, "If requestShipping is set, and if there is a multiple selected shipping options, only the last is selected.");
+
+test(() => {
+ smokeTest();
+ const selectedOption = Object.assign({}, defaultShippingOption, {
+ selected: true,
+ });
+ const unselectedOption = Object.assign({}, defaultShippingOption, {
+ selected: false,
+ });
+ const shippingOptions = [selectedOption, unselectedOption];
+ const details = Object.assign({}, defaultDetails, { shippingOptions });
+ const requestNoShipping = new PaymentRequest(defaultMethods, details);
+ assert_equals(
+ requestNoShipping.shippingOption,
+ null,
+ "shippingOption must be null, because requestShipping is false"
+ );
+ assert_throws_js(
+ TypeError,
+ () => {
+ new PaymentRequest(defaultMethods, details, { requestShipping: true });
+ },
+ "Expected to throw a TypeError because duplicate IDs"
+ );
+}, "If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError");
+
+test(() => {
+ smokeTest();
+ const dupShipping1 = Object.assign({}, defaultShippingOption, {
+ selected: true,
+ id: "DUPLICATE",
+ label: "Fail 1",
+ });
+ const dupShipping2 = Object.assign({}, defaultShippingOption, {
+ selected: false,
+ id: "DUPLICATE",
+ label: "Fail 2",
+ });
+ const shippingOptions = [dupShipping1, defaultShippingOption, dupShipping2];
+ const details = Object.assign({}, defaultDetails, { shippingOptions });
+ const requestNoShipping = new PaymentRequest(defaultMethods, details);
+ assert_equals(
+ requestNoShipping.shippingOption,
+ null,
+ "shippingOption must be null, because requestShipping is false"
+ );
+ assert_throws_js(
+ TypeError,
+ () => {
+ new PaymentRequest(defaultMethods, details, { requestShipping: true });
+ },
+ "Expected to throw a TypeError because duplicate IDs"
+ );
+}, "Throw when there are duplicate shippingOption ids, even if other values are different");
+
// Process payment details modifiers:
test(() => {
smokeTest();
@@ -474,4 +654,44 @@ test(() => {
});
}, "Rethrow any exceptions of JSON-serializing modifier.data");
+//Setting ShippingType attribute during construction
+test(() => {
+ smokeTest();
+ assert_throws_js(TypeError, () => {
+ new PaymentRequest(defaultMethods, defaultDetails, {
+ shippingType: "invalid",
+ });
+ });
+}, "Shipping type should be valid");
+
+test(() => {
+ smokeTest();
+ const request = new PaymentRequest(defaultMethods, defaultDetails, {});
+ assert_equals(request.shippingAddress, null, "must be null");
+}, "PaymentRequest.shippingAddress must initially be null");
+
+test(() => {
+ smokeTest();
+ 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");
+}, "If options.requestShipping is not set, then request.shippingType attribute is null.");
+
+test(() => {
+ smokeTest();
+ // option.shippingType defaults to 'shipping'
+ const request1 = new PaymentRequest(defaultMethods, defaultDetails, {
+ requestShipping: true,
+ });
+ assert_equals(request1.shippingType, "shipping", "must be shipping");
+ const request2 = new PaymentRequest(defaultMethods, defaultDetails, {
+ requestShipping: true,
+ shippingType: "delivery",
+ });
+ assert_equals(request2.shippingType, "delivery", "must be delivery");
+}, "If options.requestShipping is true, request.shippingType will be options.shippingType.");
+
</script>