summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/selection/onselectionchange-on-distinct-text-controls.html
blob: ee26928699c78e2f822e39a9ff6601bc8c92163c (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
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="help" href="https://w3c.github.io/selection-api/#selectionchange-event">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<input id="input1" value="hello">
<input id="input2" value="world">
<textarea id="textarea1">hello</textarea>
<textarea id="textarea2">world</textarea>
<script>

promise_test(() => {
  return (async function() {
    let selectionChangeCount1 = 0;
    let selectionChangeCount2 = 0;
    input1.addEventListener("selectionchange", () => ++selectionChangeCount1);
    input2.addEventListener("selectionchange", () => ++selectionChangeCount2);
    input1.setSelectionRange(1, 2);
    input1.setSelectionRange(2, 3);
    input2.setSelectionRange(1, 3);
    assert_equals(selectionChangeCount1, 0);
    assert_equals(selectionChangeCount2, 0);
    await new Promise(setTimeout);
    assert_equals(selectionChangeCount1, 1);
    assert_equals(selectionChangeCount2, 1);
  })();
}, "selectionchange event on each input element fires independently");

promise_test(() => {
  return (async function() {
    let selectionChangeCount1 = 0;
    let selectionChangeCount2 = 0;
    textarea1.addEventListener("selectionchange", () => ++selectionChangeCount1);
    textarea2.addEventListener("selectionchange", () => ++selectionChangeCount2);
    textarea1.setSelectionRange(1, 2);
    textarea1.setSelectionRange(2, 3);
    textarea2.setSelectionRange(1, 3);
    assert_equals(selectionChangeCount1, 0);
    assert_equals(selectionChangeCount2, 0);
    await new Promise(setTimeout);
    assert_equals(selectionChangeCount1, 1);
    assert_equals(selectionChangeCount2, 1);
  })();
}, "selectionchange event on each textarea element fires independently");

</script>