<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('This test aims to check for typeMismatch flag with type=month input fields');
var i = document.createElement('input');
i.type = 'month';

function check(value, disabled)
{
    i.value = value;
    i.disabled = !!disabled;

    if (i.validity.typeMismatch)
        testFailed('"' + value + '" had typeMismatch. This should not happen with sanitization.');
}

function shouldBeValid(value)
{
    check(value);
    if ((value === '' && i.value === '') || (value !== '' && i.value !== ""))
        testPassed('"' + value + '" is a correct valid month string.');
    else
        testFailed('"' + value + '" is a valid month string that failed to be set on the input.');
}

function shouldBeInvalid(value, disabled)
{
    check(value, disabled);
    if (i.value === '')
        testPassed('"' + value + '" is an invalid month string and was sanitized' + (disabled ? ' while disabled' : '') + '.');
    else
        testFailed('"' + value + '" is an invalid month string and was not sanitized' + (disabled ? ' while disabled' : '') + '.');
}

// Valid values
shouldBeValid('');
shouldBeValid('0001-01');
shouldBeValid('9999-12');
shouldBeValid('275760-09');
shouldBeValid('2009-01');
shouldBeValid('2009-02');
shouldBeValid('2009-03');
shouldBeValid('2009-04');
shouldBeValid('2009-05');
shouldBeValid('2009-06');
shouldBeValid('2009-07');
shouldBeValid('2009-08');
shouldBeValid('2009-09');
shouldBeValid('2009-10');
shouldBeValid('2009-11');
shouldBeValid('2009-12');

// Invalid values
shouldBeInvalid(' 2009-09 ');
shouldBeInvalid('a');
shouldBeInvalid('-1-09');
shouldBeInvalid('0000-12');
shouldBeInvalid('2147483648-12');
shouldBeInvalid('275760-10');
shouldBeInvalid('2009/09');
shouldBeInvalid('200909');
shouldBeInvalid('2009--2');
shouldBeInvalid('2009-00');
shouldBeInvalid('2009-13');
shouldBeInvalid('2009-');
shouldBeInvalid('2009-9');
shouldBeInvalid('2009-009');
shouldBeInvalid('2009-xx');
shouldBeInvalid('2009');

// Disabled
shouldBeInvalid('invalid', true);
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
