2010-09-14 00:23:03 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=590363
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 590363</title>
|
|
|
|
<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=590363">Mozilla Bug 590363</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 590363 **/
|
|
|
|
|
|
|
|
var testData = [
|
|
|
|
/* type to test | is the value reset when changing to file then reverting */
|
2011-06-29 10:51:57 +00:00
|
|
|
[ "button", false ],
|
2010-09-14 00:23:03 +00:00
|
|
|
[ "checkbox", false ],
|
2011-06-29 10:51:57 +00:00
|
|
|
[ "hidden", false ],
|
|
|
|
[ "reset", false ],
|
|
|
|
[ "image", false ],
|
|
|
|
[ "radio", false ],
|
|
|
|
[ "submit", false ],
|
|
|
|
[ "tel", true ],
|
|
|
|
[ "text", true ],
|
|
|
|
[ "url", true ],
|
|
|
|
[ "email", true ],
|
|
|
|
[ "search", true ],
|
2010-09-14 00:23:03 +00:00
|
|
|
[ "password", true ],
|
2011-06-29 10:51:57 +00:00
|
|
|
[ "number", true ],
|
2012-12-27 16:06:53 +00:00
|
|
|
[ "date", true ],
|
2013-01-08 17:10:00 +00:00
|
|
|
[ "time", true ],
|
2013-02-16 12:36:02 +00:00
|
|
|
[ "range", true ],
|
2013-05-23 13:02:23 +00:00
|
|
|
[ "color", true ],
|
2011-06-29 10:51:57 +00:00
|
|
|
// 'file' is treated separatly.
|
|
|
|
];
|
|
|
|
|
|
|
|
var todoTypes = [
|
2013-05-23 13:02:23 +00:00
|
|
|
"datetime", "month", "week", "datetime-local"
|
2010-09-14 00:23:03 +00:00
|
|
|
];
|
|
|
|
|
2013-05-23 13:02:23 +00:00
|
|
|
var nonTrivialSanitizing = [ 'number', 'date', 'time', 'color' ];
|
2013-01-11 15:00:52 +00:00
|
|
|
|
2010-09-14 00:23:03 +00:00
|
|
|
var length = testData.length;
|
|
|
|
for (var i=0; i<length; ++i) {
|
|
|
|
for (var j=0; j<length; ++j) {
|
|
|
|
var e = document.createElement('input');
|
|
|
|
e.type = testData[i][0];
|
2011-06-29 10:51:57 +00:00
|
|
|
|
|
|
|
var expectedValue;
|
2013-02-16 12:36:02 +00:00
|
|
|
|
|
|
|
// range will sanitize its value to 50 (the default) if it isn't a valid
|
|
|
|
// number. We need to handle that specially.
|
|
|
|
if (testData[j][0] == 'range' || testData[i][0] == 'range') {
|
|
|
|
if (testData[j][0] == 'date' || testData[j][0] == 'time') {
|
|
|
|
expectedValue = '';
|
2013-05-23 13:02:23 +00:00
|
|
|
} else if (testData[j][0] == 'color') {
|
|
|
|
expectedValue = '#000000';
|
2013-02-16 12:36:02 +00:00
|
|
|
} else {
|
|
|
|
expectedValue = '50';
|
|
|
|
}
|
2013-05-23 13:02:23 +00:00
|
|
|
} else if (testData[i][0] == 'color' || testData[j][0] == 'color') {
|
|
|
|
if (testData[j][0] == 'number' || testData[j][0] == 'date' ||
|
|
|
|
testData[j][0] == 'time') {
|
|
|
|
expectedValue = ''
|
|
|
|
} else {
|
|
|
|
expectedValue = '#000000';
|
|
|
|
}
|
2013-02-16 12:36:02 +00:00
|
|
|
} else if (nonTrivialSanitizing.indexOf(testData[i][0]) != -1 &&
|
|
|
|
nonTrivialSanitizing.indexOf(testData[j][0]) != -1) {
|
2012-12-27 18:48:13 +00:00
|
|
|
expectedValue = '';
|
|
|
|
} else if (testData[i][0] == 'number' || testData[j][0] == 'number') {
|
2011-06-29 10:51:57 +00:00
|
|
|
expectedValue = '42';
|
2012-12-27 18:48:13 +00:00
|
|
|
} else if (testData[i][0] == 'date' || testData[j][0] == 'date') {
|
|
|
|
expectedValue = '2012-12-21';
|
2013-01-11 15:00:52 +00:00
|
|
|
} else if (testData[i][0] == 'time' || testData[j][0] == 'time') {
|
|
|
|
expectedValue = '21:21';
|
2011-06-29 10:51:57 +00:00
|
|
|
} else {
|
|
|
|
expectedValue = "foo";
|
|
|
|
}
|
|
|
|
e.value = expectedValue;
|
|
|
|
|
2010-09-14 00:23:03 +00:00
|
|
|
e.type = testData[j][0];
|
2011-06-29 10:51:57 +00:00
|
|
|
is(e.value, expectedValue, ".value should still return the same value after " +
|
2010-09-14 00:23:03 +00:00
|
|
|
"changing type from " + testData[i][0] + " to " + testData[j][0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For type='file' .value doesn't behave the same way.
|
|
|
|
// We are just going to check that we do not loose the value.
|
2012-12-21 11:47:52 +00:00
|
|
|
for (var data of testData) {
|
2010-09-14 00:23:03 +00:00
|
|
|
var e = document.createElement('input');
|
|
|
|
e.type = data[0];
|
|
|
|
e.value = 'foo';
|
|
|
|
e.type = 'file';
|
|
|
|
e.type = data[0];
|
|
|
|
|
2013-02-16 12:36:02 +00:00
|
|
|
if (data[0] == 'range') {
|
|
|
|
is(e.value, '50', ".value should still return the same value after " +
|
|
|
|
"changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
|
2013-05-23 13:02:23 +00:00
|
|
|
} else if (data[0] == 'color') {
|
|
|
|
is(e.value, '#000000', ".value should have been reset to the default color after " +
|
|
|
|
"changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
|
2013-02-16 12:36:02 +00:00
|
|
|
} else if (data[1]) {
|
2010-09-14 00:23:03 +00:00
|
|
|
is(e.value, '', ".value should have been reset to the empty string after " +
|
|
|
|
"changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
|
|
|
|
} else {
|
|
|
|
is(e.value, 'foo', ".value should still return the same value after " +
|
|
|
|
"changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-29 10:51:57 +00:00
|
|
|
// TODO checks
|
2012-12-21 11:47:52 +00:00
|
|
|
for (var type of todoTypes) {
|
2011-06-29 10:51:57 +00:00
|
|
|
var e = document.createElement('input');
|
|
|
|
e.type = type;
|
|
|
|
todo_is(e.type, type, type + " type isn't supported yet");
|
|
|
|
}
|
|
|
|
|
2010-09-14 00:23:03 +00:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|