summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/time/time-validity-rangeoverflow.html
blob: 797f180fcbefd078ad8f9a41b7ea0b269b66d6a2 (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
72
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('This test aims to check for rangeOverflow flag with time input fields');

var input = document.createElement('input');

function checkOverflow(value, max, disabled)
{
    input.value = value;
    input.max = max;
    input.disabled = !!disabled;
    var overflow = input.validity.rangeOverflow;
    var resultText = 'The value "' + input.value + '" ' +
        (overflow ? 'overflows' : 'doesn\'t overflow') +
        ' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
    if (overflow)
        testPassed(resultText);
    else
        testFailed(resultText);
}

function checkNotOverflow(value, max, disabled, sanitized)
{
    input.value = value;
    input.max = max;
    input.disabled = !!disabled;
    var overflow = input.validity.rangeOverflow;
    var resultText = 'The value "' + input.value + '" ' +
        (sanitized ? 'sanitized from "' + value + '" ' : '') +
        (overflow ? 'overflows' : 'doesn\'t overflow') +
        ' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
    if (overflow)
        testFailed(resultText);
    else
        testPassed(resultText);
}

function checkSanitizedValueNotOverflow(value, max, disabled)
{
    // For date types, invalid values are sanitized to "".
    checkNotOverflow(value, max, disabled, true);
}

input.type = 'time';
input.min = '';
// No overflow cases
checkNotOverflow('13:16', null);
checkNotOverflow('13:16', '');
checkNotOverflow('13:16', 'foo');
checkNotOverflow('13:16', '13:16');
checkNotOverflow('13:16', '13:17');
checkNotOverflow('13:16', '14:15');
checkSanitizedValueNotOverflow('foo', '13:16');

// Overflow cases
checkOverflow('13:16', '13:15');
checkOverflow('23:59:59.999', '13:16');
input.min = '14:00';  // value < min && value > max
checkOverflow('13:16', '12:00');

// Disabled
checkNotOverflow('23:59:59.999', '13:16', true);
</script>
</body>
</html>