test_click_hold_context_menus.html (2480B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=1891221 --> 4 <head> 5 <title>Test for Bug 1891221</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script src="/tests/SimpleTest/EventUtils.js"></script> 8 <script src="/tests/SimpleTest/SpecialPowers.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 <script type="application/javascript"> 11 "use strict"; 12 const kIsAndroid = navigator.userAgent.includes("Android"); 13 14 window.oncontextmenu = function (e) { 15 e.preventDefault(); 16 } 17 18 add_task(async function test_click_hold_context_menus_events_and_target() { 19 await SpecialPowers.pushPrefEnv({ 20 set: [ 21 ["ui.click_hold_context_menus", true], 22 ["ui.click_hold_context_menus.delay", 100], 23 ], 24 }); 25 await SimpleTest.promiseFocus(); 26 await SpecialPowers.contentTransformsReceived(window); 27 28 let seq = []; 29 30 const target = document.getElementById("target"); 31 32 target.addEventListener("mousedown", e => { 33 seq.push("mousedown"); 34 }); 35 36 // Fenix's contextMenu is not part of geckoview UI 37 // So mouseup event will be dispatched to content directly. 38 var upPromise; 39 if (kIsAndroid) { 40 upPromise = new Promise(resolve => { 41 target.addEventListener("mouseup", e => { 42 seq.push("mouseup"); 43 resolve(); 44 }); 45 }); 46 } 47 48 // This should never happen 49 target.addEventListener("click", e => { 50 ok(false, "click shouldn't be dispatched"); 51 seq.push("click"); 52 }); 53 54 const promise = new Promise(resolve => { 55 target.addEventListener("contextmenu", e => { 56 is(e.target, target, "Target should be the clickable element"); 57 is(e.explicitOriginalTarget, target.childNodes[0], "explicitOriginalTarget should be text node"); 58 seq.push("contextmenu"); 59 resolve(); 60 }); 61 }); 62 63 synthesizeMouse( 64 target, 65 10, 66 10, 67 { type: "mousedown", asyncEnabled: true }, 68 ); 69 70 // ensure contextmenu before mouseup. 71 await promise; 72 73 synthesizeMouse( 74 target, 75 10, 76 10, 77 { type: "mouseup", asyncEnabled: true }, 78 ); 79 80 if (kIsAndroid) { 81 await upPromise; 82 } 83 84 if (kIsAndroid) { 85 is(seq.toString(), ["mousedown", "contextmenu", "mouseup"].toString(), "Seq should match"); 86 } else { 87 is(seq.toString(), ["mousedown", "contextmenu"].toString(), "Seq should match"); 88 } 89 }); 90 </script> 91 </head> 92 <body> 93 <a id="target" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1891221">Mozilla Bug 1891221</a> 94 </body> 95 </html>