blob: 1b5022f878c7414546f9bbf4e241ff8ec3fb9f94 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../../resources/js-test-pre.js"></script>
<script src="../../../../resources/ui-helper.js"></script>
</head>
<body>
<input id="emptyInput" type="datetime-local" value=""/>
<input id="emptyInputWithSecondStep" type="datetime-local" value="" step="2"/>
<input id="emptyInputWithMillisecondStep" type="datetime-local" value="" step="0.5"/>
<input id="inputWithSecondsValue" type="datetime-local" value="2021-02-03T10:30:40"/>
<input id="inputWithMillisecondsValue" type="datetime-local" value="2021-02-03T10:30:00.100"/>
<script>
jsTestIsAsync = true;
function hasSeconds(value) {
time = value.slice(value.lastIndexOf('T') + 1);
return time.length > 5;
}
function hasMilliseconds(value) {
time = value.slice(value.lastIndexOf('T') + 1);
return time.length > 8;
}
async function activateElementAndChooseDateUsingPicker(input) {
await UIHelper.activateElementAndWaitForInputSession(input);
await UIHelper.isShowingDateTimePicker();
await UIHelper.chooseDateTimePickerValue();
}
function expectNoSecondsOrMilliseconds(value) {
valueHasSeconds = hasSeconds(value);
shouldBeFalse("valueHasSeconds");
valueHasMillseconds = hasMilliseconds(value);
shouldBeFalse("valueHasMillseconds");
}
function expectSeconds(value) {
valueHasSeconds = hasSeconds(value);
shouldBeTrue("valueHasSeconds");
valueHasMillseconds = hasMilliseconds(value);
shouldBeFalse("valueHasMillseconds");
}
function expectMilliseconds(value) {
valueHasSeconds = hasSeconds(value);
shouldBeTrue("valueHasSeconds");
valueHasMillseconds = hasMilliseconds(value);
shouldBeTrue("valueHasMillseconds");
}
addEventListener("load", async () => {
description("Tests that choosing a value using the date/time picker does not unexpectedly add or remove second and millisecond fields.");
debug("Testing empty input with no step value.");
await activateElementAndChooseDateUsingPicker(emptyInput);
expectNoSecondsOrMilliseconds(emptyInput.value);
await UIHelper.deactivateFormControl(emptyInput);
await UIHelper.ensurePresentationUpdate();
debug("");
debug("Testing empty input with step attribute precise to seconds.");
await activateElementAndChooseDateUsingPicker(emptyInputWithSecondStep);
expectSeconds(emptyInputWithSecondStep.value);
await UIHelper.deactivateFormControl(emptyInputWithSecondStep);
await UIHelper.ensurePresentationUpdate();
debug("");
debug("Testing empty input with step attribute precise to milliseconds.");
await activateElementAndChooseDateUsingPicker(emptyInputWithMillisecondStep);
expectMilliseconds(emptyInputWithMillisecondStep.value);
await UIHelper.deactivateFormControl(emptyInputWithMillisecondStep);
await UIHelper.ensurePresentationUpdate();
debug("");
debug("Testing input with a value that contains seconds.");
await activateElementAndChooseDateUsingPicker(inputWithSecondsValue);
expectSeconds(inputWithSecondsValue.value);
await UIHelper.deactivateFormControl(inputWithSecondsValue);
await UIHelper.ensurePresentationUpdate();
debug("");
debug("Testing input with a value that contains milliseconds.");
await activateElementAndChooseDateUsingPicker(inputWithMillisecondsValue);
expectMilliseconds(inputWithMillisecondsValue.value);
await UIHelper.deactivateFormControl(inputWithMillisecondsValue);
await UIHelper.ensurePresentationUpdate();
debug("");
finishJSTest();
});
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>