time.html (9680B)
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <title>Input Time</title> 6 <meta name=viewport content="width=device-width, maximum-scale=1.0, user-scalable=no" /> 7 <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-input-element"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 </head> 11 12 <body> 13 <h1>Input Time</h1> 14 <div style="display:none;"> 15 <input type="time "id="chkDefaultValue" /> 16 <input type="time" id="chkStep" /> 17 <input type="time" id="chkSetValueTest" /> 18 <input type="time" id="chkSupportAttribute" min="01:01:01.001" max="12:12:12.012" step="600" /> 19 </div> 20 <div id="log"> 21 </div> 22 23 <script type="text/javascript"> 24 25 /* check default value */ 26 test(function(){ assert_equals(document.getElementById("chkDefaultValue").value, ""); 27 }, "time element of default time value"); 28 test(function(){assert_equals(document.getElementById('chkStep').step, ""); 29 }, "step attribute on default value check"); 30 test(function(){assert_equals(document.getElementById('chkDefaultValue').max, ""); 31 }, "max attribute on default value check") 32 test(function(){assert_equals(document.getElementById('chkDefaultValue').max, ""); 33 }, "min attribute on default value check") 34 35 /* simple attribute test*/ 36 test(function(){assert_equals(document.getElementById("chkSupportAttribute").type,"time");} 37 , "type attribute support on input element"); 38 test(function(){assert_equals(document.getElementById('chkSupportAttribute').min, "01:01:01.001")} 39 , "max attribute support on input element"); 40 test(function(){assert_equals(document.getElementById('chkSupportAttribute').max, "12:12:12.012")} 41 , "min attribute support on input element"); 42 test(function(){assert_equals(document.getElementById("chkSupportAttribute").step, "600")} 43 , "step attribute support on input element"); 44 45 /* check step up and down */ 46 var _StepTest = document.getElementById("chkStep"); 47 test(function(){ assert_true(typeof(_StepTest.stepUp) ==="function" ) } , "stepUp function support on input Element"); 48 test(function(){ assert_true(typeof(_StepTest.stepDown) ==="function" ) } , "stepDown function support on input Element"); 49 50 test(function(){ 51 _StepTest.value = "12:00"; 52 _StepTest.step = ""; 53 _StepTest.stepUp(); 54 assert_in_array( 55 _StepTest.value, 56 [ 57 "12:01", 58 "12:01:00", 59 "12:01:00.0", 60 "12:01:00.00", 61 "12:01:00.000"], 62 "a valid time string representing 1 minute after noon"); 63 } , "stepUp step value empty on default step value "); 64 65 test(function(){ 66 _StepTest.value = "12:00"; 67 _StepTest.step = ""; 68 _StepTest.stepDown(); 69 assert_in_array( 70 _StepTest.value, 71 [ 72 "11:59", 73 "11:59:00", 74 "11:59:00.0", 75 "11:59:00.00", 76 "11:59:00.000"], 77 "a valid time string representing 1 minute before noon"); 78 }, "stepDown step value empty default step value"); 79 80 test(function(){ 81 _StepTest.value = "12:00"; 82 _StepTest.step = "-600"; 83 _StepTest.stepUp(); 84 assert_in_array( 85 _StepTest.value, 86 [ 87 "12:01", 88 "12:01:00", 89 "12:01:00.0", 90 "12:01:00.00", 91 "12:01:00.000"], 92 "a valid time string representing 1 minute after noon"); 93 },"stepUp on step value minus"); 94 test(function(){ 95 _StepTest.value = "12:00"; 96 _StepTest.step = "-600"; 97 _StepTest.stepDown(); 98 assert_in_array( 99 _StepTest.value, 100 [ 101 "11:59", 102 "11:59:00", 103 "11:59:00.0", 104 "11:59:00.00", 105 "11:59:00.000"], 106 "a valid time string representing 1 minute before noon"); 107 },"stepDown on step value minus"); 108 109 test(function(){ 110 _StepTest.value = "12:00"; 111 _StepTest.step = "0"; 112 _StepTest.stepUp(); 113 assert_in_array( 114 _StepTest.value, 115 [ 116 "12:01", 117 "12:01:00", 118 "12:01:00.0", 119 "12:01:00.00", 120 "12:01:00.000"], 121 "a valid time string representing 1 minute after noon"); 122 } , "stepUp on step value zero "); 123 test(function(){ 124 _StepTest.value = "12:00"; 125 _StepTest.step = "0"; 126 _StepTest.stepDown(); 127 assert_in_array( 128 _StepTest.value, 129 [ 130 "11:59", 131 "11:59:00", 132 "11:59:00.0", 133 "11:59:00.00", 134 "11:59:00.000"], 135 "a valid time string representing 1 minute before noon"); 136 } , "stepDown on step value zero "); 137 138 test(function(){ 139 _StepTest.value = "00:00"; 140 _StepTest.step = "86399"; 141 _StepTest.stepUp(); 142 assert_in_array( 143 _StepTest.value, 144 [ 145 "23:59:59", 146 "23:59:59.0", 147 "23:59:59.00", 148 "23:59:59.000"], 149 "a valid time string representing 1 second before midnight"); 150 } , "stepUp on step value 24 hour"); 151 test(function(){ 152 _StepTest.value = "23:59:59"; 153 _StepTest.step = "86399"; 154 _StepTest.stepDown(); 155 assert_in_array( 156 _StepTest.value, 157 [ 158 "00:00", 159 "00:00:00", 160 "00:00:00.0", 161 "00:00:00.00", 162 "00:00:00.000"], 163 "a valid time string representing midnight"); 164 } , "stepDown on step value 24 hour "); 165 166 test(function(){ 167 _StepTest.value = "12:00"; 168 _StepTest.step = "3600"; 169 _StepTest.stepUp(); 170 assert_in_array( 171 _StepTest.value, 172 [ 173 "13:00", 174 "13:00:00", 175 "13:00:00.0", 176 "13:00:00.00", 177 "13:00:00.000"], 178 "a valid time string representing 1pm"); 179 } , "stepUp on step value hour "); 180 test(function(){ 181 _StepTest.value = "12:00"; 182 _StepTest.step = "3600"; 183 _StepTest.stepDown(); 184 assert_in_array( 185 _StepTest.value, 186 [ 187 "11:00", 188 "11:00:00", 189 "11:00:00.0", 190 "11:00:00.00", 191 "11:00:00.000"], 192 "a valid time string representing 11am"); 193 } , "stepDown on step value hour "); 194 195 test(function(){ 196 _StepTest.value = "12:00"; 197 _StepTest.step = "1"; 198 _StepTest.stepUp(); 199 assert_in_array( 200 _StepTest.value, 201 [ 202 "12:00:01", 203 "12:00:01.0", 204 "12:00:01.00", 205 "12:00:01.000"], 206 "a valid time string representing 1 second after noon"); 207 } , "stepUp on step value second "); 208 test(function(){ 209 _StepTest.value = "12:00"; 210 _StepTest.step = "1"; 211 _StepTest.stepDown(); 212 assert_in_array( 213 _StepTest.value, 214 [ 215 "11:59:59", 216 "11:59:59.0", 217 "11:59:59.00", 218 "11:59:59.000"], 219 "a valid time string representing 1 second before noon"); 220 } , "stepDown on step value second "); 221 222 test(function(){ 223 _StepTest.value = "12:00"; 224 _StepTest.step = "0.001"; 225 _StepTest.stepUp(); 226 assert_equals(_StepTest.value, "12:00:00.001"); 227 } , "stepUp on step value with fractional seconds"); 228 test(function(){ 229 _StepTest.value = "12:00"; 230 _StepTest.step = "0.001"; 231 _StepTest.stepDown(); 232 assert_equals(_StepTest.value, "11:59:59.999"); 233 } , "stepDown on step value with fractional seconds"); 234 235 test(function(){ 236 _StepTest.value = "13:00:00"; 237 _StepTest.step = "1"; 238 _StepTest.stepUp(2); 239 assert_in_array( 240 _StepTest.value, 241 [ 242 "13:00:02", 243 "13:00:02.0", 244 "13:00:02.00", 245 "13:00:02.000"], 246 "a valid time string representing 2 seconds after 1pm"); 247 }, "stepUp argument 2 times"); 248 test(function(){ 249 _StepTest.value = "13:00:00"; 250 _StepTest.step = "1"; 251 _StepTest.stepDown(2); 252 assert_in_array( 253 _StepTest.value, 254 [ 255 "12:59:58", 256 "12:59:58.0", 257 "12:59:58.00", 258 "12:59:58.000"], 259 "a valid time string representing 2 seconds before 1pm"); 260 }, "stepDown argument 2 times"); 261 262 test(function(){ 263 _StepTest.max = "15:00"; 264 this.add_cleanup(function() { _StepTest.max = ""; }); 265 _StepTest.value = "15:00"; 266 _StepTest.stepUp(); 267 assert_in_array( 268 _StepTest.value, 269 [ 270 "15:00", 271 "15:00:00", 272 "15:00:00.0", 273 "15:00:00.00", 274 "15:00:00.000"], 275 "a valid time string representing 3pm"); 276 } , "stepUp stop because it exceeds the maximum value"); 277 test(function(){ 278 _StepTest.min = "13:00"; 279 this.add_cleanup(function() { _StepTest.min = ""; }); 280 _StepTest.value = "13:00"; 281 _StepTest.stepDown(); 282 assert_in_array( 283 _StepTest.value, 284 [ 285 "13:00", 286 "13:00:00", 287 "13:00:00.0", 288 "13:00:00.00", 289 "13:00:00.000"], 290 "a valid time string representing 1pm"); 291 } , "stepDown stop so lower than the minimum value"); 292 293 test(function(){ 294 // Set min value to ensure that 15:01 - base is a multiple of 2 min (i.e., a 295 // valid value). 296 _StepTest.min = "14:01"; 297 _StepTest.max = "15:01"; 298 this.add_cleanup(function() { _StepTest.min = _StepTest.max = ""; }); 299 _StepTest.value = "15:00"; 300 _StepTest.step = "120"; 301 _StepTest.stepUp(); 302 assert_in_array( 303 _StepTest.value, 304 [ 305 "15:01", 306 "15:01:00", 307 "15:01:00.0", 308 "15:01:00.00", 309 "15:01:00.000"], 310 "a valid time string representing 1 minute after 3pm"); 311 } , "stop at border on stepUp"); 312 test(function(){ 313 _StepTest.min = "12:59"; 314 this.add_cleanup(function() { _StepTest.min = ""; }); 315 _StepTest.value = "13:00"; 316 _StepTest.step = "120"; 317 _StepTest.stepDown(); 318 assert_in_array( 319 _StepTest.value, 320 [ 321 "12:59", 322 "12:59:00", 323 "12:59:00.0", 324 "12:59:00.00", 325 "12:59:00.000"], 326 "a valid time string representing 1 minute before 2pm"); 327 } , "stop at border on stepDown"); 328 329 test(function(){ 330 _StepTest.value = ""; 331 _StepTest.step = "60"; 332 _StepTest.stepUp(); 333 assert_in_array( 334 _StepTest.value, 335 [ 336 "00:01", 337 "00:01:00", 338 "00:01:00.0", 339 "00:01:00.00", 340 "00:01:00.000"], 341 "a valid time string representing 1 minute after midnight"); 342 } , " empty value of stepUp"); 343 344 345 /* set value test */ 346 test(function(){ 347 var _time = document.getElementById("chkSetValueTest"); 348 _time.value = "12:00:00.000"; 349 assert_equals(_time.value, "12:00:00.000"); 350 _time.value = "hh:mi:ss.sss"; 351 assert_equals(_time.value, ""); 352 }, "set value on not time format value"); 353 354 355 </script> 356 </body> 357 </html>