зеркало из https://github.com/mozilla/pjs.git
Bug 386772, use right format for date values, and add datepicker/timepicker tests,r=gavin
This commit is contained in:
Родитель
5b9c01a5d5
Коммит
455ebf4b99
|
@ -52,6 +52,8 @@ _TEST_FILES = test_bug360220.xul \
|
|||
test_popup_coords.xul \
|
||||
test_popup_recreate.xul \
|
||||
test_progressmeter.xul \
|
||||
test_datepicker.xul \
|
||||
test_timepicker.xul \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,309 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<!--
|
||||
XUL Widget Test for datepicker
|
||||
-->
|
||||
<window title="datepicker" width="500" height="600"
|
||||
onload="setTimeout(testtag_datepickers, 0);"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<datepicker id="datepicker"/>
|
||||
<datepicker id="datepicker-popup" type="popup"/>
|
||||
<datepicker id="datepicker-grid" type="grid"/>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function testtag_datepickers()
|
||||
{
|
||||
testtag_datepicker(document.getElementById("datepicker"), "", "datepicker");
|
||||
testtag_datepicker(document.getElementById("datepicker-popup"), "popup", "datepicker popup");
|
||||
testtag_datepicker(document.getElementById("datepicker-grid"), "grid", "datepicker grid");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testtag_datepicker(dp, type, testid)
|
||||
{
|
||||
testid += " ";
|
||||
|
||||
var today = new Date();
|
||||
var tyear = today.getFullYear();
|
||||
var tmonth = today.getMonth();
|
||||
var tdate = today.getDate();
|
||||
|
||||
// testtag_comparedate(dp, testid + "initial", tyear, tmonth, tdate);
|
||||
|
||||
// check that setting the value property works
|
||||
dp.value = testtag_getdatestring(tyear, tmonth, tdate);
|
||||
testtag_comparedate(dp, testid + "set value", tyear, tmonth, tdate);
|
||||
|
||||
// check that setting the dateValue property works
|
||||
dp.dateValue = today;
|
||||
testtag_comparedate(dp, testid + "set dateValue", tyear, tmonth, tdate);
|
||||
ok(dp.value !== today, testid + " set dateValue different date");
|
||||
|
||||
ok(!dp.readOnly, testid + "readOnly");
|
||||
dp.readOnly = true;
|
||||
ok(dp.readOnly, testid + "set readOnly");
|
||||
dp.readOnly = false;
|
||||
ok(!dp.readOnly, testid + "clear readOnly");
|
||||
|
||||
var setDateField = function(field, value, expectException,
|
||||
expectedYear, expectedMonth, expectedDate)
|
||||
{
|
||||
var exh = false;
|
||||
try {
|
||||
dp[field] = value;
|
||||
} catch (ex) { exh = true; }
|
||||
is(exh, expectException, testid + "set " + field + " " + value);
|
||||
testtag_comparedate(dp, testid + "set " + field + " " + value,
|
||||
expectedYear, expectedMonth, expectedDate);
|
||||
}
|
||||
|
||||
// check the value property
|
||||
setDateField("value", "2003-1-27", false, 2003, 0, 27);
|
||||
setDateField("value", "2002-11-8", false, 2002, 10, 8);
|
||||
setDateField("value", "2001-07-02", false, 2001, 6, 2);
|
||||
setDateField("value", "2002-10-25", false, 2002, 9, 25);
|
||||
|
||||
// check that the year, month and date fields can be set properly
|
||||
setDateField("year", 2002, false, 2002, 9, 25);
|
||||
setDateField("year", 0, true, 2002, 9, 25);
|
||||
|
||||
setDateField("month", 6, false, 2002, 6, 25);
|
||||
setDateField("month", 9, false, 2002, 9, 25);
|
||||
setDateField("month", 10, false, 2002, 10, 25);
|
||||
setDateField("month", -1, true, 2002, 10, 25);
|
||||
setDateField("month", 12, true, 2002, 10, 25);
|
||||
|
||||
setDateField("date", 9, false, 2002, 10, 9);
|
||||
setDateField("date", 10, false, 2002, 10, 10);
|
||||
setDateField("date", 15, false, 2002, 10, 15);
|
||||
setDateField("date", 0, true, 2002, 10, 15);
|
||||
setDateField("date", 32, true, 2002, 10, 15);
|
||||
|
||||
// check that dates overflow properly
|
||||
setDateField("value", "2002-2-40", false, 2002, 2, 12);
|
||||
setDateField("value", "2003-03-32", false, 2003, 3, 1);
|
||||
setDateField("value", "2003-12-32", false, 2004, 0, 1);
|
||||
|
||||
// check leap year handling
|
||||
setDateField("value", "1600-2-29", false, 1600, 1, 29);
|
||||
setDateField("value", "2000-2-29", false, 2000, 1, 29);
|
||||
setDateField("value", "2003-2-29", false, 2003, 2, 1);
|
||||
setDateField("value", "2004-2-29", false, 2004, 1, 29);
|
||||
setDateField("value", "2100-2-29", false, 2100, 2, 1);
|
||||
|
||||
// check invalid values for the value and dateValue properties
|
||||
dp.value = "2002-07-15";
|
||||
setDateField("value", "", true, 2002, 6, 15);
|
||||
setDateField("value", "2-2", true, 2002, 6, 15);
|
||||
setDateField("value", "2000-5-6-6", true, 2002, 6, 15);
|
||||
setDateField("value", "2000-a-19", true, 2002, 6, 15);
|
||||
setDateField("dateValue", "none", true, 2002, 6, 15);
|
||||
|
||||
is(dp.open, false, testid + "open false");
|
||||
dp.open = true;
|
||||
if (type == "popup") {
|
||||
ok(dp.open, testid + "open true");
|
||||
dp.open = false;
|
||||
ok(!dp.open, testid + "open false again");
|
||||
}
|
||||
else {
|
||||
ok(!dp.open, testid + "open still false");
|
||||
}
|
||||
|
||||
// check the fields
|
||||
if (type != "grid") {
|
||||
ok(dp.yearField instanceof HTMLInputElement, testid + "yearField");
|
||||
ok(dp.monthField instanceof HTMLInputElement, testid + "monthField");
|
||||
ok(dp.dateField instanceof HTMLInputElement, testid + "dateField");
|
||||
|
||||
testtag_datepicker_UI_fields(dp, testid);
|
||||
|
||||
dp.readOnly = true;
|
||||
|
||||
// check that keyboard usage doesn't change the value when the datepicker
|
||||
// is read only
|
||||
testtag_datepicker_UI_key(dp, testid + "readonly ", "2003-01-29",
|
||||
dp.yearField, 2003, 0, 29, 2003, 0, 29);
|
||||
testtag_datepicker_UI_key(dp, testid + "readonly ", "2003-04-29",
|
||||
dp.monthField, 2003, 3, 29, 2003, 3, 29);
|
||||
testtag_datepicker_UI_key(dp, testid + "readonly ", "2003-06-15",
|
||||
dp.dateField, 2003, 5, 15, 2003, 5, 15);
|
||||
}
|
||||
else {
|
||||
testtag_datepicker_UI_grid(dp, testid);
|
||||
}
|
||||
}
|
||||
|
||||
function testtag_datepicker_UI_fields(dp, testid)
|
||||
{
|
||||
testid += "UI";
|
||||
dp.focus();
|
||||
|
||||
// test adjusting the date with the up and down keys
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-01-29", dp.yearField, 2004, 0, 29, 2003, 0, 29);
|
||||
testtag_datepicker_UI_key(dp, testid, "1600-02-29", dp.yearField, 1601, 1, 28, 1600, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2000-02-29", dp.yearField, 2001, 1, 28, 2000, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2004-02-29", dp.yearField, 2005, 1, 28, 2004, 1, 28);
|
||||
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-04-29", dp.monthField, 2003, 4, 29, 2003, 3, 29);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-01-15", dp.monthField, 2003, 1, 15, 2003, 0, 15);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-12-29", dp.monthField, 2003, 0, 29, 2003, 11, 29);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-03-31", dp.monthField, 2003, 3, 30, 2003, 2, 30);
|
||||
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-06-15", dp.dateField, 2003, 5, 16, 2003, 5, 15);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-06-01", dp.dateField, 2003, 5, 2, 2003, 5, 1);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-06-30", dp.dateField, 2003, 5, 1, 2003, 5, 30);
|
||||
testtag_datepicker_UI_key(dp, testid, "1600-02-28", dp.dateField, 1600, 1, 29, 1600, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2000-02-28", dp.dateField, 2000, 1, 29, 2000, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2003-02-28", dp.dateField, 2003, 1, 1, 2003, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2004-02-28", dp.dateField, 2004, 1, 29, 2004, 1, 28);
|
||||
testtag_datepicker_UI_key(dp, testid, "2100-02-28", dp.dateField, 2100, 1, 1, 2100, 1, 28);
|
||||
}
|
||||
|
||||
function testtag_datepicker_UI_grid(dp, testid)
|
||||
{
|
||||
testid += "UI ";
|
||||
|
||||
// check that pressing the cursor keys moves the date properly
|
||||
dp.focus();
|
||||
dp.value = "2003-02-22";
|
||||
|
||||
synthesizeKeyExpectEvent("VK_LEFT", { }, dp, "change", testid + "key left");
|
||||
is(dp.value, "2003-02-21", testid + "key left");
|
||||
synthesizeKeyExpectEvent("VK_RIGHT", { }, dp, "change", testid + "key right");
|
||||
is(dp.value, "2003-02-22", testid + "key right");
|
||||
synthesizeKeyExpectEvent("VK_RIGHT", { }, dp, "change", testid + "key right next week");
|
||||
is(dp.value, "2003-02-23", testid + "key right next week");
|
||||
synthesizeKeyExpectEvent("VK_LEFT", { }, dp, "change", testid + "key left previous week");
|
||||
is(dp.value, "2003-02-22", testid + "key left previous week");
|
||||
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, dp, "change", testid + "key up");
|
||||
is(dp.value, "2003-02-15", testid + "key up");
|
||||
synthesizeKeyExpectEvent("VK_DOWN", { }, dp, "change", testid + "key down");
|
||||
is(dp.value, "2003-02-22", testid + "key down");
|
||||
synthesizeKeyExpectEvent("VK_DOWN", { }, dp, "change");
|
||||
is(dp.value, "2003-03-01", testid + "key down next month", testid + "key down next month");
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, dp, "change");
|
||||
is(dp.value, "2003-02-22", testid + "key up previous month", testid + "key up previous month");
|
||||
|
||||
// the displayed month may be changed with the page up and page down keys,
|
||||
// however this only changes the displayed month, not the current value.
|
||||
synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, dp, "monthchange", testid + "key page down");
|
||||
is(dp.value, "2003-02-22", testid + "key page down");
|
||||
|
||||
// the monthchange event is fired when the displayed month is changed
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, dp, "monthchange", testid + "key up after month change");
|
||||
is(dp.value, "2003-02-15", testid + "key up after month change");
|
||||
|
||||
synthesizeKeyExpectEvent("VK_PAGE_UP", { }, dp, "monthchange", testid + "key page up");
|
||||
is(dp.value, "2003-02-15", testid + "key page up");
|
||||
|
||||
// the value of a read only datepicker cannot be changed
|
||||
dp.readOnly = true;
|
||||
synthesizeKeyExpectEvent("VK_LEFT", { }, dp, "!change", testid + "key left read only");
|
||||
is(dp.value, "2003-02-15", testid + "key left read only");
|
||||
synthesizeKeyExpectEvent("VK_RIGHT", { }, dp, "!change", testid + "key right read only");
|
||||
is(dp.value, "2003-02-15", testid + "key right read only");
|
||||
synthesizeKeyExpectEvent("VK_DOWN", { }, dp, "!change", testid + "key down read only");
|
||||
is(dp.value, "2003-02-15", testid + "key down read only");
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, dp, "!change", testid + "key up read only");
|
||||
is(dp.value, "2003-02-15", testid + "key up read only");
|
||||
|
||||
// month can still be changed even when readonly
|
||||
synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, dp, "monthchange",
|
||||
testid + "key page up read only");
|
||||
synthesizeKeyExpectEvent("VK_PAGE_UP", { }, dp, "monthchange",
|
||||
testid + "key page down read only");
|
||||
|
||||
dp.readOnly = false;
|
||||
synthesizeKeyExpectEvent("VK_LEFT", { }, dp, "change", testid + "key left changable again");
|
||||
is(dp.value, "2003-02-14", testid + "key left changable again");
|
||||
|
||||
// the value of a disabled datepicker cannot be changed
|
||||
dp.disabled = true;
|
||||
synthesizeKeyExpectEvent("VK_LEFT", { }, dp, "!change", testid + "key left disabled");
|
||||
is(dp.value, "2003-02-14", testid + "key left disabled");
|
||||
synthesizeKeyExpectEvent("VK_RIGHT", { }, dp, "!change", testid + "key right disabled");
|
||||
is(dp.value, "2003-02-14", testid + "key right disabled");
|
||||
synthesizeKeyExpectEvent("VK_DOWN", { }, dp, "!change", testid + "key down disabled");
|
||||
is(dp.value, "2003-02-14", testid + "key down disabled");
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, dp, "!change", testid + "key up disabled");
|
||||
is(dp.value, "2003-02-14", testid + "key up disabled");
|
||||
|
||||
// month cannot be changed even when disabled
|
||||
synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, dp, "!monthchange",
|
||||
testid + "key page down disabled");
|
||||
synthesizeKeyExpectEvent("VK_PAGE_UP", { }, dp, "!monthchange",
|
||||
testid + "key page up disabled");
|
||||
|
||||
dp.disabled = false;
|
||||
synthesizeKeyExpectEvent("VK_RIGHT", { }, dp, "change", testid + "key right enabled again");
|
||||
is(dp.value, "2003-02-15", testid + "key right enabled again");
|
||||
}
|
||||
|
||||
function testtag_datepicker_UI_key(dp, testid, value, field,
|
||||
uyear, umonth, udate,
|
||||
dyear, dmonth, ddate)
|
||||
{
|
||||
dp.value = value;
|
||||
field.focus();
|
||||
|
||||
synthesizeKey("VK_UP", { });
|
||||
testtag_comparedate(dp, testid + " " + value + " key up", uyear, umonth, udate);
|
||||
|
||||
synthesizeKey("VK_DOWN", { });
|
||||
testtag_comparedate(dp, testid + " " + value + " key down", dyear, dmonth, ddate);
|
||||
}
|
||||
|
||||
function testtag_getdatestring(year, month, date)
|
||||
{
|
||||
month = (month < 9) ? ("0" + ++month) : month + 1;
|
||||
if (date < 10)
|
||||
date = "0" + date;
|
||||
return year + "-" + month + "-" + date;
|
||||
}
|
||||
|
||||
function testtag_comparedate(dp, testid, year, month, date)
|
||||
{
|
||||
is(dp.value, testtag_getdatestring(year, month, date), testid + " value");
|
||||
if (testid.indexOf("initial") == -1)
|
||||
is(dp.getAttribute("value"),
|
||||
testtag_getdatestring(year, month, date),
|
||||
testid + " value attribute");
|
||||
|
||||
var dateValue = dp.dateValue;
|
||||
ok(dateValue.getFullYear() == year &&
|
||||
dateValue.getMonth() == month &&
|
||||
dateValue.getDate() == date,
|
||||
testid + " dateValue");
|
||||
|
||||
is(dp.year, year, testid + " year");
|
||||
is(dp.month, month, testid + " month");
|
||||
is(dp.date, date, testid + " date");
|
||||
}
|
||||
|
||||
]]>
|
||||
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -0,0 +1,206 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<!--
|
||||
XUL Widget Test for timepicker
|
||||
-->
|
||||
<window title="timepicker" width="500" height="600"
|
||||
onload="setTimeout(testtag_timepicker, 0);"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<timepicker id="timepicker"/>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function testtag_timepicker()
|
||||
{
|
||||
var tp = document.getElementById("timepicker");
|
||||
|
||||
var testid = "timepicker ";
|
||||
|
||||
var today = new Date();
|
||||
var thour = today.getHours();
|
||||
var tminute = today.getMinutes();
|
||||
var tsecond = today.getSeconds();
|
||||
|
||||
// testtag_comparetime(tp, testid + "initial", thour, tminute, tsecond);
|
||||
|
||||
// check that setting the value property works
|
||||
tp.value = testtag_gettimestring(thour, tminute, tsecond);
|
||||
testtag_comparetime(tp, testid + "set value", thour, tminute, tsecond);
|
||||
|
||||
// check that setting the dateValue property works
|
||||
tp.dateValue = today;
|
||||
testtag_comparetime(tp, testid + "set dateValue", thour, tminute, tsecond);
|
||||
ok(tp.value !== today, testid + " set dateValue different time");
|
||||
|
||||
ok(!tp.readOnly, testid + "readOnly");
|
||||
tp.readOnly = true;
|
||||
ok(tp.readOnly, testid + "set readOnly");
|
||||
tp.readOnly = false;
|
||||
ok(!tp.readOnly, testid + "clear readOnly");
|
||||
|
||||
function setTimeField(field, value, expectException,
|
||||
expectedHour, expectedMinute, expectedSecond)
|
||||
{
|
||||
var exh = false;
|
||||
try {
|
||||
tp[field] = value;
|
||||
} catch (ex) { exh = true; }
|
||||
is(exh, expectException, testid + "set " + field + " " + value);
|
||||
testtag_comparetime(tp, testid + "set " + field + " " + value,
|
||||
expectedHour, expectedMinute, expectedSecond);
|
||||
}
|
||||
|
||||
// check the value property
|
||||
setTimeField("value", "0:0:0", false, 0, 0, 0);
|
||||
setTimeField("value", "21:1:40", false, 21, 1, 40);
|
||||
setTimeField("value", "7:11:8", false, 7, 11, 8);
|
||||
setTimeField("value", "04:07:02", false, 4, 7, 2);
|
||||
setTimeField("value", "10:42:20", false, 10, 42, 20);
|
||||
|
||||
// check that the hour, minute and second fields can be set properly
|
||||
setTimeField("hour", 7, false, 7, 42, 20);
|
||||
setTimeField("hour", 0, false, 0, 42, 20);
|
||||
setTimeField("hour", 21, false, 21, 42, 20);
|
||||
setTimeField("hour", -1, true, 21, 42, 20);
|
||||
setTimeField("hour", 24, true, 21, 42, 20);
|
||||
|
||||
setTimeField("minute", 0, false, 21, 0, 20);
|
||||
setTimeField("minute", 9, false, 21, 9, 20);
|
||||
setTimeField("minute", 10, false, 21, 10, 20);
|
||||
setTimeField("minute", 35, false, 21, 35, 20);
|
||||
setTimeField("minute", -1, true, 21, 35, 20);
|
||||
setTimeField("minute", 60, true, 21, 35, 20);
|
||||
|
||||
setTimeField("second", 0, false, 21, 35, 0);
|
||||
setTimeField("second", 9, false, 21, 35, 9);
|
||||
setTimeField("second", 10, false, 21, 35, 10);
|
||||
setTimeField("second", 51, false, 21, 35, 51);
|
||||
setTimeField("second", -1, true, 21, 35, 51);
|
||||
setTimeField("second", 60, true, 21, 35, 51);
|
||||
|
||||
// check when seconds is not specified
|
||||
setTimeField("value", "06:05", false, 6, 5, 0);
|
||||
setTimeField("value", "06:15", false, 6, 15, 0);
|
||||
setTimeField("value", "16:15", false, 16, 15, 0);
|
||||
|
||||
// check that times overflow properly
|
||||
setTimeField("value", "5:65:21", false, 6, 5, 21);
|
||||
setTimeField("value", "5:25:72", false, 5, 26, 12);
|
||||
|
||||
// check invalid values for the value and dateValue properties
|
||||
tp.value = "14:25:48";
|
||||
setTimeField("value", "", true, 14, 25, 48);
|
||||
setTimeField("value", "1:5:6:6", true, 14, 25, 48);
|
||||
setTimeField("value", "2:a:19", true, 14, 25, 48);
|
||||
setTimeField("dateValue", "none", true, 14, 25, 48);
|
||||
|
||||
// check the fields
|
||||
ok(tp.hourField instanceof HTMLInputElement, testid + "hourField");
|
||||
ok(tp.minuteField instanceof HTMLInputElement, testid + "minuteField");
|
||||
ok(tp.secondField instanceof HTMLInputElement, testid + "secondField");
|
||||
|
||||
testtag_timepicker_UI(tp, testid);
|
||||
|
||||
tp.readOnly = true;
|
||||
|
||||
// check that keyboard usage doesn't change the value when the timepicker
|
||||
// is read only
|
||||
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
|
||||
tp.hourField, 14, 25, 48, 14, 25, 48);
|
||||
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
|
||||
tp.minuteField, 14, 25, 48, 14, 25, 48);
|
||||
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
|
||||
tp.secondField, 14, 25, 48, 14, 25, 48);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testtag_timepicker_UI(tp, testid)
|
||||
{
|
||||
testid += "UI";
|
||||
|
||||
// test adjusting the time with the up and down keys
|
||||
testtag_timepicker_UI_key(tp, testid, "0:12:25", tp.hourField, 1, 12, 25, 0, 12, 25);
|
||||
testtag_timepicker_UI_key(tp, testid, "11:12:25", tp.hourField, 12, 12, 25, 11, 12, 25);
|
||||
testtag_timepicker_UI_key(tp, testid, "7:12:25", tp.hourField, 8, 12, 25, 7, 12, 25);
|
||||
testtag_timepicker_UI_key(tp, testid, "16:12:25", tp.hourField, 17, 12, 25, 16, 12, 25);
|
||||
testtag_timepicker_UI_key(tp, testid, "23:12:25", tp.hourField, 0, 12, 25, 23, 12, 25);
|
||||
|
||||
testtag_timepicker_UI_key(tp, testid, "15:23:46", tp.minuteField, 15, 24, 46, 15, 23, 46);
|
||||
testtag_timepicker_UI_key(tp, testid, "15:0:46", tp.minuteField, 15, 1, 46, 15, 0, 46);
|
||||
testtag_timepicker_UI_key(tp, testid, "15:59:46", tp.minuteField, 15, 0, 46, 15, 59, 46);
|
||||
|
||||
testtag_timepicker_UI_key(tp, testid, "11:50:46", tp.secondField, 11, 50, 47, 11, 50, 46);
|
||||
testtag_timepicker_UI_key(tp, testid, "11:50:0", tp.secondField, 11, 50, 1, 11, 50, 0);
|
||||
testtag_timepicker_UI_key(tp, testid, "11:50:59", tp.secondField, 11, 50, 0, 11, 50, 59);
|
||||
}
|
||||
|
||||
function testtag_timepicker_UI_key(tp, testid, value, field,
|
||||
uhour, uminute, usecond,
|
||||
dhour, dminute, dsecond)
|
||||
{
|
||||
tp.value = value;
|
||||
field.focus();
|
||||
|
||||
var eventTarget = tp.readOnly ? null : tp;
|
||||
|
||||
var testname = testid + " " + value + " key down";
|
||||
synthesizeKeyExpectEvent("VK_UP", { }, eventTarget, "change", testname);
|
||||
testtag_comparetime(tp, testid + " " + value + " key up", uhour, uminute, usecond);
|
||||
|
||||
testname = testid + " " + value + " key down";
|
||||
synthesizeKeyExpectEvent("VK_DOWN", { }, eventTarget, "change", testname);
|
||||
testtag_comparetime(tp, testname, dhour, dminute, dsecond);
|
||||
}
|
||||
|
||||
function testtag_gettimestring(hour, minute, second)
|
||||
{
|
||||
if (minute < 10)
|
||||
minute = "0" + minute;
|
||||
if (second < 10)
|
||||
second = "0" + second;
|
||||
return hour + ":" + minute + ":" + second;
|
||||
}
|
||||
|
||||
function testtag_comparetime(tp, testid, hour, minute, second)
|
||||
{
|
||||
is(tp.value, testtag_gettimestring(hour, minute, second), testid + " value");
|
||||
is(tp.getAttribute("value"),
|
||||
testtag_gettimestring(hour, minute, second),
|
||||
testid + " value attribute");
|
||||
|
||||
var dateValue = tp.dateValue;
|
||||
ok(dateValue.getHours() == hour &&
|
||||
dateValue.getMinutes() == minute &&
|
||||
dateValue.getSeconds() == second,
|
||||
testid + " dateValue");
|
||||
|
||||
is(tp.hour, hour, testid + " hour");
|
||||
is(tp.minute, minute, testid + " minute");
|
||||
is(tp.second, second, testid + " second");
|
||||
}
|
||||
|
||||
]]>
|
||||
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -593,16 +593,17 @@
|
|||
var date = this._dateValue.getDate();
|
||||
if (date < 10)
|
||||
date = "0" + date;
|
||||
return this._dateValue.getFullYear() + "/" + month + "/" + date;
|
||||
return this._dateValue.getFullYear() + "-" + month + "-" + date;
|
||||
]]>
|
||||
|
||||
</getter>
|
||||
<setter>
|
||||
<![CDATA[
|
||||
if (val.search(/^([0-9]{1,4})\/([0-9]{1,2})\/([0-9]{1,2})$/) != 0)
|
||||
var results = val.match(/^([0-9]{1,4})\-([0-9]{1,2})\-([0-9]{1,2})$/);
|
||||
if (!results)
|
||||
throw "Invalid Date";
|
||||
|
||||
this.dateValue = new Date(val);
|
||||
this.dateValue = new Date(results[1] + "/" + results[2] + "/" + results[3]);
|
||||
this.setAttribute("value", this.value);
|
||||
return val;
|
||||
]]>
|
||||
|
|
Загрузка…
Ссылка в новой задаче