chromium/third_party/blink/web_tests/fast/forms/calendar-picker/date-picker-month-switcher-buttons.html

<!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="date" id="date-0" value="2019-06-10">
<input type="date" id="date-1" value="2019-09-20">
<input type="date" id="date-2" value="2019-01-31">
<input type="date" id="date-3" value="2019-10-31">
<script>

promise_test(() => {
  let dateElement = document.getElementById('date-0');
  return openPicker(dateElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickNextMonthButton();
    assert_equals(dateElement.value, "2019-07-10", "Month chooser button should have changed month");

    clickDayCellAt(2, 3);
    assert_equals(dateElement.value, "2019-07-23", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Clicking date should have dismissed popup");
  });
}, "Date picker: Next month button should advance to next month and change selection to same day in that month when doing so.");

promise_test(() => {
  let dateElement = document.getElementById('date-1');
  return openPicker(dateElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickPrevMonthButton();
    assert_equals(dateElement.value, "2019-08-20", "Selection should have been clipped when moving into shorter month");

    clickDayCellAt(3, 4);
    assert_equals(dateElement.value, "2019-08-28", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Clicking date should have dismissed popup");
  });
}, "Date picker: Prev month button should advance to previous month and change selection to same day in that month when doing so.");

promise_test(() => {
  let dateElement = document.getElementById('date-2');
  return openPicker(dateElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickNextMonthButton();
    assert_equals(dateElement.value, "2019-02-28", "Selection should have been clipped when moving into shorter month");

    clickDayCellAt(3, 3);
    assert_equals(dateElement.value, "2019-02-20", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Clicking date should have dismissed popup");
  });
}, "Date picker: Next month button should clip date if next month has fewer days");

promise_test(() => {
  let dateElement = document.getElementById('date-3');
  return openPicker(dateElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickPrevMonthButton();
    assert_equals(dateElement.value, "2019-09-30", "Selection should have been clipped when moving into shorter month");

    clickDayCellAt(3, 3);
    assert_equals(dateElement.value, "2019-09-25", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Clicking date should have dismissed popup");
  });
}, "Date picker: Previous month button should clip date if prev month has fewer days");

</script>