chromium/third_party/blink/web_tests/fast/forms/month/month-picker-escape-cancellation.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='../../../fast/forms/resources/picker-common.js'></script>

<input type='month' id='month0' value='2019-04'>
<script>
'use strict';

promise_test(() => {
  let monthElement = document.getElementById("month0");
  return openPicker(monthElement)
  .then(() => {
    eventSender.keyDown('Escape');
    assert_equals(internals.pagePopupWindow, null, "First escape should close popup if there were no changes.");
    assert_equals(monthElement.value, "2019-04", "Control should remain at original value.");
  });
}, "Month picker: Single escape should close popup if there were no modifications.");

promise_test(() => {
  let monthElement = document.getElementById("month0");
  return openPicker(monthElement)
  .then(() => {
    eventSender.keyDown('ArrowRight');
    eventSender.keyDown('ArrowDown');
    assert_equals(monthElement.value, "2019-09", "Using arrow keys to navigate month picker should update in-page control.");

    eventSender.keyDown('Escape');
    assert_not_equals(internals.pagePopupWindow, null, "First escape keypress should not close popup.");
    assert_equals(monthElement.value, "2019-04", "First escape keypress should reset control back to original value.");

    eventSender.keyDown('Escape');
    assert_equals(internals.pagePopupWindow, null, "Second escape keypress should close popup.");
    assert_equals(monthElement.value, "2019-04", "Control should remain at original value.");
  });
}, "Month picker: After modification, first escape should reset value and second escape should close picker.");

promise_test(() => {
  let monthElement = document.getElementById("month0");
  return openPicker(monthElement)
  .then(() => {
    eventSender.keyDown('ArrowRight');
    eventSender.keyDown('ArrowDown');
    assert_equals(monthElement.value, "2019-09", "Using arrow keys to navigate month picker should update in-page control.");

    eventSender.keyDown('ArrowUp');
    eventSender.keyDown('ArrowLeft');
    assert_equals(monthElement.value, "2019-04", "Expected to be back at the original value.");

    eventSender.keyDown('Escape');
    assert_equals(internals.pagePopupWindow, null, "Escape keypress should close popup.");
    assert_equals(monthElement.value, "2019-04", "Control should remain at original value.");
  });
}, "Month picker: After modification, single escape should close popup if it was changed back to the initial value.");

</script>