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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const PAGE_URL =
"https://example.com/browser/remote/cdp/test/browser/input/doc_events.html";
add_task(async function testPressedReleasedAndClick({ client }) {
const { Input } = client;
await loadURL(PAGE_URL);
await resetEvents();
info("Click the 'pointers' div.");
await Input.dispatchMouseEvent({
type: "mousePressed",
x: 80,
y: 180,
});
await Input.dispatchMouseEvent({
type: "mouseReleased",
x: 80,
y: 180,
});
const events = await getEvents();
["mousedown", "mouseup", "click"].forEach((type, index) => {
info(`Checking properties for event ${type}`);
checkProperties({ type, button: 0 }, events[index]);
});
});
add_task(async function testModifiers({ client }) {
const { Input } = client;
await loadURL(PAGE_URL);
const testable_modifiers = [
[alt],
[ctrl],
[meta],
[shift],
[alt, meta],
[ctrl, shift],
[alt, ctrl, meta, shift],
];
for (let modifiers of testable_modifiers) {
info(`MousePressed with modifier ${modifiers} on the 'pointers' div.`);
await resetEvents();
await Input.dispatchMouseEvent({
type: "mousePressed",
x: 80,
y: 180,
modifiers: modifiers.reduce((previous, current) => previous | current),
});
const events = await getEvents();
const expectedEvent = {
type: "mousedown",
button: 0,
altKey: modifiers.includes(alt),
ctrlKey: modifiers.includes(ctrl),
metaKey: modifiers.includes(meta),
shiftKey: modifiers.includes(shift),
};
checkProperties(expectedEvent, events[0]);
}
});
add_task(async function testClickCount({ client }) {
const { Input } = client;
await loadURL(PAGE_URL);
const testable_clickCounts = [
{ type: "click", clickCount: 1 },
{ type: "dblclick", clickCount: 2 },
];
for (const { clickCount, type } of testable_clickCounts) {
info(`MousePressed with clickCount ${clickCount} on the 'pointers' div.`);
await resetEvents();
await Input.dispatchMouseEvent({
type: "mousePressed",
x: 80,
y: 180,
clickCount,
});
await Input.dispatchMouseEvent({
type: "mouseReleased",
x: 80,
y: 180,
clickCount,
});
const events = await getEvents();
checkProperties({ type, button: 0 }, events[events.length - 1]);
}
});
add_task(async function testDispatchMouseEventAwaitClick({ client }) {
const { Input } = client;
await setupForInput(PAGE_URL);
await loadURL(
toDataURL(`
<div onclick="setTimeout(() => result = 'clicked', 0)">foo</div>
`)
);
const { x, y } = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => {
const div = content.document.querySelector("div");
return div.getBoundingClientRect();
}
);
await Input.dispatchMouseEvent({ type: "mousePressed", x, y });
await Input.dispatchMouseEvent({ type: "mouseReleased", x, y });
const context = await enableRuntime(client);
const { result } = await evaluate(
client,
context.id,
() => globalThis.result
);
is(result.value, "clicked", "Awaited click event handler");
});
|