зеркало из https://github.com/mozilla/gecko-dev.git
155 строки
3.2 KiB
HTML
155 строки
3.2 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1367669
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for Bug 1345367</title>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="application/javascript">
|
|
|
|
"use strict";
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
// process total
|
|
const invalidAmounts = [
|
|
"-",
|
|
"notdigits",
|
|
"ALSONOTDIGITS",
|
|
"10.",
|
|
".99",
|
|
"-10.",
|
|
"-.99",
|
|
"10-",
|
|
"1-0",
|
|
"1.0.0",
|
|
"1/3",
|
|
"",
|
|
null,
|
|
" 1.0 ",
|
|
" 1.0 ",
|
|
"1.0 ",
|
|
"USD$1.0",
|
|
"$1.0",
|
|
{
|
|
toString() {
|
|
return " 1.0";
|
|
},
|
|
},
|
|
];
|
|
const invalidTotalAmounts = invalidAmounts.concat([
|
|
"-1",
|
|
"-1.0",
|
|
"-1.00",
|
|
"-1000.000",
|
|
]);
|
|
|
|
|
|
|
|
function testInvalidTotalAmounts() {
|
|
return new Promise((resolve, reject) => {
|
|
for (const amount of invalidTotalAmounts) {
|
|
try {
|
|
new PaymentRequest(
|
|
[
|
|
{
|
|
supportedMethods: "basic-card",
|
|
},
|
|
],
|
|
{
|
|
total: {
|
|
label: "",
|
|
amount: {
|
|
currency: "USD",
|
|
value: amount,
|
|
},
|
|
},
|
|
}
|
|
);
|
|
|
|
ok(false, "Should throw 'TypeError', but got resolved.");
|
|
resolve();
|
|
}
|
|
catch (err) {
|
|
is(err.name, "TypeError",
|
|
"Expected 'TypeError', but got '" + err.name + "'");
|
|
resolve();
|
|
};
|
|
}
|
|
});
|
|
}
|
|
|
|
function testInvalidAmounts() {
|
|
return new Promise((resolve, reject) => {
|
|
for (const amount of invalidAmounts) {
|
|
try {
|
|
new PaymentRequest(
|
|
[
|
|
{
|
|
supportedMethods: "basic-card",
|
|
},
|
|
],
|
|
{
|
|
total: {
|
|
label: "",
|
|
amount: {
|
|
currency: "USD",
|
|
value: "1.00",
|
|
},
|
|
},
|
|
displayItems: [
|
|
{
|
|
label: "",
|
|
amount: {
|
|
currency: "USD",
|
|
value: amount,
|
|
},
|
|
},
|
|
],
|
|
}
|
|
);
|
|
ok(false, "Should throw 'TypeError', but got resolved.");
|
|
resolve();
|
|
}
|
|
catch (err) {
|
|
is(err.name, "TypeError",
|
|
"Expected 'TypeError', but got '" + err.name + "'");
|
|
resolve();
|
|
};
|
|
}
|
|
});
|
|
}
|
|
|
|
function runTests() {
|
|
testInvalidTotalAmounts()
|
|
.then(testInvalidAmounts)
|
|
.then(SimpleTest.finish)
|
|
.catch( e => {
|
|
ok(false, "Unexpected error: " + e.name);
|
|
SimpleTest.finish();
|
|
});
|
|
}
|
|
|
|
window.addEventListener('load', function() {
|
|
SpecialPowers.pushPrefEnv({
|
|
'set': [
|
|
['dom.payments.request.enabled', true],
|
|
]
|
|
}, runTests);
|
|
});
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1367669">Mozilla Bug 1367669</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
</pre>
|
|
</body>
|
|
</html>
|