summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/week/week-stepup-stepdown.html
blob: c7beee13a60439b5cda74579aa79f8f9251ae39e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<script src="../../js/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=week.');

var input = document.createElement('input');
var invalidStateErr = '"InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable."';

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 = 'week';
debug('Invalid value');
shouldThrow('stepUp("", null, null)', invalidStateErr);
shouldThrow('stepDown("", null, null)', invalidStateErr);
debug('Non-number arguments');
shouldBe('stepUp("2010-W02", null, null, "0")', '"2010-W02"');
shouldBe('stepDown("2010-W02", null, null, "0")', '"2010-W02"');
shouldBe('stepUp("2010-W02", null, null, "foo")', '"2010-W02"');
shouldBe('stepDown("2010-W02", null, null, "foo")', '"2010-W02"');
shouldBe('stepUp("2010-W02", null, null, null)', '"2010-W02"');
shouldBe('stepDown("2010-W02", null, null, null)', '"2010-W02"');
debug('Normal cases');
shouldBe('stepUp("2010-W02", null, null)', '"2010-W03"');
shouldBe('stepDown("2010-W02", null, null)', '"2010-W01"');
shouldBe('stepUp("2010-W02", null, null, 10)', '"2010-W12"');
shouldBe('stepDown("2010-W02", null, null, 11)', '"2009-W44"');
shouldBe('stepUp("1970-W01", "4", null, 2)', '"1970-W09"');
shouldBe('stepDown("1970-W01", "4", null, 3)', '"1969-W41"');
debug('Step=any');
shouldThrow('stepUp("2010-W02", "any", null)', invalidStateErr);
shouldThrow('stepDown("2010-W02", "any", null)', invalidStateErr);
debug('Overflow/underflow');
shouldThrow('stepUp("2010-W02", "3.40282346e+38", null)', invalidStateErr);
shouldThrow('stepDown("2010-W02", "3.40282346e+38", null)', invalidStateErr);
shouldThrow('stepUp("2010-W02", "1", "2010-W02")', invalidStateErr);
shouldThrow('stepDown("2010-W02", "1", "2010-W02")', invalidStateErr);

debug('');
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>