chromium/third_party/blink/web_tests/fast/forms/week/ValidityState-rangeUnderflow-week.html

<!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 week 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 = 'week';
input.max = '';
// No underflow cases
checkNotUnderflow('2010-W01', null);
checkNotUnderflow('2010-W01', '');
checkNotUnderflow('2010-W01', 'foo');
// 1000-W01 is smaller than the implicit minimum value.
// But the month parser rejects it before comparing the minimum value.
checkNotUnderflow('1000-W01', '');
checkNotUnderflow('1583-W01', '');
checkNotUnderflow('2010-W01', '2009-W51');
checkNotUnderflow('2010-W01', '2009-W01');
checkSanitizedValueNotUnderflow('foo', '2011-W01');

// Underflow cases
checkUnderflow('2010-W01', '2010-W02');
checkUnderflow('9999-W01', '10000-W12');
input.max = '2009-W52';  // value < min && value > max
checkUnderflow('2010-W01', '2010-W02');

// Disabled
checkUnderflow('9999-W01', '10000-W12', true);
</script>
</body>
</html>