<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/whatwg/html/pull/7283">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1266468">

<link rel=author href="mailto:gulukesh@gmail.com">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1131234">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
function runTest(type, testValue) {
  promise_test(async () => {
    const w = window.open(`resources/${type}-restore-events.html`);
    // Unfortunately, navigating |w| doesn't fire load events in this parent
    // window, so we have to make the child window manually tell this parent
    // window when it has loaded.
    await new Promise(resolve => window.loadResolver = resolve);
    // We can't navigate the child window until after a setTimeout.
    await new Promise(resolve => step_timeout(resolve, 0));

    assert_not_equals(
      w.document.querySelector('input').value,
      testValue,
      `Test shouldn't start with the new value already in the input.`);
    w.document.querySelector('input').value = testValue;

    w.location.href = 'resources/loadresolver.html';
    await new Promise(resolve => window.loadResolver = resolve);

    w.history.back();
    await new Promise(resolve => window.loadResolver = resolve);
    // The value doesn't get restored until after a setTimeout.
    await new Promise(resolve => step_timeout(resolve, 0));

    assert_equals(w.document.querySelector('input').value, testValue,
      'The input should have its value restored.');

    assert_false(w.seeninput || false,
      'The input event should not have been fired after restoration.');
    assert_false(w.seenchange || false,
      'The change event should not have been fired after restoration.');

    w.close();
  }, `Verifies that form restoration does not fire input or change events for <input type=${type}>.`);
}

runTest('range', '8');
runTest('text', 'foo');
</script>
