| <!DOCTYPE html> |
| <html> |
| <head> |
| <link rel="stylesheet" href="../../js/resources/js-test-style.css"> |
| <script src="../../js/resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description('Check stepping-up and -down for datetime-local input fields from renderer. No cases of empty initial values.'); |
| |
| var input = document.createElement('input'); |
| var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"'; |
| |
| function sendKey(keyName) { |
| var event = document.createEvent('KeyboardEvent'); |
| event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName); |
| input.dispatchEvent(event); |
| } |
| |
| 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") |
| if (optionalStepCount < 0) |
| for (var i = 0; i < -optionalStepCount; i++) |
| sendKey('Down'); |
| else |
| for (var i = 0; i < optionalStepCount; i++) |
| sendKey('Up'); |
| else |
| sendKey('Up'); |
| return input.value; |
| } |
| |
| function stepDown(value, step, min, optionalStepCount) { |
| setInputAttributes(min, null, step, value); |
| if (typeof optionalStepCount != "undefined") |
| if (optionalStepCount < 0) |
| for (var i = 0; i < -optionalStepCount; i++) |
| sendKey('Up'); |
| else |
| for (var i = 0; i < optionalStepCount; i++) |
| sendKey('Down'); |
| else |
| sendKey('Down'); |
| return input.value; |
| } |
| |
| input.type = 'datetime-local'; |
| debug('Function arguments are (value, step, {min or max}, [stepCount]).'); |
| debug('Normal cases'); |
| shouldBe('stepUp("2010-02-10T20:13", null, null)', '"2010-02-10T20:14"'); |
| shouldBe('stepDown("2010-02-10T20:13", null, null)', '"2010-02-10T20:12"'); |
| shouldBe('stepUp("2010-02-10T20:13", null, null, 10)', '"2010-02-10T20:23"'); |
| shouldBe('stepDown("2010-02-10T20:13", null, null, 11)', '"2010-02-10T20:02"'); |
| shouldBe('stepUp("1970-01-01T20:13", "4", null, 2)', '"1970-01-01T20:13:08"'); |
| shouldBe('stepDown("1970-01-01T20:13", "4", null, 3)', '"1970-01-01T20:12:48"'); |
| debug('Step=any'); |
| shouldBe('stepUp("2010-02-10T20:13", "any", null)', '"2010-02-10T20:14"'); |
| shouldBe('stepDown("2010-02-10T20:13", "any", null)', '"2010-02-10T20:12"'); |
| debug('Overflow/underflow'); |
| shouldBe('stepUp("2010-02-10T20:13", "3.40282346e+38", null)', '"275760-09-13T00:00:00.000"'); |
| shouldBe('stepDown("2010-02-10T20:13", "3.40282346e+38", null)', '"1970-01-01T00:00:00.000"'); |
| shouldBe('stepUp("2010-02-10T20:13", "1", "2010-02-10T20:13")', '"2010-02-10T20:13"'); |
| shouldBe('stepDown("2010-02-10T20:13", "1", "2010-02-10T20:13")', '"2010-02-10T20:13"'); |
| debug('stepDown()/stepUp() for stepMismatch values'); |
| shouldBe('stepDown("2010-02-10T20:13", "3", "2010-02-10T20:12:56")', '"2010-02-10T20:12:59"'); |
| shouldBe('stepUp("1970-01-01T00:13", "7", "")', '"1970-01-01T00:13:04"'); |
| |
| debug(''); |
| var successfullyParsed = true; |
| </script> |
| <script src="../../js/resources/js-test-post.js"></script> |
| </body> |
| </html> |