<!DOCTYPE html>
<meta name=fuzzy content="maxDifference=0-3; totalPixels=0-1000">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/testdriver.js"></script>
<script src="../../../resources/testdriver-vendor.js"></script>
<script src="../resources/common.js"></script>
<script src="../resources/picker-common.js"></script>
<script src="../calendar-picker/resources/calendar-picker-common.js"></script>
<input type="week" id="week-0" value="2018-W23">
<script>
promise_test(() => {
let weekElement = document.getElementById('week-0');
return openPicker(weekElement)
.then(() => {
eventSender.keyDown('Home');
assert_equals(weekElement.value, "2018-W22", "Home hotkey should go to the first week of the month");
for (let week of [18, 13,9,5,1]) {
eventSender.keyDown('Home');
assert_equals(weekElement.value, "2018-W" + ("0" + week).substr(-2), "Home hotkey should go to the first week of the previous month");
}
eventSender.keyDown('Home');
assert_equals(weekElement.value, "2017-W48", "Home hotkey should wrap to the previous year");
eventSender.keyDown('End');
assert_equals(weekElement.value, "2017-W52", "End hotkey should go to the end week of the month");
eventSender.keyDown('End');
assert_equals(weekElement.value, "2018-W05", "End hotkey should go to the end week of the next month (wrapping to next year)");
eventSender.keyDown('Enter');
assert_equals(internals.pagePopupWindow, null, "Enter key should have closed popup.");
});
}, "Week picker: Home/end month hotkeys");
</script>