3 <title>Test control+click on Mac
</title>
4 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"/tests/SimpleTest/SpecialPowers.js"></script>
7 <script src=
"/tests/SimpleTest/paint_listener.js"></script>
8 <script src=
"/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css">
14 background-color: lightgreen;
19 <div id=
"target"></div>
20 <script type=
"application/javascript">
22 function waitAndCheckMouseEvents(aTarget, aExpectedEvents) {
23 return new Promise((aResolve, aReject) =
> {
25 let cleanup = function() {
30 aTarget.removeEventListener(
"mousedown", listener);
31 aTarget.removeEventListener(
"mouseup", listener);
32 aTarget.removeEventListener(
"contextmenu", listener);
33 aTarget.removeEventListener(
"click", listener);
34 aTarget.removeEventListener(
"auxclick", listener);
37 let listener = function(aEvent) {
38 aEvent.preventDefault();
39 let expectedEvent = aExpectedEvents.shift();
42 ok(false, `receive unexpected ${aEvent.type} event`);
43 aReject(new Error(`receive unexpected ${aEvent.type} event`));
47 isDeeply([aEvent.type, aEvent.button, aEvent.ctrlKey], expectedEvent,
48 `check received ${aEvent.type} event`);
49 if (!aExpectedEvents.length) {
50 // Wait a bit to see if there is any unexpected event.
51 timer = setTimeout(function() {
58 aTarget.addEventListener(
"mousedown", listener);
59 aTarget.addEventListener(
"mouseup", listener);
60 aTarget.addEventListener(
"contextmenu", listener);
61 aTarget.addEventListener(
"click", listener);
62 aTarget.addEventListener(
"auxclick", listener);
66 add_task(async function Init() {
67 await SimpleTest.promiseFocus();
68 await waitUntilApzStable();
70 let target = document.getElementById(
"target");
71 target.addEventListener(
"click", function() {
72 ok(false, `should not receive click event`);
76 add_task(async function TestMouseClickWithControl() {
77 await SpecialPowers.pushPrefEnv({
78 set: [[
"dom.event.treat_ctrl_click_as_right_click.disabled", true]],
81 let target = document.getElementById(
"target");
82 let promise = waitAndCheckMouseEvents(target, [[
"mousedown",
0, true],
83 [
"contextmenu",
0, true],
84 [
"mouseup",
0, true]]);
85 synthesizeNativeMouseEvent({
90 modifiers: { ctrlKey: true },
95 add_task(async function TestOldBehavior() {
96 await SpecialPowers.pushPrefEnv({
97 set: [[
"dom.event.treat_ctrl_click_as_right_click.disabled", false]],
100 let target = document.getElementById(
"target");
101 let promise = waitAndCheckMouseEvents(target, [[
"mousedown",
2, true],
102 [
"contextmenu",
2, true],
103 [
"mouseup",
2, true],
104 [
"auxclick",
2, true]]);
105 synthesizeNativeMouseEvent({
110 modifiers: { ctrlKey: true },