browser_bug706743.js (3966B)
1 add_task(async function () { 2 const url = 3 "data:text/html,<html><head></head><body>" + 4 '<a id="target" href="about:blank" title="This is tooltip text" ' + 5 'style="display:block;height:20px;margin:10px;" ' + 6 'onclick="return false;">here is an anchor element</a></body></html>'; 7 8 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 9 let browser = gBrowser.selectedBrowser; 10 11 await SpecialPowers.pushPrefEnv({ set: [["ui.tooltip.delay_ms", 0]] }); 12 13 // Send a mousemove at a known position to start the test. 14 await BrowserTestUtils.synthesizeMouse( 15 "#target", 16 -5, 17 -5, 18 { type: "mousemove" }, 19 browser 20 ); 21 22 // show tooltip by mousemove into target. 23 let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown"); 24 await BrowserTestUtils.synthesizeMouse( 25 "#target", 26 5, 27 15, 28 { type: "mousemove" }, 29 browser 30 ); 31 await popupShownPromise; 32 33 // hide tooltip by mousemove to outside. 34 let popupHiddenPromise = BrowserTestUtils.waitForEvent( 35 document, 36 "popuphidden" 37 ); 38 await BrowserTestUtils.synthesizeMouse( 39 "#target", 40 -5, 41 15, 42 { type: "mousemove" }, 43 browser 44 ); 45 await popupHiddenPromise; 46 47 // mousemove into the target and start drag by emulation via nsIDragService. 48 // Note that on some platforms, we cannot actually start the drag by 49 // synthesized events. E.g., Windows waits an actual mousemove event after 50 // dragstart. 51 52 // Emulate a buggy mousemove event. widget might dispatch mousemove event 53 // during drag. 54 55 function tooltipNotExpected() { 56 ok(false, "tooltip is shown during drag"); 57 } 58 addEventListener("popupshown", tooltipNotExpected, true); 59 60 let dragService = Cc["@mozilla.org/widget/dragservice;1"].getService( 61 Ci.nsIDragService 62 ); 63 dragService.startDragSessionForTests( 64 window, 65 Ci.nsIDragService.DRAGDROP_ACTION_MOVE | 66 Ci.nsIDragService.DRAGDROP_ACTION_COPY | 67 Ci.nsIDragService.DRAGDROP_ACTION_LINK 68 ); 69 try { 70 await BrowserTestUtils.synthesizeMouse( 71 "#target", 72 5, 73 15, 74 { type: "mousemove" }, 75 browser 76 ); 77 78 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 79 await new Promise(resolve => setTimeout(resolve, 100)); 80 } finally { 81 removeEventListener("popupshown", tooltipNotExpected, true); 82 dragService.getCurrentSession().endDragSession(true); 83 } 84 85 await BrowserTestUtils.synthesizeMouse( 86 "#target", 87 -5, 88 -5, 89 { type: "mousemove" }, 90 browser 91 ); 92 93 // If tooltip listener used a flag for managing D&D state, we would need 94 // to test if the tooltip is shown after drag. 95 96 // show tooltip by mousemove into target. 97 popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown"); 98 await BrowserTestUtils.synthesizeMouse( 99 "#target", 100 5, 101 15, 102 { type: "mousemove" }, 103 browser 104 ); 105 await popupShownPromise; 106 107 // hide tooltip by mousemove to outside. 108 popupHiddenPromise = BrowserTestUtils.waitForEvent(document, "popuphidden"); 109 await BrowserTestUtils.synthesizeMouse( 110 "#target", 111 -5, 112 15, 113 { type: "mousemove" }, 114 browser 115 ); 116 await popupHiddenPromise; 117 118 // Show tooltip after mousedown 119 popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown"); 120 await BrowserTestUtils.synthesizeMouse( 121 "#target", 122 5, 123 15, 124 { type: "mousemove" }, 125 browser 126 ); 127 await popupShownPromise; 128 129 popupHiddenPromise = BrowserTestUtils.waitForEvent(document, "popuphidden"); 130 await BrowserTestUtils.synthesizeMouse( 131 "#target", 132 5, 133 15, 134 { type: "mousedown" }, 135 browser 136 ); 137 await popupHiddenPromise; 138 139 await BrowserTestUtils.synthesizeMouse( 140 "#target", 141 5, 142 15, 143 { type: "mouseup" }, 144 browser 145 ); 146 await BrowserTestUtils.synthesizeMouse( 147 "#target", 148 -5, 149 15, 150 { type: "mousemove" }, 151 browser 152 ); 153 154 ok(true, "tooltips appear properly"); 155 156 gBrowser.removeCurrentTab(); 157 });