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
73
|
<!DOCTYPE html> <meta charset="utf-8" />
<title>Validates PaymentMethodData's data member during construction</title>
<link
rel="help"
href="https://w3c.github.io/browser-payment-api/#constructor"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const details = {
total: {
label: "Total",
amount: {
currency: "USD",
value: "0.00",
},
},
};
test(() => {
new PaymentRequest([{ supportedMethods: "basic-card" }], details);
new PaymentRequest(
[{ supportedMethods: "https://apple.com/apple-pay" }],
details
);
}, "Smoke test.");
const knownPMIs = ["basic-card", "https://apple.com/apple-pay"];
const unknownPMIs = ["fake-pmi", "https://does-not.exist"];
promise_test(async t => {
for (const supportedMethods of [].concat(knownPMIs).concat(unknownPMIs)) {
const method = { supportedMethods };
const request = new PaymentRequest([method], details);
assert_throws_js(
TypeError,
() => {
const badMethod = Object.assign(
{},
method,
{ data: 123 } // <- this will throw
);
new PaymentRequest([badMethod], details);
},
"PaymentMethodData.data can't be converted to an Object."
);
}
}, "Tries to convert data member during Payment Request construction, irrespective of PMI.");
promise_test(async t => {
for (const supportedMethods of knownPMIs) {
const method = { supportedMethods };
const request = new PaymentRequest([method], details);
// Only check the PMIs that are actually supported
if (!(await request.canMakePayment())) continue;
assert_throws_js(
TypeError,
() => {
const badMethod = Object.assign(
{},
method,
/* This is invalid in both Apple Pay and Basic Card */
{ data: { supportedNetworks: "this will throw" } }
);
new PaymentRequest([badMethod], details);
},
"PaymentMethodData.data is invalid."
);
}
}, "Converts PaymentMethodData's data to mandated IDL type during PaymentRequest construction.");
</script>
|