summaryrefslogtreecommitdiffstats
path: root/dom/events/test/pointerevents/test_pointermove_drag_scrollbar.html
blob: 27ef2829ef1919a78e8ebef0997d7372e6d5c785 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1509710
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1509710</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
#scroll {
  width: 200px;
  height: 200px;
  overflow: scroll;
}
#scrolled {
  width: 200px;
  height: 1000px; /* so the subframe has room to scroll */
  will-change: transform; /* to force active layers */
}
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1509710">Mozilla Bug 1509710</a>
<p id="display"></p>
<div id="scroll">
<div id="scrolled"></div>
</div>
<script type="text/javascript">

/** Test for Bug 1509710 **/
add_task(async function test_pointer_mouse_event() {
  await SimpleTest.promiseFocus();

  let subframe = document.getElementById("scroll");
  if (subframe.clientWidth == 200) {
    // No scrollbar, abort the test. This can happen e.g. on local macOS runs
    // with OS settings to only show scrollbars on trackpad/mouse activity.
    ok(false, "No scrollbars found, cannot run this test!");
    return;
  }

  let receivedEvent = {};
  let handler = function(e) {
    receivedEvent[e.type] = true;
  };
  subframe.addEventListener("pointerdown", handler);
  subframe.addEventListener("pointermove", handler);
  subframe.addEventListener("pointerup", handler);
  subframe.addEventListener("mousedown", handler);
  subframe.addEventListener("mousemove", handler);
  subframe.addEventListener("mouseup", handler);

  // synthesize mouse actions on scrollbar.
  let scrollbarX = (200 + subframe.clientWidth) / 2;
  synthesizeMouse(subframe, scrollbarX, 30, { type: "mousedown" });
  synthesizeMouse(subframe, scrollbarX, 40, { type: "mousemove" });
  synthesizeMouse(subframe, scrollbarX, 40, { type: "mouseup" });

  await new Promise(SimpleTest.executeSoon);

  // Test pointer event
  ok(receivedEvent.pointerdown, "should receive pointerdown event");
  ok(!receivedEvent.pointermove, "should not receive pointermove event");
  ok(receivedEvent.pointerup, "should receive pointerup event");

  // Test mouse event
  ok(receivedEvent.mousedown, "should receive mousedown event");
  ok(!receivedEvent.mousemove, "should not receive mousemove event");
  ok(receivedEvent.mouseup, "should receive mouseup event");
});

</script>
</body>
</html>