mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-30 14:17:36 -10:00
395 lines
8.2 KiB
HTML
395 lines
8.2 KiB
HTML
<!DOCTYPE html>
|
|
<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
|
|
<meta charset="utf-8">
|
|
<title>Test for PaymentRequest Constructor</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>
|
|
'use strict';
|
|
|
|
test(() => {
|
|
assert_equals((new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
id: 'foo',
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
})).id, 'foo');
|
|
}, 'Use provided request ID');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'If the length of the methodData sequence is zero, then throw a TypeError');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: [],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'If the length of the paymentMethod.supportedMethods sequence is zero, ' +
|
|
'then throw a TypeError');
|
|
|
|
test(() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
data: ['some-data'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
}, 'Method data must be JSON-serializable object (a list in this case)');
|
|
|
|
test(() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
data: {
|
|
some: 'data',
|
|
},
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
}, 'Method data must be JSON-serializable object (a dictionary in this case)');
|
|
|
|
test(() => {
|
|
const recursiveDictionary = {};
|
|
recursiveDictionary.foo = recursiveDictionary;
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
data: recursiveDictionary,
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
data: 'a string',
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'Rethrow any exceptions of JSON-serializing paymentMethod.data into ' +
|
|
'a string');
|
|
|
|
const invalidMonetaryAmounts = ['-', 'notdigits', 'ALSONOTDIGITS', '10.', '.99',
|
|
'-10.', '-.99', '10-', '1-0', '1.0.0', '1/3', '', null,
|
|
];
|
|
for (const amount of invalidMonetaryAmounts) {
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: amount,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'If details.total.amount.value is not a valid decimal monetary value ' +
|
|
'(in this case "' + amount + '"), then throw a TypeError');
|
|
}
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '-1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'If the first character of details.total.amount.value is ' +
|
|
'U+002D HYPHEN-MINUS, then throw a TypeError');
|
|
|
|
for (const amount of invalidMonetaryAmounts) {
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
displayItems: [{
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: amount,
|
|
},
|
|
}],
|
|
});
|
|
});
|
|
}, 'For each item in details.displayItems: if item.amount.value is not ' +
|
|
'a valid decimal monetary value (in this case "' + amount +
|
|
'"), then throw a TypeError');
|
|
}
|
|
|
|
test(() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
modifiers: [{
|
|
supportedMethods: ['basic-card'],
|
|
data: ['some-data'],
|
|
}],
|
|
});
|
|
}, 'Modifier data must be JSON-serializable object (a list in this case)');
|
|
|
|
test(() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
modifiers: [{
|
|
supportedMethods: ['basic-card'],
|
|
data: {
|
|
some: 'data',
|
|
},
|
|
}],
|
|
});
|
|
}, 'Modifier data must be JSON-serializable object (a dictionary in this ' +
|
|
'case)');
|
|
|
|
test(() => {
|
|
const recursiveDictionary = {};
|
|
recursiveDictionary.foo = recursiveDictionary;
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
modifiers: [{
|
|
supportedMethods: ['basic-card'],
|
|
data: recursiveDictionary,
|
|
}],
|
|
});
|
|
});
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
modifiers: [{
|
|
supportedMethods: ['basic-card'],
|
|
data: 'a string',
|
|
}],
|
|
});
|
|
});
|
|
}, 'Rethrow any exceptions of JSON-serializing modifier.data into a string');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {});
|
|
});
|
|
}, 'Total is required');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'Label is required');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
},
|
|
});
|
|
});
|
|
}, 'Amount is required');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'Amount value is required');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
value: '1.00',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}, 'Amount currency is required');
|
|
|
|
test(() => {
|
|
assert_throws({
|
|
name: 'TypeError',
|
|
},
|
|
() => {
|
|
new PaymentRequest([{
|
|
supportedMethods: ['basic-card'],
|
|
}], {
|
|
total: {
|
|
label: '',
|
|
amount: {
|
|
currency: 'USD',
|
|
value: '1.00',
|
|
},
|
|
},
|
|
}, {
|
|
shippingType: 'invalid',
|
|
});
|
|
});
|
|
}, 'Shipping type should be valid');
|
|
</script>
|