summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-input-element/range-restore-oninput-onchange-event.https.html
blob: f73c5e6f635f870286d75838f0a6df30a20a8d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!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>