summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/event-timing/interactionid-aux-pointerdown-and-pointerdown.html
blob: a46ca6727790d5a87fa9fc4f4a65e827f38ef972 (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
<!DOCTYPE html>
<html>
<meta charset=utf-8 />
<title>Event Timing: interactionId-aux-pointerdown-and-pointerdown</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-actions.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=resources/event-timing-test-utils.js></script>
<div id='target'>Right click me to bring up OS level contextmenu popup.</div>

<script>
  let platformSupported = false;
  const map = new Map();
  const events = ['pointerdown'];

  // This test replicates a real world scenario that - on triggering contextmenu
  // with a pointer, pointerdown is captured but not pointerup. (crbug/1413096)
  // In this case, we need to make sure event timing will correctly report the
  // pointerdown entry with a valid/non-trivial interactionId.
  promise_test(async t => {
    assert_implements(window.PerformanceEventTiming, 'Event Timing is not supported.');
    // This test is not applicable to platforms like Windows where contextmenu
    // is triggered on aux pointerup. So we do a platform behavior test first to
    // distinguish and skip those platforms who do not dispatch contextmenu on
    // aux pointerdown.
    document.getElementById('target').addEventListener('contextmenu', () => { platformSupported = true; });
    await auxPointerdown(document.getElementById('target'));
    // 2000ms is a magic number picked to wait for contextmenu being observed
    // from the performance observer. Consider enlarge it if flaky.
    await t.step_timeout(() => { }, 2000);
    if (!platformSupported) {
      return;
    }

    // Perform test on qualified platforms
    const callback = (entryList) => { entryList.getEntries().filter(filterAndAddToMap(events, map)); };
    const readyToResolve = () => { return map.has('pointerdown'); };
    const observerPromise = createPerformanceObserverPromise(['event'], callback, readyToResolve);

    await interactAndObserve('aux-pointerdown-and-pointerdown', document.getElementById('target'), observerPromise);

    assert_greater_than(map.get('pointerdown'), 0, 'The pointerdown entry should have a non-trivial interactionId');
  }, "Event Timing: verify pointerdown reporting for mouse aux pointerdown only triggered contextmenu followed immediately by another pointerdown event.");

</script>

</html>