<!DOCTYPE html>
<body>
<script src="../../../resources/js-test.js"></script>
<script>
function createWeekInput(min, max, value) {
var input = document.createElement('input');
input.type = 'week';
if (min)
input.min = min;
if (max)
input.max = max;
if (value)
input.value = value;
return input;
}
// FIXME: Rename this function and the test file.
function isReadOnlyField(input, pseudo) {
var node = internals.shadowRoot(input).querySelector('*[pseudo="' + pseudo + '"]');
if (!node)
testFailed('Requested node is missing.');
return node && node.hasAttribute('disabled');
}
var pseudoWeek = '-webkit-datetime-edit-week-field';
var pseudoYear = '-webkit-datetime-edit-year-field';
description('Sub-fields in input[type=week] should be read-only in some cases. This requires window.internals.');
debug('createWeekInput argument order: min, max, value');
debug('');
debug('Year field:');
shouldBeFalse('isReadOnlyField(createWeekInput("", "", ""), pseudoYear)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "", ""), pseudoYear)');
shouldBeFalse('isReadOnlyField(createWeekInput("", "2012-W50", ""), pseudoYear)');
shouldBeFalse('isReadOnlyField(createWeekInput("", "", "2012-W50"), pseudoYear)');
shouldBeTrue('isReadOnlyField(createWeekInput("2012-W01", "2012-W50", ""), pseudoYear)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W01", "2013-W50", ""), pseudoYear)');
shouldBeTrue('isReadOnlyField(createWeekInput("2012-W01", "2012-W50", "2012-W05"), pseudoYear)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W01", "2012-W50", "2013-W01"), pseudoYear)');
debug('Week field:');
debug('We should not make all the fields readonly by min/max, so week field is always editable.');
shouldBeFalse('isReadOnlyField(createWeekInput("", "", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("", "2012-W50", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("", "", "2012-W50"), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "2012-W50", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W49", "2013-W50", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "2013-W50", ""), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "2012-W50", "2012-W50"), pseudoWeek)');
shouldBeFalse('isReadOnlyField(createWeekInput("2012-W50", "2012-W50", "2012-W49"), pseudoWeek)');
</script>
</body>