layout/xul/test/browser_bug706743.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/test/browser_bug706743.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,154 @@
     1.4 +function test() {
     1.5 +  waitForExplicitFinish();
     1.6 +  gBrowser.selectedTab = gBrowser.addTab();
     1.7 +
     1.8 +  SpecialPowers.setIntPref("ui.tooltipDelay", 0);
     1.9 +
    1.10 +  let target;
    1.11 +  let doc;
    1.12 +  let win;
    1.13 +  let callbackOnPopupShown;
    1.14 +  let callbackOnPopupHidden;
    1.15 +  let dragService = Components.classes["@mozilla.org/widget/dragservice;1"].
    1.16 +                      getService(Components.interfaces.nsIDragService);
    1.17 +
    1.18 +  let onPopupHidden = function (aEvent)
    1.19 +  {
    1.20 +    if (aEvent.originalTarget.localName != "tooltip") {
    1.21 +      return;
    1.22 +    }
    1.23 +    if (callbackOnPopupHidden) {
    1.24 +      setTimeout(callbackOnPopupHidden, 0);
    1.25 +    }
    1.26 +  }
    1.27 +
    1.28 +  let onPopupShown = function (aEvent)
    1.29 +  {
    1.30 +    if (aEvent.originalTarget.localName != "tooltip") {
    1.31 +      return;
    1.32 +    }
    1.33 +    if (callbackOnPopupShown) {
    1.34 +      setTimeout(callbackOnPopupShown, 0);
    1.35 +    }
    1.36 +  }
    1.37 +
    1.38 +  let finishTest = function ()
    1.39 +  {
    1.40 +    document.removeEventListener("popupshown", onPopupShown, true);
    1.41 +    document.removeEventListener("popuphidden", onPopupHidden, true);
    1.42 +
    1.43 +    SpecialPowers.clearUserPref("ui.tooltipDelay");
    1.44 +
    1.45 +    gBrowser.removeCurrentTab();
    1.46 +    finish();
    1.47 +  }
    1.48 +
    1.49 +  let testHideTooltipByMouseDown = function ()
    1.50 +  {
    1.51 +    callbackOnPopupShown = function () {
    1.52 +      callbackOnPopupShown = null;
    1.53 +      ok(true, "tooltip is shown before testing mousedown");
    1.54 +
    1.55 +      // hide tooltip by mousemove to outside.
    1.56 +      callbackOnPopupHidden = function () {
    1.57 +        callbackOnPopupHidden = null;
    1.58 +        ok(true, "The tooltip is hidden by mousedown");
    1.59 +
    1.60 +        EventUtils.synthesizeMouse(target, 5, 15, { type: "mouseup" }, win);
    1.61 +        EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win);
    1.62 +
    1.63 +        setTimeout(finishTest, 0);
    1.64 +      }
    1.65 +      EventUtils.synthesizeMouse(target, 5, 15, { type: "mousedown" }, win);
    1.66 +    }
    1.67 +    EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win);
    1.68 +  }
    1.69 +
    1.70 +  let testShowTooltipAgain = function ()
    1.71 +  {
    1.72 +    // If tooltip listener used a flag for managing D&D state, we would need
    1.73 +    // to test if the tooltip is shown after drag.
    1.74 +    callbackOnPopupShown = function () {
    1.75 +      callbackOnPopupShown = null;
    1.76 +      ok(true, "tooltip is shown after drag");
    1.77 +
    1.78 +      // hide tooltip by mousemove to outside.
    1.79 +      callbackOnPopupHidden = function () {
    1.80 +        callbackOnPopupHidden = null;
    1.81 +        ok(true, "The tooltip is hidden again");
    1.82 +
    1.83 +        setTimeout(testHideTooltipByMouseDown, 0);
    1.84 +      }
    1.85 +      EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win);
    1.86 +    }
    1.87 +    EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win);
    1.88 +  }
    1.89 +
    1.90 +  let testDuringDnD = function ()
    1.91 +  {
    1.92 +    // mousemove into the target and start drag by emulation via nsIDragService.
    1.93 +    // Note that on some platforms, we cannot actually start the drag by
    1.94 +    // synthesized events.  E.g., Windows waits an actual mousemove event after
    1.95 +    // dragstart.
    1.96 +    callbackOnPopupShown = function () {
    1.97 +      callbackOnPopupShown = null;
    1.98 +      ok(false, "tooltip is shown during drag");
    1.99 +    }
   1.100 +    dragService.startDragSession();
   1.101 +    // Emulate a buggy mousemove event.  widget might dispatch mousemove event
   1.102 +    // during drag.
   1.103 +    EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win);
   1.104 +    setTimeout(function () {
   1.105 +      callbackOnPopupShown = null;
   1.106 +      ok(true, "tooltip isn't shown during drag");
   1.107 +      dragService.endDragSession(true);
   1.108 +      EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win);
   1.109 +
   1.110 +      setTimeout(testShowTooltipAgain, 0);
   1.111 +    }, 100);
   1.112 +  }
   1.113 +
   1.114 +  let onLoad = function (aEvent)
   1.115 +  {
   1.116 +    doc = gBrowser.contentDocument;
   1.117 +    win = gBrowser.contentWindow;
   1.118 +    target = doc.getElementById("target");
   1.119 +
   1.120 +    document.addEventListener("popupshown", onPopupShown, true);
   1.121 +    document.addEventListener("popuphidden", onPopupHidden, true);
   1.122 +
   1.123 +    EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win);
   1.124 +
   1.125 +    // show tooltip by mousemove into target.
   1.126 +    callbackOnPopupShown = function ()
   1.127 +    {
   1.128 +      callbackOnPopupShown = null;
   1.129 +      ok(true, "The tooltip is shown");
   1.130 +
   1.131 +      // hide tooltip by mousemove to outside.
   1.132 +      callbackOnPopupHidden = function () {
   1.133 +        callbackOnPopupHidden = null;
   1.134 +        ok(true, "The tooltip is hidden");
   1.135 +
   1.136 +        setTimeout(testDuringDnD, 0);
   1.137 +      }
   1.138 +      EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win);
   1.139 +    }
   1.140 +    EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win);
   1.141 +  }
   1.142 +
   1.143 +  gBrowser.selectedBrowser.addEventListener("load",
   1.144 +    function () {
   1.145 +      gBrowser.selectedBrowser.
   1.146 +        removeEventListener("load", arguments.callee, true);
   1.147 +      setTimeout(onLoad, 0);
   1.148 +   }, true);
   1.149 +
   1.150 +  content.location = "data:text/html,<html><head></head><body>" +
   1.151 +    "<a id=\"target\" href=\"about:blank\" title=\"This is tooltip text\" " +
   1.152 +       "style=\"display:block;height:20px;margin:10px;\" " +
   1.153 +       "onclick=\"return false;\">here is an anchor element</a></body></html>";
   1.154 +}
   1.155 +
   1.156 +
   1.157 +

mercurial