testing/web-platform/tests/html/semantics/forms/the-input-element/range-restore-oninput-onchange-event.https.html
author Florian Quèze <florian@queze.net>
Tue, 08 Jul 2025 20:48:53 +0000 (7 hours ago)
changeset 795809 b01190f141a12f4b506acb1f4476561c4b0f2407
parent 634114 4190cb92639ceddd3cd038b5e4cdf6edb01e4de6
permissions -rw-r--r--
Bug 1960567 - remove the last C++ and scriptable APIs to accumulate data to legacy telemetry histograms, r=chutten. Differential Revision: https://phabricator.services.mozilla.com/D255582
<!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>