mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-11-03 19:05:35 +00:00
764 lines
35 KiB
HTML
764 lines
35 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<html>
|
||
|
<!--
|
||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=636627
|
||
|
-->
|
||
|
<head>
|
||
|
<title>Test for Bug 636627</title>
|
||
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||
|
</head>
|
||
|
<body>
|
||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=636627">Mozilla Bug 636627</a>
|
||
|
<p id="display"></p>
|
||
|
<pre id="test">
|
||
|
<script type="application/javascript">
|
||
|
|
||
|
/** Test for Bug 636627 **/
|
||
|
|
||
|
/**
|
||
|
* This test is testing stepDown() and stepUp().
|
||
|
*/
|
||
|
|
||
|
function checkPresence()
|
||
|
{
|
||
|
var input = document.createElement('input');
|
||
|
is('stepDown' in input, true, 'stepDown() should be an input function');
|
||
|
is('stepUp' in input, true, 'stepUp() should be an input function');
|
||
|
}
|
||
|
|
||
|
function checkAvailability()
|
||
|
{
|
||
|
var testData =
|
||
|
[
|
||
|
["text", false],
|
||
|
["password", false],
|
||
|
["search", false],
|
||
|
["telephone", false],
|
||
|
["email", false],
|
||
|
["url", false],
|
||
|
["hidden", false],
|
||
|
["checkbox", false],
|
||
|
["radio", false],
|
||
|
["file", false],
|
||
|
["submit", false],
|
||
|
["image", false],
|
||
|
["reset", false],
|
||
|
["button", false],
|
||
|
["number", true],
|
||
|
["range", true],
|
||
|
["date", true],
|
||
|
["time", true],
|
||
|
["color", false],
|
||
|
];
|
||
|
|
||
|
var todoList =
|
||
|
[
|
||
|
["datetime", true],
|
||
|
["month", true],
|
||
|
["week", true],
|
||
|
["datetime-local", true],
|
||
|
];
|
||
|
|
||
|
var element = document.createElement("input");
|
||
|
element.setAttribute('value', '0');
|
||
|
|
||
|
for (data of testData) {
|
||
|
var exceptionCaught = false;
|
||
|
element.type = data[0];
|
||
|
try {
|
||
|
element.stepDown();
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
}
|
||
|
is(exceptionCaught, !data[1], "stepDown() availability is not correct");
|
||
|
|
||
|
exceptionCaught = false;
|
||
|
try {
|
||
|
element.stepUp();
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
}
|
||
|
is(exceptionCaught, !data[1], "stepUp() availability is not correct");
|
||
|
}
|
||
|
|
||
|
for (data of todoList) {
|
||
|
var exceptionCaught = false;
|
||
|
element.type = data[0];
|
||
|
try {
|
||
|
element.stepDown();
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
}
|
||
|
todo_is(exceptionCaught, !data[1],
|
||
|
"stepDown() availability is not correct");
|
||
|
|
||
|
exceptionCaught = false;
|
||
|
try {
|
||
|
element.stepUp();
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
}
|
||
|
todo_is(exceptionCaught, !data[1],
|
||
|
"stepUp() availability is not correct");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function checkStepDown()
|
||
|
{
|
||
|
// This testData is very similar to the one in checkStepUp with some changes
|
||
|
// relative to stepDown.
|
||
|
var testData = [
|
||
|
/* Initial value | step | min | max | stepDown arg | final value | exception */
|
||
|
{ type: 'number', data: [
|
||
|
// Regular case.
|
||
|
[ '1', null, null, null, null, '0', false ],
|
||
|
// Argument testing.
|
||
|
[ '1', null, null, null, 1, '0', false ],
|
||
|
[ '9', null, null, null, 9, '0', false ],
|
||
|
[ '1', null, null, null, -1, '2', false ],
|
||
|
[ '1', null, null, null, 0, '1', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '1', null, null, null, 1.1, '0', false ],
|
||
|
// With step values.
|
||
|
[ '1', '0.5', null, null, null, '0.5', false ],
|
||
|
[ '1', '0.25', null, null, 4, '0', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '0', null, null, null, '0', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '-1', null, null, null, '0', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '1', 'foo', null, null, null, '0', false ],
|
||
|
// Min values testing.
|
||
|
[ '1', '1', 'foo', null, null, '0', false ],
|
||
|
[ '1', null, '-10', null, null, '0', false ],
|
||
|
[ '1', null, '0', null, null, '0', false ],
|
||
|
[ '1', null, '10', null, null, '1', false ],
|
||
|
[ '1', null, '2', null, null, '1', false ],
|
||
|
[ '1', null, '1', null, null, '1', false ],
|
||
|
// Max values testing.
|
||
|
[ '1', '1', null, 'foo', null, '0', false ],
|
||
|
[ '1', null, null, '10', null, '0', false ],
|
||
|
[ '1', null, null, '0', null, '0', false ],
|
||
|
[ '1', null, null, '-10', null, '-10', false ],
|
||
|
[ '1', null, null, '1', null, '0', false ],
|
||
|
[ '5', null, null, '3', '3', '2', false ],
|
||
|
[ '5', '2', '-6', '3', '2', '2', false ],
|
||
|
[ '-3', '5', '-10', '-3', null, '-5', false ],
|
||
|
// Step mismatch.
|
||
|
[ '1', '2', '-2', null, null, '0', false ],
|
||
|
[ '3', '2', '-2', null, null, '2', false ],
|
||
|
[ '3', '2', '-2', null, '2', '0', false ],
|
||
|
[ '3', '2', '-2', null, '-2', '6', false ],
|
||
|
[ '1', '2', '-6', null, null, '0', false ],
|
||
|
[ '1', '2', '-2', null, null, '0', false ],
|
||
|
[ '1', '3', '-6', null, null, '0', false ],
|
||
|
[ '2', '3', '-6', null, null, '0', false ],
|
||
|
[ '2', '3', '1', null, null, '1', false ],
|
||
|
[ '5', '3', '1', null, null, '4', false ],
|
||
|
[ '3', '2', '-6', null, null, '2', false ],
|
||
|
[ '5', '2', '-6', null, null, '4', false ],
|
||
|
[ '6', '2', '1', null, null, '5', false ],
|
||
|
[ '8', '3', '1', null, null, '7', false ],
|
||
|
[ '9', '2', '-10', null, null, '8', false ],
|
||
|
[ '7', '3', '-10', null, null, '5', false ],
|
||
|
[ '-2', '3', '-10', null, null, '-4', false ],
|
||
|
// Clamping.
|
||
|
[ '0', '2', '-1', null, null, '-1', false ],
|
||
|
[ '10', '2', '0', '4', '10', '0', false ],
|
||
|
[ '10', '2', '0', '4', '5', '0', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '-1', false ],
|
||
|
[ '', '2', null, null, null, '-2', false ],
|
||
|
[ '', '2', '3', null, null, '3', false ],
|
||
|
[ '', null, '3', null, null, '3', false ],
|
||
|
[ '', '2', '3', '8', null, '3', false ],
|
||
|
[ '', null, '-10', '10', null, '-1', false ],
|
||
|
[ '', '3', '-10', '10', null, '-1', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '0', 'any', null, null, 1, null, true ],
|
||
|
[ '0', 'ANY', null, null, 1, null, true ],
|
||
|
[ '0', 'AnY', null, null, 1, null, true ],
|
||
|
[ '0', 'aNy', null, null, 1, null, true ],
|
||
|
// With @value = step base.
|
||
|
[ '1', '2', null, null, null, '-1', false ],
|
||
|
]},
|
||
|
{ type: 'range', data: [
|
||
|
// Regular case.
|
||
|
[ '1', null, null, null, null, '0', false ],
|
||
|
// Argument testing.
|
||
|
[ '1', null, null, null, 1, '0', false ],
|
||
|
[ '9', null, null, null, 9, '0', false ],
|
||
|
[ '1', null, null, null, -1, '2', false ],
|
||
|
[ '1', null, null, null, 0, '1', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '1', null, null, null, 1.1, '0', false ],
|
||
|
// With step values.
|
||
|
[ '1', '0.5', null, null, null, '0.5', false ],
|
||
|
[ '1', '0.25', null, null, 4, '0', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '0', null, null, null, '0', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '-1', null, null, null, '0', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '1', 'foo', null, null, null, '0', false ],
|
||
|
// Min values testing.
|
||
|
[ '1', '1', 'foo', null, null, '0', false ],
|
||
|
[ '1', null, '-10', null, null, '0', false ],
|
||
|
[ '1', null, '0', null, null, '0', false ],
|
||
|
[ '1', null, '10', null, null, '10', false ],
|
||
|
[ '1', null, '2', null, null, '2', false ],
|
||
|
[ '1', null, '1', null, null, '1', false ],
|
||
|
// Max values testing.
|
||
|
[ '1', '1', null, 'foo', null, '0', false ],
|
||
|
[ '1', null, null, '10', null, '0', false ],
|
||
|
[ '1', null, null, '0', null, '0', false ],
|
||
|
[ '1', null, null, '-10', null, '0', false ],
|
||
|
[ '1', null, null, '1', null, '0', false ],
|
||
|
[ '5', null, null, '3', '3', '0', false ],
|
||
|
[ '5', '2', '-6', '3', '2', '-2', false ],
|
||
|
[ '-3', '5', '-10', '-3', null, '-10', false ],
|
||
|
// Step mismatch.
|
||
|
[ '1', '2', '-2', null, null, '0', false ],
|
||
|
[ '3', '2', '-2', null, null, '2', false ],
|
||
|
[ '3', '2', '-2', null, '2', '0', false ],
|
||
|
[ '3', '2', '-2', null, '-2', '8', false ],
|
||
|
[ '1', '2', '-6', null, null, '0', false ],
|
||
|
[ '1', '2', '-2', null, null, '0', false ],
|
||
|
[ '1', '3', '-6', null, null, '-3', false ],
|
||
|
[ '2', '3', '-6', null, null, '0', false ],
|
||
|
[ '2', '3', '1', null, null, '1', false ],
|
||
|
[ '5', '3', '1', null, null, '1', false ],
|
||
|
[ '3', '2', '-6', null, null, '2', false ],
|
||
|
[ '5', '2', '-6', null, null, '4', false ],
|
||
|
[ '6', '2', '1', null, null, '5', false ],
|
||
|
[ '8', '3', '1', null, null, '4', false ],
|
||
|
[ '9', '2', '-10', null, null, '8', false ],
|
||
|
[ '7', '3', '-10', null, null, '5', false ],
|
||
|
[ '-2', '3', '-10', null, null, '-4', false ],
|
||
|
// Clamping.
|
||
|
[ '0', '2', '-1', null, null, '-1', false ],
|
||
|
[ '10', '2', '0', '4', '10', '0', false ],
|
||
|
[ '10', '2', '0', '4', '5', '0', false ],
|
||
|
// value = "" (default will be 50).
|
||
|
[ '', null, null, null, null, '49', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '0', 'any', null, null, 1, null, true ],
|
||
|
[ '0', 'ANY', null, null, 1, null, true ],
|
||
|
[ '0', 'AnY', null, null, 1, null, true ],
|
||
|
[ '0', 'aNy', null, null, 1, null, true ],
|
||
|
// With @value = step base.
|
||
|
[ '1', '2', null, null, null, '1', false ],
|
||
|
]},
|
||
|
{ type: 'date', data: [
|
||
|
// Regular case.
|
||
|
[ '2012-07-09', null, null, null, null, '2012-07-08', false ],
|
||
|
// Argument testing.
|
||
|
[ '2012-07-09', null, null, null, 1, '2012-07-08', false ],
|
||
|
[ '2012-07-09', null, null, null, 5, '2012-07-04', false ],
|
||
|
[ '2012-07-09', null, null, null, -1, '2012-07-10', false ],
|
||
|
[ '2012-07-09', null, null, null, 0, '2012-07-09', false ],
|
||
|
// Month/Year wrapping.
|
||
|
[ '2012-08-01', null, null, null, 1, '2012-07-31', false ],
|
||
|
[ '1969-01-02', null, null, null, 4, '1968-12-29', false ],
|
||
|
[ '1969-01-01', null, null, null, -365, '1970-01-01', false ],
|
||
|
[ '2012-02-29', null, null, null, -1, '2012-03-01', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '2012-01-02', null, null, null, 1.1, '2012-01-01', false ],
|
||
|
[ '2012-01-02', null, null, null, 1.9, '2012-01-01', false ],
|
||
|
// With step values.
|
||
|
[ '2012-01-03', '0.5', null, null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-02', '0.5', null, null, null, '2012-01-01', false ],
|
||
|
[ '2012-01-01', '2', null, null, null, '2011-12-30', false ],
|
||
|
[ '2012-01-02', '0.25',null, null, 4, '2012-01-01', false ],
|
||
|
[ '2012-01-15', '1.1', '2012-01-01', null, 1, '2012-01-12', false ],
|
||
|
[ '2012-01-12', '1.1', '2012-01-01', null, 2, '2012-01-01', false ],
|
||
|
[ '2012-01-23', '1.1', '2012-01-01', null, 10, '2012-01-12', false ],
|
||
|
[ '2012-01-23', '1.1', '2012-01-01', null, 11, '2012-01-01', false ],
|
||
|
[ '1968-01-12', '1.1', '1968-01-01', null, 8, '1968-01-01', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '2012-01-02', '0', null, null, null, '2012-01-01', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '2012-01-02', '-1', null, null, null, '2012-01-01', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '2012-01-02', 'foo', null, null, null, '2012-01-01', false ],
|
||
|
// Min values testing.
|
||
|
[ '2012-01-03', '1', 'foo', null, 2, '2012-01-01', false ],
|
||
|
[ '2012-01-02', '1', '2012-01-01', null, null, '2012-01-01', false ],
|
||
|
[ '2012-01-01', '1', '2012-01-01', null, null, '2012-01-01', false ],
|
||
|
[ '2012-01-01', '1', '2012-01-10', null, 1, '2012-01-01', false ],
|
||
|
[ '2012-01-05', '3', '2012-01-01', null, null, '2012-01-04', false ],
|
||
|
[ '1969-01-01', '5', '1969-01-01', '1969-01-02', null, '1969-01-01', false ],
|
||
|
// Max values testing.
|
||
|
[ '2012-01-02', '1', null, 'foo', null, '2012-01-01', false ],
|
||
|
[ '2012-01-02', null, null, '2012-01-05', null, '2012-01-01', false ],
|
||
|
[ '2012-01-03', null, null, '2012-01-03', null, '2012-01-02', false ],
|
||
|
[ '2012-01-07', null, null, '2012-01-04', 4, '2012-01-03', false ],
|
||
|
[ '2012-01-07', '2', null, '2012-01-04', 3, '2012-01-01', false ],
|
||
|
// Step mismatch.
|
||
|
[ '2012-01-04', '2', '2012-01-01', null, null, '2012-01-03', false ],
|
||
|
[ '2012-01-06', '2', '2012-01-01', null, 2, '2012-01-03', false ],
|
||
|
[ '2012-01-05', '2', '2012-01-04', '2012-01-08', null, '2012-01-04', false ],
|
||
|
[ '1970-01-04', '2', null, null, null, '1970-01-02', false ],
|
||
|
[ '1970-01-09', '3', null, null, null, '1970-01-06', false ],
|
||
|
// Clamping.
|
||
|
[ '2012-05-01', null, null, '2012-01-05', null, '2012-01-05', false ],
|
||
|
[ '1970-01-05', '2', '1970-01-02', '1970-01-05', null, '1970-01-04', false ],
|
||
|
[ '1970-01-01', '5', '1970-01-02', '1970-01-09', 10, '1970-01-01', false ],
|
||
|
[ '1970-01-07', '5', '1969-12-27', '1970-01-06', 2, '1970-01-01', false ],
|
||
|
[ '1970-03-08', '3', '1970-02-01', '1970-02-07', 15, '1970-02-01', false ],
|
||
|
[ '1970-01-10', '3', '1970-01-01', '1970-01-06', 2, '1970-01-04', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '1969-12-31', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '2012-01-01', 'any', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'ANY', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'AnY', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'aNy', null, null, 1, null, true ],
|
||
|
]},
|
||
|
{ type: 'time', data: [
|
||
|
// Regular case.
|
||
|
[ '16:39', null, null, null, null, '16:38', false ],
|
||
|
// Argument testing.
|
||
|
[ '16:40', null, null, null, 1, '16:39', false ],
|
||
|
[ '16:40', null, null, null, 5, '16:35', false ],
|
||
|
[ '16:40', null, null, null, -1, '16:41', false ],
|
||
|
[ '16:40', null, null, null, 0, '16:40', false ],
|
||
|
// hour/minutes/seconds wrapping.
|
||
|
[ '05:00', null, null, null, null, '04:59', false ],
|
||
|
[ '05:00:00', 1, null, null, null, '04:59:59', false ],
|
||
|
[ '05:00:00', 0.1, null, null, null, '04:59:59.900', false ],
|
||
|
[ '05:00:00', 0.01, null, null, null, '04:59:59.990', false ],
|
||
|
[ '05:00:00', 0.001, null, null, null, '04:59:59.999', false ],
|
||
|
// stepDown() on '00:00' gives '23:59'.
|
||
|
[ '00:00', null, null, null, 1, '23:59', false ],
|
||
|
[ '00:00', null, null, null, 3, '23:57', false ],
|
||
|
// Some random step values..
|
||
|
[ '16:56', '0.5', null, null, null, '16:55:59.500', false ],
|
||
|
[ '16:56', '2', null, null, null, '16:55:58', false ],
|
||
|
[ '16:56', '0.25',null, null, 4, '16:55:59', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 1, '16:56:59.900', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 2, '16:56:58.800', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 10, '16:56:50', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 11, '16:56:48.900', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 8, '16:56:52.200', false ],
|
||
|
// Invalid @step, means that we use the default value.
|
||
|
[ '17:01', '0', null, null, null, '17:00', false ],
|
||
|
[ '17:01', '-1', null, null, null, '17:00', false ],
|
||
|
[ '17:01', 'foo', null, null, null, '17:00', false ],
|
||
|
// Min values testing.
|
||
|
[ '17:02', '60', 'foo', null, 2, '17:00', false ],
|
||
|
[ '17:10', '60', '17:09', null, null, '17:09', false ],
|
||
|
[ '17:10', '60', '17:10', null, null, '17:10', false ],
|
||
|
[ '17:10', '60', '17:30', null, 1, '17:10', false ],
|
||
|
[ '17:10', '180', '17:05', null, null, '17:08', false ],
|
||
|
[ '17:10', '300', '17:10', '17:11', null, '17:10', false ],
|
||
|
// Max values testing.
|
||
|
[ '17:15', '60', null, 'foo', null, '17:14', false ],
|
||
|
[ '17:15', null, null, '17:20', null, '17:14', false ],
|
||
|
[ '17:15', null, null, '17:15', null, '17:14', false ],
|
||
|
[ '17:15', null, null, '17:13', 4, '17:11', false ],
|
||
|
[ '17:15', '120', null, '17:13', 3, '17:09', false ],
|
||
|
// Step mismatch.
|
||
|
[ '17:19', '120', '17:10', null, null, '17:18', false ],
|
||
|
[ '17:19', '120', '17:10', null, 2, '17:16', false ],
|
||
|
[ '17:19', '120', '17:18', '17:25', null, '17:18', false ],
|
||
|
[ '17:19', '120', null, null, null, '17:17', false ],
|
||
|
[ '17:19', '180', null, null, null, '17:16', false ],
|
||
|
// Clamping.
|
||
|
[ '17:22', null, null, '17:11', null, '17:11', false ],
|
||
|
[ '17:22', '120', '17:20', '17:22', null, '17:20', false ],
|
||
|
[ '17:22', '300', '17:12', '17:20', 10, '17:12', false ],
|
||
|
[ '17:22', '300', '17:18', '17:20', 2, '17:18', false ],
|
||
|
[ '17:22', '180', '17:00', '17:20', 15, '17:00', false ],
|
||
|
[ '17:22', '180', '17:10', '17:20', 2, '17:16', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '23:59', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '17:26', 'any', null, null, 1, null, true ],
|
||
|
[ '17:26', 'ANY', null, null, 1, null, true ],
|
||
|
[ '17:26', 'AnY', null, null, 1, null, true ],
|
||
|
[ '17:26', 'aNy', null, null, 1, null, true ],
|
||
|
]},
|
||
|
];
|
||
|
|
||
|
for (var test of testData) {
|
||
|
for (var data of test.data) {
|
||
|
var element = document.createElement("input");
|
||
|
element.type = test.type;
|
||
|
|
||
|
if (data[1] != null) {
|
||
|
element.step = data[1];
|
||
|
}
|
||
|
|
||
|
if (data[2] != null) {
|
||
|
element.min = data[2];
|
||
|
}
|
||
|
|
||
|
if (data[3] != null) {
|
||
|
element.max = data[3];
|
||
|
}
|
||
|
|
||
|
// Set 'value' last for type=range, because the final sanitized value
|
||
|
// after setting 'step', 'min' and 'max' can be affected by the order in
|
||
|
// which those attributes are set. Setting 'value' last makes it simpler
|
||
|
// to reason about what the final value should be.
|
||
|
if (data[0] != null) {
|
||
|
element.setAttribute('value', data[0]);
|
||
|
}
|
||
|
|
||
|
var exceptionCaught = false;
|
||
|
try {
|
||
|
if (data[4] != null) {
|
||
|
element.stepDown(data[4]);
|
||
|
} else {
|
||
|
element.stepDown();
|
||
|
}
|
||
|
|
||
|
is(element.value, data[5], "The value for type=" + test.type + " should be " + data[5]);
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
is(element.value, data[0], e.name + "The value should not have changed");
|
||
|
is(e.name, 'InvalidStateError',
|
||
|
"It should be a InvalidStateError exception.");
|
||
|
} finally {
|
||
|
is(exceptionCaught, data[6], "exception status should be " + data[6]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function checkStepUp()
|
||
|
{
|
||
|
// This testData is very similar to the one in checkStepDown with some changes
|
||
|
// relative to stepUp.
|
||
|
var testData = [
|
||
|
/* Initial value | step | min | max | stepUp arg | final value | exception */
|
||
|
{ type: 'number', data: [
|
||
|
// Regular case.
|
||
|
[ '1', null, null, null, null, '2', false ],
|
||
|
// Argument testing.
|
||
|
[ '1', null, null, null, 1, '2', false ],
|
||
|
[ '9', null, null, null, 9, '18', false ],
|
||
|
[ '1', null, null, null, -1, '0', false ],
|
||
|
[ '1', null, null, null, 0, '1', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '1', null, null, null, 1.1, '2', false ],
|
||
|
// With step values.
|
||
|
[ '1', '0.5', null, null, null, '1.5', false ],
|
||
|
[ '1', '0.25', null, null, 4, '2', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '0', null, null, null, '2', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '-1', null, null, null, '2', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '1', 'foo', null, null, null, '2', false ],
|
||
|
// Min values testing.
|
||
|
[ '1', '1', 'foo', null, null, '2', false ],
|
||
|
[ '1', null, '-10', null, null, '2', false ],
|
||
|
[ '1', null, '0', null, null, '2', false ],
|
||
|
[ '1', null, '10', null, null, '10', false ],
|
||
|
[ '1', null, '2', null, null, '2', false ],
|
||
|
[ '1', null, '1', null, null, '2', false ],
|
||
|
[ '0', null, '4', null, '5', '5', false ],
|
||
|
[ '0', '2', '5', null, '3', '5', false ],
|
||
|
// Max values testing.
|
||
|
[ '1', '1', null, 'foo', null, '2', false ],
|
||
|
[ '1', null, null, '10', null, '2', false ],
|
||
|
[ '1', null, null, '0', null, '1', false ],
|
||
|
[ '1', null, null, '-10', null, '1', false ],
|
||
|
[ '1', null, null, '1', null, '1', false ],
|
||
|
[ '-3', '5', '-10', '-3', null, '-3', false ],
|
||
|
// Step mismatch.
|
||
|
[ '1', '2', '0', null, null, '2', false ],
|
||
|
[ '1', '2', '0', null, '2', '4', false ],
|
||
|
[ '8', '2', null, '9', null, '8', false ],
|
||
|
[ '-3', '2', '-6', null, null, '-2', false ],
|
||
|
[ '9', '3', '-10', null, null, '11', false ],
|
||
|
[ '7', '3', '-10', null, null, '8', false ],
|
||
|
[ '7', '3', '5', null, null, '8', false ],
|
||
|
[ '9', '4', '3', null, null, '11', false ],
|
||
|
[ '-2', '3', '-6', null, null, '0', false ],
|
||
|
[ '7', '3', '6', null, null, '9', false ],
|
||
|
// Clamping.
|
||
|
[ '1', '2', '0', '3', null, '2', false ],
|
||
|
[ '0', '5', '1', '8', '10', '6', false ],
|
||
|
[ '-9', '3', '-8', '-1', '5', '-2', false ],
|
||
|
[ '-9', '3', '8', '15', '15', '14', false ],
|
||
|
[ '-1', '3', '-1', '4', '3', '2', false ],
|
||
|
[ '-3', '2', '-6', '-2', null, '-2', false ],
|
||
|
[ '-3', '2', '-6', '-1', null, '-2', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '1', false ],
|
||
|
[ '', null, null, null, null, '1', false ],
|
||
|
[ '', '2', null, null, null, '2', false ],
|
||
|
[ '', '2', '3', null, null, '3', false ],
|
||
|
[ '', null, '3', null, null, '3', false ],
|
||
|
[ '', '2', '3', '8', null, '3', false ],
|
||
|
[ '', null, '-10', '10', null, '1', false ],
|
||
|
[ '', '3', '-10', '10', null, '2', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '0', 'any', null, null, 1, null, true ],
|
||
|
[ '0', 'ANY', null, null, 1, null, true ],
|
||
|
[ '0', 'AnY', null, null, 1, null, true ],
|
||
|
[ '0', 'aNy', null, null, 1, null, true ],
|
||
|
// With @value = step base.
|
||
|
[ '1', '2', null, null, null, '3', false ],
|
||
|
]},
|
||
|
{ type: 'range', data: [
|
||
|
// Regular case.
|
||
|
[ '1', null, null, null, null, '2', false ],
|
||
|
// Argument testing.
|
||
|
[ '1', null, null, null, 1, '2', false ],
|
||
|
[ '9', null, null, null, 9, '18', false ],
|
||
|
[ '1', null, null, null, -1, '0', false ],
|
||
|
[ '1', null, null, null, 0, '1', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '1', null, null, null, 1.1, '2', false ],
|
||
|
// With step values.
|
||
|
[ '1', '0.5', null, null, null, '1.5', false ],
|
||
|
[ '1', '0.25', null, null, 4, '2', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '0', null, null, null, '2', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '1', '-1', null, null, null, '2', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '1', 'foo', null, null, null, '2', false ],
|
||
|
// Min values testing.
|
||
|
[ '1', '1', 'foo', null, null, '2', false ],
|
||
|
[ '1', null, '-10', null, null, '2', false ],
|
||
|
[ '1', null, '0', null, null, '2', false ],
|
||
|
[ '1', null, '10', null, null, '11', false ],
|
||
|
[ '1', null, '2', null, null, '3', false ],
|
||
|
[ '1', null, '1', null, null, '2', false ],
|
||
|
[ '0', null, '4', null, '5', '9', false ],
|
||
|
[ '0', '2', '5', null, '3', '11', false ],
|
||
|
// Max values testing.
|
||
|
[ '1', '1', null, 'foo', null, '2', false ],
|
||
|
[ '1', null, null, '10', null, '2', false ],
|
||
|
[ '1', null, null, '0', null, '0', false ],
|
||
|
[ '1', null, null, '-10', null, '0', false ],
|
||
|
[ '1', null, null, '1', null, '1', false ],
|
||
|
[ '-3', '5', '-10', '-3', null, '-5', false ],
|
||
|
// Step mismatch.
|
||
|
[ '1', '2', '0', null, null, '4', false ],
|
||
|
[ '1', '2', '0', null, '2', '6', false ],
|
||
|
[ '8', '2', null, '9', null, '8', false ],
|
||
|
[ '-3', '2', '-6', null, null, '0', false ],
|
||
|
[ '9', '3', '-10', null, null, '11', false ],
|
||
|
[ '7', '3', '-10', null, null, '11', false ],
|
||
|
[ '7', '3', '5', null, null, '11', false ],
|
||
|
[ '9', '4', '3', null, null, '15', false ],
|
||
|
[ '-2', '3', '-6', null, null, '0', false ],
|
||
|
[ '7', '3', '6', null, null, '9', false ],
|
||
|
// Clamping.
|
||
|
[ '1', '2', '0', '3', null, '2', false ],
|
||
|
[ '0', '5', '1', '8', '10', '6', false ],
|
||
|
[ '-9', '3', '-8', '-1', '5', '-2', false ],
|
||
|
[ '-9', '3', '8', '15', '15', '14', false ],
|
||
|
[ '-1', '3', '-1', '4', '3', '2', false ],
|
||
|
[ '-3', '2', '-6', '-2', null, '-2', false ],
|
||
|
[ '-3', '2', '-6', '-1', null, '-2', false ],
|
||
|
// value = "" (default will be 50).
|
||
|
[ '', null, null, null, null, '51', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '0', 'any', null, null, 1, null, true ],
|
||
|
[ '0', 'ANY', null, null, 1, null, true ],
|
||
|
[ '0', 'AnY', null, null, 1, null, true ],
|
||
|
[ '0', 'aNy', null, null, 1, null, true ],
|
||
|
// With @value = step base.
|
||
|
[ '1', '2', null, null, null, '3', false ],
|
||
|
]},
|
||
|
{ type: 'date', data: [
|
||
|
// Regular case.
|
||
|
[ '2012-07-09', null, null, null, null, '2012-07-10', false ],
|
||
|
// Argument testing.
|
||
|
[ '2012-07-09', null, null, null, 1, '2012-07-10', false ],
|
||
|
[ '2012-07-09', null, null, null, 9, '2012-07-18', false ],
|
||
|
[ '2012-07-09', null, null, null, -1, '2012-07-08', false ],
|
||
|
[ '2012-07-09', null, null, null, 0, '2012-07-09', false ],
|
||
|
// Month/Year wrapping.
|
||
|
[ '2012-07-31', null, null, null, 1, '2012-08-01', false ],
|
||
|
[ '1968-12-29', null, null, null, 4, '1969-01-02', false ],
|
||
|
[ '1970-01-01', null, null, null, -365, '1969-01-01', false ],
|
||
|
[ '2012-03-01', null, null, null, -1, '2012-02-29', false ],
|
||
|
// Float values are rounded to integer (1.1 -> 1).
|
||
|
[ '2012-01-01', null, null, null, 1.1, '2012-01-02', false ],
|
||
|
[ '2012-01-01', null, null, null, 1.9, '2012-01-02', false ],
|
||
|
// With step values.
|
||
|
[ '2012-01-01', '0.5', null, null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', '0.5', null, null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', '2', null, null, null, '2012-01-03', false ],
|
||
|
[ '2012-01-01', '0.25', null, null, 4, '2012-01-02', false ],
|
||
|
[ '2012-01-01', '1.1', '2012-01-01', null, 1, '2012-01-12', false ],
|
||
|
[ '2012-01-01', '1.1', '2012-01-01', null, 2, '2012-01-12', false ],
|
||
|
[ '2012-01-01', '1.1', '2012-01-01', null, 10, '2012-01-12', false ],
|
||
|
[ '2012-01-01', '1.1', '2012-01-01', null, 11, '2012-01-23', false ],
|
||
|
[ '1968-01-01', '1.1', '1968-01-01', null, 8, '1968-01-12', false ],
|
||
|
// step = 0 isn't allowed (-> step = 1).
|
||
|
[ '2012-01-01', '0', null, null, null, '2012-01-02', false ],
|
||
|
// step < 0 isn't allowed (-> step = 1).
|
||
|
[ '2012-01-01', '-1', null, null, null, '2012-01-02', false ],
|
||
|
// step = NaN isn't allowed (-> step = 1).
|
||
|
[ '2012-01-01', 'foo', null, null, null, '2012-01-02', false ],
|
||
|
// Min values testing.
|
||
|
[ '2012-01-01', '1', 'foo', null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', null, '2011-12-01', null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', null, '2012-01-02', null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', null, '2012-01-01', null, null, '2012-01-02', false ],
|
||
|
[ '2012-01-01', null, '2012-01-04', null, 4, '2012-01-05', false ],
|
||
|
[ '2012-01-01', '2', '2012-01-04', null, 3, '2012-01-06', false ],
|
||
|
// Max values testing.
|
||
|
[ '2012-01-01', '1', null, 'foo', 2, '2012-01-03', false ],
|
||
|
[ '2012-01-01', '1', null, '2012-01-10', 1, '2012-01-02', false ],
|
||
|
[ '2012-01-02', null, null, '2012-01-01', null, '2012-01-02', false ],
|
||
|
[ '2012-01-02', null, null, '2012-01-02', null, '2012-01-02', false ],
|
||
|
[ '2012-01-02', null, null, '2012-01-02', null, '2012-01-02', false ],
|
||
|
[ '1969-01-02', '5', '1969-01-01', '1969-01-02', null, '1969-01-02', false ],
|
||
|
// Step mismatch.
|
||
|
[ '2012-01-02', '2', '2012-01-01', null, null, '2012-01-03', false ],
|
||
|
[ '2012-01-02', '2', '2012-01-01', null, 2, '2012-01-05', false ],
|
||
|
[ '2012-01-05', '2', '2012-01-01', '2012-01-06', null, '2012-01-05', false ],
|
||
|
[ '1970-01-02', '2', null, null, null, '1970-01-04', false ],
|
||
|
[ '1970-01-05', '3', null, null, null, '1970-01-08', false ],
|
||
|
[ '1970-01-03', '3', null, null, null, '1970-01-06', false ],
|
||
|
[ '1970-01-03', '3', '1970-01-02', null, null, '1970-01-05', false ],
|
||
|
// Clamping.
|
||
|
[ '2012-01-01', null, '2012-01-31', null, null, '2012-01-31', false ],
|
||
|
[ '1970-01-02', '2', '1970-01-01', '1970-01-04', null, '1970-01-03', false ],
|
||
|
[ '1970-01-01', '5', '1970-01-02', '1970-01-09', 10, '1970-01-07', false ],
|
||
|
[ '1969-12-28', '5', '1969-12-29', '1970-01-06', 3, '1970-01-03', false ],
|
||
|
[ '1970-01-01', '3', '1970-02-01', '1970-02-07', 15, '1970-02-07', false ],
|
||
|
[ '1970-01-01', '3', '1970-01-01', '1970-01-06', 2, '1970-01-04', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '1970-01-02', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '2012-01-01', 'any', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'ANY', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'AnY', null, null, 1, null, true ],
|
||
|
[ '2012-01-01', 'aNy', null, null, 1, null, true ],
|
||
|
]},
|
||
|
{ type: 'time', data: [
|
||
|
// Regular case.
|
||
|
[ '16:39', null, null, null, null, '16:40', false ],
|
||
|
// Argument testing.
|
||
|
[ '16:40', null, null, null, 1, '16:41', false ],
|
||
|
[ '16:40', null, null, null, 5, '16:45', false ],
|
||
|
[ '16:40', null, null, null, -1, '16:39', false ],
|
||
|
[ '16:40', null, null, null, 0, '16:40', false ],
|
||
|
// hour/minutes/seconds wrapping.
|
||
|
[ '04:59', null, null, null, null, '05:00', false ],
|
||
|
[ '04:59:59', 1, null, null, null, '05:00', false ],
|
||
|
[ '04:59:59.900', 0.1, null, null, null, '05:00', false ],
|
||
|
[ '04:59:59.990', 0.01, null, null, null, '05:00', false ],
|
||
|
[ '04:59:59.999', 0.001, null, null, null, '05:00', false ],
|
||
|
// stepUp() on '23:59' gives '00:00'.
|
||
|
[ '23:59', null, null, null, 1, '00:00', false ],
|
||
|
[ '23:59', null, null, null, 3, '00:02', false ],
|
||
|
// Some random step values..
|
||
|
[ '16:56', '0.5', null, null, null, '16:56:00.500', false ],
|
||
|
[ '16:56', '2', null, null, null, '16:56:02', false ],
|
||
|
[ '16:56', '0.25',null, null, 4, '16:56:01', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 1, '16:57:01', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 2, '16:57:02.100', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 10, '16:57:10.900', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 11, '16:57:12', false ],
|
||
|
[ '16:57', '1.1', '16:00', null, 8, '16:57:08.700', false ],
|
||
|
// Invalid @step, means that we use the default value.
|
||
|
[ '17:01', '0', null, null, null, '17:02', false ],
|
||
|
[ '17:01', '-1', null, null, null, '17:02', false ],
|
||
|
[ '17:01', 'foo', null, null, null, '17:02', false ],
|
||
|
// Min values testing.
|
||
|
[ '17:02', '60', 'foo', null, 2, '17:04', false ],
|
||
|
[ '17:10', '60', '17:09', null, null, '17:11', false ],
|
||
|
[ '17:10', '60', '17:10', null, null, '17:11', false ],
|
||
|
[ '17:10', '60', '17:30', null, 1, '17:30', false ],
|
||
|
[ '17:10', '180', '17:05', null, null, '17:11', false ],
|
||
|
[ '17:10', '300', '17:10', '17:11', null,'17:10', false ],
|
||
|
// Max values testing.
|
||
|
[ '17:15', '60', null, 'foo', null, '17:16', false ],
|
||
|
[ '17:15', null, null, '17:20', null, '17:16', false ],
|
||
|
[ '17:15', null, null, '17:15', null, '17:15', false ],
|
||
|
[ '17:15', null, null, '17:13', 4, '17:15', false ],
|
||
|
[ '17:15', '120', null, '17:13', 3, '17:15', false ],
|
||
|
// Step mismatch.
|
||
|
[ '17:19', '120', '17:10', null, null, '17:20', false ],
|
||
|
[ '17:19', '120', '17:10', null, 2, '17:22', false ],
|
||
|
[ '17:19', '120', '17:18', '17:25', null, '17:20', false ],
|
||
|
[ '17:19', '120', null, null, null, '17:21', false ],
|
||
|
[ '17:19', '180', null, null, null, '17:22', false ],
|
||
|
// Clamping.
|
||
|
[ '17:22', null, null, '17:11', null, '17:22', false ],
|
||
|
[ '17:22', '120', '17:20', '17:22', null, '17:22', false ],
|
||
|
[ '17:22', '300', '17:12', '17:20', 10, '17:22', false ],
|
||
|
[ '17:22', '300', '17:18', '17:20', 2, '17:22', false ],
|
||
|
[ '17:22', '180', '17:00', '17:20', 15, '17:22', false ],
|
||
|
[ '17:22', '180', '17:10', '17:20', 2, '17:22', false ],
|
||
|
// value = "" (NaN).
|
||
|
[ '', null, null, null, null, '00:01', false ],
|
||
|
// With step = 'any'.
|
||
|
[ '17:26', 'any', null, null, 1, null, true ],
|
||
|
[ '17:26', 'ANY', null, null, 1, null, true ],
|
||
|
[ '17:26', 'AnY', null, null, 1, null, true ],
|
||
|
[ '17:26', 'aNy', null, null, 1, null, true ],
|
||
|
]},
|
||
|
];
|
||
|
|
||
|
for (var test of testData) {
|
||
|
for (var data of test.data) {
|
||
|
var element = document.createElement("input");
|
||
|
element.type = test.type;
|
||
|
|
||
|
if (data[1] != null) {
|
||
|
element.step = data[1];
|
||
|
}
|
||
|
|
||
|
if (data[2] != null) {
|
||
|
element.min = data[2];
|
||
|
}
|
||
|
|
||
|
if (data[3] != null) {
|
||
|
element.max = data[3];
|
||
|
}
|
||
|
|
||
|
// Set 'value' last for type=range, because the final sanitized value
|
||
|
// after setting 'step', 'min' and 'max' can be affected by the order in
|
||
|
// which those attributes are set. Setting 'value' last makes it simpler
|
||
|
// to reason about what the final value should be.
|
||
|
if (data[0] != null) {
|
||
|
element.setAttribute('value', data[0]);
|
||
|
}
|
||
|
|
||
|
var exceptionCaught = false;
|
||
|
try {
|
||
|
if (data[4] != null) {
|
||
|
element.stepUp(data[4]);
|
||
|
} else {
|
||
|
element.stepUp();
|
||
|
}
|
||
|
|
||
|
is(element.value, data[5], "The value for type=" + test.type + " should be " + data[5]);
|
||
|
} catch (e) {
|
||
|
exceptionCaught = true;
|
||
|
is(element.value, data[0], e.name + "The value should not have changed");
|
||
|
is(e.name, 'InvalidStateError',
|
||
|
"It should be a InvalidStateError exception.");
|
||
|
} finally {
|
||
|
is(exceptionCaught, data[6], "exception status should be " + data[6]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
checkPresence();
|
||
|
checkAvailability();
|
||
|
|
||
|
checkStepDown();
|
||
|
checkStepUp();
|
||
|
|
||
|
</script>
|
||
|
</pre>
|
||
|
</body>
|
||
|
</html>
|