<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Check stepUp() and stepDown() bahevior for type=datetime-local.');

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 = 'datetime-local';
debug('Invalid value');
shouldBe('stepUp("", null, null)', '"1970-01-01T00:01"');
shouldBe('stepDown("", null, null)', '"1969-12-31T23:59"');
debug('Non-number arguments');
shouldBe('stepUp("2010-02-10T20:13", null, null, "0")', '"2010-02-10T20:13"');
shouldBe('stepDown("2010-02-10T20:13", null, null, "0")', '"2010-02-10T20:13"');
shouldBe('stepUp("2010-02-10T20:13", null, null, "foo")', '"2010-02-10T20:13"');
shouldBe('stepDown("2010-02-10T20:13", null, null, "foo")', '"2010-02-10T20:13"');
shouldBe('stepUp("2010-02-10T20:13", null, null, null)', '"2010-02-10T20:13"');
shouldBe('stepDown("2010-02-10T20:13", null, null, null)', '"2010-02-10T20:13"');
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');
shouldThrowErrorName('stepUp("2010-02-10T20:13", "any", null)', "InvalidStateError");
shouldThrowErrorName('stepDown("2010-02-10T20:13", "any", null)', "InvalidStateError");
debug('Overflow/underflow');
shouldBe('stepUp("2010-02-10T20:13", "3.40282346e+38", null)', '"2010-02-10T20:13"');
shouldBe('stepDown("2010-02-10T20:13", "3.40282346e+38", null)', '"1970-01-01T00:00"');
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"');
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
