toolkit/content/tests/chrome/test_timepicker.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4 <!--
michael@0 5 XUL Widget Test for timepicker
michael@0 6 -->
michael@0 7 <window title="timepicker" width="500" height="600"
michael@0 8 onload="setTimeout(testtag_timepicker, 0);"
michael@0 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 12
michael@0 13 <timepicker id="timepicker"/>
michael@0 14
michael@0 15 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 16 <p id="display"></p>
michael@0 17 <div id="content" style="display: none">
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 </pre>
michael@0 21 </body>
michael@0 22
michael@0 23 <script>
michael@0 24 <![CDATA[
michael@0 25
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27
michael@0 28 function testtag_timepicker()
michael@0 29 {
michael@0 30 var tp = document.getElementById("timepicker");
michael@0 31
michael@0 32 var testid = "timepicker ";
michael@0 33
michael@0 34 var today = new Date();
michael@0 35 var thour = today.getHours();
michael@0 36 var tminute = today.getMinutes();
michael@0 37 var tsecond = today.getSeconds();
michael@0 38
michael@0 39 // testtag_comparetime(tp, testid + "initial", thour, tminute, tsecond);
michael@0 40
michael@0 41 // check that setting the value property works
michael@0 42 tp.value = testtag_gettimestring(thour, tminute, tsecond);
michael@0 43 testtag_comparetime(tp, testid + "set value", thour, tminute, tsecond);
michael@0 44
michael@0 45 var numberOrder = /^(\D*)\s*(\d+)(\D*)(\d+)(\D*)(\d+)\s*(\D*)$/;
michael@0 46 var fdt = new Date(2000,0,1,16,7,9).toLocaleFormat("%X");
michael@0 47 is(tp.is24HourClock, Number(fdt.match(numberOrder)[2]) > 12, "is24HourClock");
michael@0 48
michael@0 49 // check that setting the dateValue property works
michael@0 50 tp.dateValue = today;
michael@0 51 testtag_comparetime(tp, testid + "set dateValue", thour, tminute, tsecond);
michael@0 52 ok(tp.value !== today, testid + " set dateValue different time");
michael@0 53
michael@0 54 ok(!tp.readOnly, testid + "readOnly");
michael@0 55 tp.readOnly = true;
michael@0 56 ok(tp.readOnly, testid + "set readOnly");
michael@0 57 tp.readOnly = false;
michael@0 58 ok(!tp.readOnly, testid + "clear readOnly");
michael@0 59
michael@0 60 function setTimeField(field, value, expectException,
michael@0 61 expectedHour, expectedMinute, expectedSecond)
michael@0 62 {
michael@0 63 var exh = false;
michael@0 64 try {
michael@0 65 tp[field] = value;
michael@0 66 } catch (ex) { exh = true; }
michael@0 67 is(exh, expectException, testid + "set " + field + " " + value);
michael@0 68 testtag_comparetime(tp, testid + "set " + field + " " + value,
michael@0 69 expectedHour, expectedMinute, expectedSecond);
michael@0 70 }
michael@0 71
michael@0 72 // check the value property
michael@0 73 setTimeField("value", "0:0:0", false, 0, 0, 0);
michael@0 74 setTimeField("value", "21:1:40", false, 21, 1, 40);
michael@0 75 setTimeField("value", "7:11:8", false, 7, 11, 8);
michael@0 76 setTimeField("value", "04:07:02", false, 4, 7, 2);
michael@0 77 setTimeField("value", "10:42:20", false, 10, 42, 20);
michael@0 78
michael@0 79 // check that the hour, minute and second fields can be set properly
michael@0 80 setTimeField("hour", 7, false, 7, 42, 20);
michael@0 81 setTimeField("hour", 0, false, 0, 42, 20);
michael@0 82 setTimeField("hour", 21, false, 21, 42, 20);
michael@0 83 setTimeField("hour", -1, true, 21, 42, 20);
michael@0 84 setTimeField("hour", 24, true, 21, 42, 20);
michael@0 85
michael@0 86 setTimeField("minute", 0, false, 21, 0, 20);
michael@0 87 setTimeField("minute", 9, false, 21, 9, 20);
michael@0 88 setTimeField("minute", 10, false, 21, 10, 20);
michael@0 89 setTimeField("minute", 35, false, 21, 35, 20);
michael@0 90 setTimeField("minute", -1, true, 21, 35, 20);
michael@0 91 setTimeField("minute", 60, true, 21, 35, 20);
michael@0 92
michael@0 93 setTimeField("second", 0, false, 21, 35, 0);
michael@0 94 setTimeField("second", 9, false, 21, 35, 9);
michael@0 95 setTimeField("second", 10, false, 21, 35, 10);
michael@0 96 setTimeField("second", 51, false, 21, 35, 51);
michael@0 97 setTimeField("second", -1, true, 21, 35, 51);
michael@0 98 setTimeField("second", 60, true, 21, 35, 51);
michael@0 99
michael@0 100 // check when seconds is not specified
michael@0 101 setTimeField("value", "06:05", false, 6, 5, 0);
michael@0 102 setTimeField("value", "06:15", false, 6, 15, 0);
michael@0 103 setTimeField("value", "16:15", false, 16, 15, 0);
michael@0 104
michael@0 105 // check that times overflow properly
michael@0 106 setTimeField("value", "5:65:21", false, 6, 5, 21);
michael@0 107 setTimeField("value", "5:25:72", false, 5, 26, 12);
michael@0 108
michael@0 109 // check invalid values for the value and dateValue properties
michael@0 110 tp.value = "14:25:48";
michael@0 111 setTimeField("value", "", true, 14, 25, 48);
michael@0 112 setTimeField("value", "1:5:6:6", true, 14, 25, 48);
michael@0 113 setTimeField("value", "2:a:19", true, 14, 25, 48);
michael@0 114 setTimeField("dateValue", "none", true, 14, 25, 48);
michael@0 115
michael@0 116 // check the fields
michael@0 117 ok(tp.hourField instanceof HTMLInputElement, testid + "hourField");
michael@0 118 ok(tp.minuteField instanceof HTMLInputElement, testid + "minuteField");
michael@0 119 ok(tp.secondField instanceof HTMLInputElement, testid + "secondField");
michael@0 120
michael@0 121 testtag_timepicker_UI(tp, testid);
michael@0 122
michael@0 123 tp.readOnly = true;
michael@0 124
michael@0 125 // check that keyboard usage doesn't change the value when the timepicker
michael@0 126 // is read only
michael@0 127 testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
michael@0 128 tp.hourField, 14, 25, 48, 14, 25, 48);
michael@0 129 testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
michael@0 130 tp.minuteField, 14, 25, 48, 14, 25, 48);
michael@0 131 testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
michael@0 132 tp.secondField, 14, 25, 48, 14, 25, 48);
michael@0 133
michael@0 134 SimpleTest.finish();
michael@0 135 }
michael@0 136
michael@0 137 function testtag_timepicker_UI(tp, testid)
michael@0 138 {
michael@0 139 testid += "UI";
michael@0 140
michael@0 141 // test adjusting the time with the up and down keys
michael@0 142 testtag_timepicker_UI_key(tp, testid, "0:12:25", tp.hourField, 1, 12, 25, 0, 12, 25);
michael@0 143 testtag_timepicker_UI_key(tp, testid, "11:12:25", tp.hourField, 12, 12, 25, 11, 12, 25);
michael@0 144 testtag_timepicker_UI_key(tp, testid, "7:12:25", tp.hourField, 8, 12, 25, 7, 12, 25);
michael@0 145 testtag_timepicker_UI_key(tp, testid, "16:12:25", tp.hourField, 17, 12, 25, 16, 12, 25);
michael@0 146 testtag_timepicker_UI_key(tp, testid, "23:12:25", tp.hourField, 0, 12, 25, 23, 12, 25);
michael@0 147
michael@0 148 testtag_timepicker_UI_key(tp, testid, "15:23:46", tp.minuteField, 15, 24, 46, 15, 23, 46);
michael@0 149 testtag_timepicker_UI_key(tp, testid, "15:0:46", tp.minuteField, 15, 1, 46, 15, 0, 46);
michael@0 150 testtag_timepicker_UI_key(tp, testid, "15:59:46", tp.minuteField, 15, 0, 46, 15, 59, 46);
michael@0 151
michael@0 152 testtag_timepicker_UI_key(tp, testid, "11:50:46", tp.secondField, 11, 50, 47, 11, 50, 46);
michael@0 153 testtag_timepicker_UI_key(tp, testid, "11:50:0", tp.secondField, 11, 50, 1, 11, 50, 0);
michael@0 154 testtag_timepicker_UI_key(tp, testid, "11:50:59", tp.secondField, 11, 50, 0, 11, 50, 59);
michael@0 155 }
michael@0 156
michael@0 157 function testtag_timepicker_UI_key(tp, testid, value, field,
michael@0 158 uhour, uminute, usecond,
michael@0 159 dhour, dminute, dsecond)
michael@0 160 {
michael@0 161 tp.value = value;
michael@0 162 field.focus();
michael@0 163
michael@0 164 var eventTarget = tp.readOnly ? null : tp;
michael@0 165
michael@0 166 var testname = testid + " " + value + " key up";
michael@0 167 synthesizeKeyExpectEvent("VK_UP", { }, eventTarget, "change", testname);
michael@0 168 testtag_comparetime(tp, testname, uhour, uminute, usecond);
michael@0 169
michael@0 170 testname = testid + " " + value + " key down";
michael@0 171 synthesizeKeyExpectEvent("VK_DOWN", { }, eventTarget, "change", testname);
michael@0 172 testtag_comparetime(tp, testname, dhour, dminute, dsecond);
michael@0 173 }
michael@0 174
michael@0 175 function testtag_gettimestring(hour, minute, second)
michael@0 176 {
michael@0 177 if (minute < 10)
michael@0 178 minute = "0" + minute;
michael@0 179 if (second < 10)
michael@0 180 second = "0" + second;
michael@0 181 return hour + ":" + minute + ":" + second;
michael@0 182 }
michael@0 183
michael@0 184 function testtag_comparetime(tp, testid, hour, minute, second)
michael@0 185 {
michael@0 186 is(tp.value, testtag_gettimestring(hour, minute, second), testid + " value");
michael@0 187 is(tp.getAttribute("value"),
michael@0 188 testtag_gettimestring(hour, minute, second),
michael@0 189 testid + " value attribute");
michael@0 190
michael@0 191 var dateValue = tp.dateValue;
michael@0 192 ok(dateValue.getHours() == hour &&
michael@0 193 dateValue.getMinutes() == minute &&
michael@0 194 dateValue.getSeconds() == second,
michael@0 195 testid + " dateValue");
michael@0 196
michael@0 197 is(tp.hour, hour, testid + " hour");
michael@0 198 is(tp.minute, minute, testid + " minute");
michael@0 199 is(tp.second, second, testid + " second");
michael@0 200 }
michael@0 201
michael@0 202 ]]>
michael@0 203
michael@0 204 </script>
michael@0 205
michael@0 206 </window>

mercurial