Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / widget / tests / test_mouse_event_with_control_on_mac.html
blob52ce206d35d786fad61a3d24778ce9931710c411
1 <html>
2 <head>
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">
10 <style>
11 #target {
12 width: 100px;
13 height: 100px;
14 background-color: lightgreen;
16 </style>
17 </head>
18 <body>
19 <div id="target"></div>
20 <script type="application/javascript">
22 function waitAndCheckMouseEvents(aTarget, aExpectedEvents) {
23 return new Promise((aResolve, aReject) => {
24 let timer;
25 let cleanup = function() {
26 if (timer) {
27 clearTimeout(timer);
28 timer = null;
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();
40 if (!expectedEvent) {
41 cleanup();
42 ok(false, `receive unexpected ${aEvent.type} event`);
43 aReject(new Error(`receive unexpected ${aEvent.type} event`));
44 return;
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() {
52 cleanup();
53 aResolve();
54 }, 0);
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);
63 });
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`);
73 });
74 });
76 add_task(async function TestMouseClickWithControl() {
77 await SpecialPowers.pushPrefEnv({
78 set: [["dom.event.treat_ctrl_click_as_right_click.disabled", true]],
79 });
81 let target = document.getElementById("target");
82 let promise = waitAndCheckMouseEvents(target, [["mousedown", 0, true],
83 ["contextmenu", 0, true],
84 ["mouseup", 0, true]]);
85 synthesizeNativeMouseEvent({
86 type: "click",
87 target,
88 offsetX: 10,
89 offsetY: 10,
90 modifiers: { ctrlKey: true },
91 });
92 await promise;
93 });
95 add_task(async function TestOldBehavior() {
96 await SpecialPowers.pushPrefEnv({
97 set: [["dom.event.treat_ctrl_click_as_right_click.disabled", false]],
98 });
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({
106 type: "click",
107 target,
108 offsetX: 10,
109 offsetY: 10,
110 modifiers: { ctrlKey: true },
112 await promise;
114 </script>
115 </body>
116 </html>