<!DOCTYPE html>
<body>
<script src="../../../resources/js-test.js"></script>
<script>
function createTimeInput(min, max, step, value) {
var input = document.createElement('input');
input.type = 'time';
input.min = min;
input.max = max;
input.step = step;
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 pseudoMillisecond = '-webkit-datetime-edit-millisecond-field';
var pseudoSecond = '-webkit-datetime-edit-second-field';
var pseudoMinute = '-webkit-datetime-edit-minute-field';
var pseudoHour = '-webkit-datetime-edit-hour-field';
var pseudoAMPM = '-webkit-datetime-edit-ampm-field';
var step1ms = '0.001';
var step1sec = '1';
var step1min = '60';
var step1hour = '3600';
var step1day = '86400';
description('Sub-fields in input[type=time] should be read-only in some cases. This requires window.internals.');
debug('createTimeInput argument order: min, max, step, value');
debug('');
debug('Milliseconds field:');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:00.500", null, step1sec, ""), pseudoMillisecond)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:00.500", null, step1sec, "00:00:00.500"), pseudoMillisecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00.500", null, step1sec, "00:00:00.600"), pseudoMillisecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00.000", null, step1sec, "00:00:00.600"), pseudoMillisecond)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:00.500", "00:00:00.500", step1ms, ""), pseudoMillisecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00.500", "00:00:00.501", step1ms, ""), pseudoMillisecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00.500", "00:00:00.500", step1ms, "00:00:00.100"), pseudoMillisecond)');
debug('Seconds field:');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:30", null, step1min, ""), pseudoSecond)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:30", null, step1min, "00:00:30"), pseudoSecond)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:30.500", null, step1min, "00:00:30.600"), pseudoSecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:30", null, step1min, "00:00:35"), pseudoSecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00", null, step1min, "00:00:35"), pseudoSecond)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:30", "00:00:30", step1ms, ""), pseudoSecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:30", "00:00:31", step1ms, ""), pseudoSecond)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:30", "00:00:30", step1ms, "00:00:29"), pseudoSecond)');
debug('Minutes field:');
shouldBeTrue('isReadOnlyField(createTimeInput("00:30", null, step1hour, ""), pseudoMinute)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:30", null, step1hour, "00:30"), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:30", null, step1hour, "00:35"), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", null, step1hour, "00:35"), pseudoMinute)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00:00", "00:00:30", step1sec, ""), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00", "00:01:30", step1sec, ""), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00:00", "00:00:30", step1sec, "00:01:00"), pseudoMinute)');
debug('Hour field:');
shouldBeFalse('isReadOnlyField(createTimeInput("11:00", null, step1day, ""), pseudoHour)');
shouldBeFalse('isReadOnlyField(createTimeInput("11:00", null, step1day, ""), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("11:00", null, step1day, ""), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("11:30", null, step1day, "11:30"), pseudoHour)');
shouldBeFalse('isReadOnlyField(createTimeInput("11:30", null, step1day, "11:30"), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("11:30", null, step1day, "11:30"), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("11:30", null, step1day, "12:30"), pseudoHour)');
shouldBeFalse('isReadOnlyField(createTimeInput("11:30", null, step1day, "12:30"), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("11:30", null, step1day, "12:30"), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", null, step1day, "12:30"), pseudoHour)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", null, step1day, "12:30"), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", null, step1day, "12:30"), pseudoMinute)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00", "00:30", step1min, ""), pseudoHour)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00", "00:30", step1min, ""), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", "00:30", step1min, ""), pseudoMinute)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", "00:00", step1hour, ""), pseudoHour)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00", "00:00", step1hour, ""), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00", "00:00", step1hour, ""), pseudoMinute)');
debug('AM/PM field:');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", null, step1min, ""), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput("23:00", null, step1min, ""), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput(null, "01:00", step1min, ""), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput(null, "23:00", step1min, ""), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("00:00", "11:59", step1min, ""), pseudoAMPM)');
shouldBeFalse('isReadOnlyField(createTimeInput("00:00", "12:00", step1min, ""), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("12:00", "12:00", step1min, ""), pseudoAMPM)');
shouldBeTrue('isReadOnlyField(createTimeInput("12:00", "23:59", step1min, ""), pseudoAMPM)');
</script>
</body>