| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../../resources/js-test.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description('Check stepUp() and stepDown() behavior for type=time.'); |
| |
| var input = document.createElement('input'); |
| |
| function setInputAttributes(min, max, step, value) { |
| input.min = min; |
| input.max = max; |
| input.step = step; |
| input.value = value; |
| } |
| |
| function stepUp(value, step, max, optionalStepCount) { |
| setInputAttributes(null, max, step, value); |
| if (typeof optionalStepCount != "undefined") |
| input.stepUp(optionalStepCount); |
| else |
| input.stepUp(); |
| return input.value; |
| } |
| |
| function stepDown(value, step, min, optionalStepCount) { |
| setInputAttributes(min, null, step, value); |
| if (typeof optionalStepCount != "undefined") |
| input.stepDown(optionalStepCount); |
| else |
| input.stepDown(); |
| return input.value; |
| } |
| |
| input.type = 'time'; |
| debug('Invalid value'); |
| shouldBeEqualToString('stepUp("", null, null)', '00:01'); |
| shouldBeEqualToString('stepDown("", null, null)', '00:00'); |
| debug('Non-number arguments'); |
| shouldBeEqualToString('stepUp("20:13", null, null, "0")', '20:13'); |
| shouldBeEqualToString('stepDown("20:13", null, null, "0")', '20:13'); |
| shouldBeEqualToString('stepUp("20:13", null, null, "foo")', '20:13'); |
| shouldBeEqualToString('stepDown("20:13", null, null, "foo")', '20:13'); |
| shouldBeEqualToString('stepUp("20:13", null, null, null)', '20:13'); |
| shouldBeEqualToString('stepDown("20:13", null, null, null)', '20:13'); |
| debug('Normal cases'); |
| shouldBeEqualToString('stepUp("20:13", null, null)', '20:14'); |
| shouldBeEqualToString('stepDown("20:13", null, null)', '20:12'); |
| shouldBeEqualToString('stepUp("20:13", null, null, 10)', '20:23'); |
| shouldBeEqualToString('stepDown("20:13", null, null, 11)', '20:02'); |
| shouldBeEqualToString('stepUp("20:13", "4", null, 2)', '20:13:08'); |
| shouldBeEqualToString('stepDown("20:13", "4", null, 3)', '20:12:48'); |
| debug('Step=any'); |
| shouldThrow('stepUp("20:13", "any", null)'); |
| shouldThrow('stepDown("20:13", "any", null)'); |
| debug('Overflow/underflow'); |
| shouldBeEqualToString('stepUp("20:13", "3.40282346e+38", null)', '20:13'); |
| shouldBeEqualToString('stepDown("20:13", "3.40282346e+38", null)', '20:13'); |
| shouldBeEqualToString('stepUp("20:13", "1", "20:13")', '20:13:00'); |
| shouldBeEqualToString('stepDown("20:13", "1", "20:13")', '20:13:00'); |
| shouldBeEqualToString('stepUp("23:59", null, null)', '23:59'); |
| shouldBeEqualToString('stepDown("00:00", null, null)', '00:00'); |
| |
| debug(''); |
| debug('Invalid min/max:'); |
| shouldBeEqualToString('setInputAttributes("10:00", "09:00", "60", "08:00"); input.stepUp(); input.value', '08:00'); |
| // Threre are no valid values between 00:00 - 00:33 because the step-base |
| // is 12:34. |
| var inputWithInitialValue = document.createElement('input'); |
| inputWithInitialValue.type = 'time'; |
| inputWithInitialValue.setAttribute('value', '12:34'); |
| inputWithInitialValue.setAttribute('step', '3600'); |
| inputWithInitialValue.setAttribute('max', '00:33'); |
| shouldBeEqualToString('inputWithInitialValue.stepUp(); inputWithInitialValue.value', '12:34'); |
| |
| debug(''); |
| debug('Step-mismatched initial values'); |
| // There are no step-match values in 00:00 - 23:59:59.999 except 00:00. |
| shouldBeEqualToString('stepUp("20:13", "86400.000", null, 65536)', '20:13'); |
| shouldBeEqualToString('stepUp("20:13", "86400.001", null, 65536)', '20:13'); |
| shouldBeEqualToString('stepUp("20:13", "600", null, 1)', '20:20'); |
| shouldBeEqualToString('stepUp("20:13", "600", null, 2)', '20:30'); |
| shouldBeEqualToString('stepDown("20:13", "600", null, 1)', '20:10'); |
| shouldBeEqualToString('stepDown("20:13", "600", null, 2)', '20:00'); |
| |
| debug(''); |
| </script> |
| </body> |
| </html> |