File: test_mouse_double_click_on_android.html

package info (click to toggle)
firefox 146.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,260 kB
  • sloc: cpp: 7,587,892; javascript: 6,509,455; ansic: 3,755,295; python: 1,410,813; xml: 629,201; asm: 438,677; java: 186,096; sh: 62,697; makefile: 18,086; objc: 13,087; perl: 12,811; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (159 lines) | stat: -rw-r--r-- 3,578 bytes parent folder | download | duplicates (13)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1837119
-->
<html>
<head>
<meta charset="utf-8" />
<title>Test to fire dblclick event by Android's widget level</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<style>
#target {
  width: 100px;
  height: 100px;
  background-color: blue;
  user-select: none;
}
</style>
<script>
"use strict";
// If this test runs repeatedly, we have to reset internal double click state
// to detect double click correctly.
function resetMouseState() {
  const target = document.getElementById("target");
  const promise =
    new Promise(resolve => target.addEventListener("click", resolve, { once: true }));

  synthesizeNativeMouseEvent({
    type: "mousedown",
    target,
    offsetX: 30,
    offsetY: 10,
  });

  synthesizeNativeMouseEvent({
    type: "mouseup",
    target,
    offsetX: 30,
    offsetY: 10,
  });

  return promise;
}

add_task(async function test_fire_dblclick() {
  // Don't use min time for double click to reduce execution time.
  // Also, we cannot make a min time on parent process since
  // synthesizeNativeMouseEvent is called on child process.
  await SpecialPowers.pushPrefEnv({
    set: [["widget.double-click.min", -1]],
  });

  await SimpleTest.promiseFocus();
  await resetMouseState();

  const target = document.getElementById("target");
  let click = 0;
  target.addEventListener("click", () => {
    info("click event is received");
    click++;
  });

  const promise = new Promise(resolve => {
    target.addEventListener("dblclick", e => {
      resolve();
      e.preventDefault();
    }, { once: true });
  });

  for (let i = 0; i < 2; i++) {
    synthesizeNativeMouseEvent({
      type: "mousedown",
      target,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });

    synthesizeNativeMouseEvent({
      type: "mouseup",
      target,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });
  }

  await promise;

  is(click, 2, "Click event is twice");

  await SpecialPowers.popPrefEnv();
});

add_task(async function test_fire_no_dblclick() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["widget.double-click.min", 500],
      ["widget.double-click.timeout", 1000],
    ],
  });

  await SimpleTest.promiseFocus();
  await resetMouseState();

  let click = 0;
  let dblclick = 0;

  const target = document.getElementById("target");
  const promise = new Promise(resolve => {
    target.addEventListener("click", () => {
      info("click event is received");
      click++;
      if (click == 2) {
        resolve();
      }
    });
  })
  target.addEventListener("dblclick", () => {
    info("dblclick event is received");
    dblclick++
  });

  // no delay means that dblclick isn't fired.
  for (let i = 0; i < 2; i++) {
    synthesizeNativeMouseEvent({
      type: "mousedown",
      target,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });

    synthesizeNativeMouseEvent({
      type: "mouseup",
      target,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });
  }

  await promise;

  // This test is that dblclick isn't fired when each click is no delayed.
  // So we need to spin event loop to check whether dblclick is fired.
  await new Promise(resolve => window.requestAnimationFrame(resolve));

  is(click, 2, "Click event is twice");
  is(dblclick, 0, "No double click event is fired");
});

</script>
</head>
<body>
<div id="target"></div>
</body>
</html>