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
|
<html>
<head>
<title>Test control+click on Mac</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/SpecialPowers.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<style>
#target {
width: 100px;
height: 100px;
background-color: lightgreen;
};
</style>
</head>
<body>
<div id="target"></div>
<script type="application/javascript">
function waitAndCheckMouseEvents(aTarget, aExpectedEvents) {
return new Promise((aResolve, aReject) => {
let timer;
let cleanup = function() {
if (timer) {
clearTimeout(timer);
timer = null;
}
aTarget.removeEventListener("mousedown", listener);
aTarget.removeEventListener("mouseup", listener);
aTarget.removeEventListener("contextmenu", listener);
aTarget.removeEventListener("click", listener);
aTarget.removeEventListener("auxclick", listener);
};
let listener = function(aEvent) {
aEvent.preventDefault();
let expectedEvent = aExpectedEvents.shift();
if (!expectedEvent) {
cleanup();
ok(false, `receive unexpected ${aEvent.type} event`);
aReject(new Error(`receive unexpected ${aEvent.type} event`));
return;
}
isDeeply([aEvent.type, aEvent.button, aEvent.ctrlKey], expectedEvent,
`check received ${aEvent.type} event`);
if (!aExpectedEvents.length) {
// Wait a bit to see if there is any unexpected event.
timer = setTimeout(function() {
cleanup();
aResolve();
}, 0);
}
};
aTarget.addEventListener("mousedown", listener);
aTarget.addEventListener("mouseup", listener);
aTarget.addEventListener("contextmenu", listener);
aTarget.addEventListener("click", listener);
aTarget.addEventListener("auxclick", listener);
});
}
add_task(async function Init() {
await SimpleTest.promiseFocus();
await waitUntilApzStable();
let target = document.getElementById("target");
target.addEventListener("click", function() {
ok(false, `should not receive click event`);
});
});
add_task(async function TestMouseClickWithControl() {
await SpecialPowers.pushPrefEnv({
set: [["dom.event.treat_ctrl_click_as_right_click.disabled", true]],
});
let target = document.getElementById("target");
let promise = waitAndCheckMouseEvents(target, [["mousedown", 0, true],
["contextmenu", 0, true],
["mouseup", 0, true]]);
synthesizeNativeMouseEvent({
type: "click",
target,
offsetX: 10,
offsetY: 10,
modifiers: { ctrlKey: true },
});
await promise;
});
add_task(async function TestOldBehavior() {
await SpecialPowers.pushPrefEnv({
set: [["dom.event.treat_ctrl_click_as_right_click.disabled", false]],
});
let target = document.getElementById("target");
let promise = waitAndCheckMouseEvents(target, [["mousedown", 2, true],
["contextmenu", 2, true],
["mouseup", 2, true],
["auxclick", 2, true]]);
synthesizeNativeMouseEvent({
type: "click",
target,
offsetX: 10,
offsetY: 10,
modifiers: { ctrlKey: true },
});
await promise;
});
</script>
</body>
</html>
|