summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/date/ValidityState-rangeUnderflow-date.html
blob: 74e9b2b88b624102c88a634d562ab700a4d7d972 (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
73
74
75
<!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 rangeUnderflow flag with date input fields');

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

function checkUnderflow(value, min, disabled)
{
    input.value = value;
    input.min = min;
    input.disabled = !!disabled;
    var underflow = input.validity.rangeUnderflow;
    var resultText = 'The value "' + input.value + '" ' +
        (underflow ? 'undeflows' : 'doesn\'t underflow') +
        ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
    if (underflow)
        testPassed(resultText);
    else
        testFailed(resultText);
}

function checkNotUnderflow(value, min, disabled, sanitized)
{
    input.value = value;
    input.min = min;
    input.disabled = !!disabled;
    var underflow = input.validity.rangeUnderflow;
    var resultText = 'The value "' + input.value + '" ' +
        (sanitized ? 'sanitized from "' + value + '" ' : '') +
        (underflow ? 'underflows' : 'doesn\'t underflow') +
        ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
    if (underflow)
        testFailed(resultText);
    else
        testPassed(resultText);
}

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

input.type = 'date';
input.max = '';
// No underflow cases
checkNotUnderflow('2010-01-27', null);
checkNotUnderflow('2010-01-27', '');
checkNotUnderflow('2010-01-27', 'foo');
// 1000-01-01 is smaller than the implicit minimum value.
// But the date parser rejects it before comparing the minimum value.
checkNotUnderflow('1000-01-01', '');
checkNotUnderflow('1582-10-15', '');
checkNotUnderflow('2010-01-27', '2010-01-26');
checkNotUnderflow('2010-01-27', '2009-01-28');
checkSanitizedValueNotUnderflow('foo', '2011-01-26');

// Underflow cases
checkUnderflow('2010-01-27', '2010-01-28');
checkUnderflow('9999-01-01', '10000-12-31');
input.max = '2010-01-01';  // value < min && value > max
checkUnderflow('2010-01-27', '2010-02-01');

// Disabled
checkNotUnderflow('9999-01-01', '10000-12-31', true);
</script>
</body>
</html>