DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d38398e5144e)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=486990
-->
<window title="Mozilla Bug 486990"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="setTimeout(runTests, 0);">
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"/>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=486990"
     target="_blank">Mozilla Bug 486990</a>

  </body>
  <div xmlns="http://www.w3.org/1999/xhtml">
  <select size="5" id="select">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
  </select>
  </div>
  <menupopup id="cm" onpopupshowing="popupShowing(event);">
    <menuitem label="Mozilla" value="http://mozilla.org"/>
    <menuitem label="Slashdot" value="http://slashdot.org"/>
    <menuitem label="Sourceforge" value="http://sf.net"/>
    <menuitem label="Freshmeat" value="http://freshmeat.net"/>
  </menupopup>
  <button label="test button" contextmenu="cm" id="testbutton"/>
  
  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[

  /** Test for Bug 486990 **/

  SimpleTest.waitForExplicitFinish();

  var prevented = false;
  var eventCount = 0;

  function fooListener(evt) {
    evt.preventDefault();
    prevented = evt.defaultPrevented;
    ++eventCount;
  };

  var clickCount = 0;
  var mouseDownCount = 0;
  var mouseUpCount = 0;
  function clickListener(evt) {
    ++clickCount;
  }

  function mouseDownListener(evt) {
    ++mouseDownCount;
  }

  function mouseUpListener(evt) {
    ++mouseUpCount;
  }

  var popupshowingcount = 0;

  function popupShowing(evt) {
    ++popupshowingcount;
    evt.preventDefault();
  }

  function contextMenuStopper(evt) {
    evt.stopPropagation();
  }

  function contextMenuPreventer(evt) {
    evt.preventDefault();
  }

  var tb;
  function runTests() {
    document.addEventListener("foo", fooListener, true);
    var e1 = document.createEvent("Event");
    e1.initEvent("foo", true, true);
    document.dispatchEvent(e1);
    is(eventCount, 1, "Wrong event count");
    ok(prevented, "Default handling should have been prevented.");

    prevented = false;
    var e2 = document.createEvent("Event");
    e2.initEvent("foo", false, false);
    document.dispatchEvent(e1);
    is(eventCount, 2, "Wrong event count");
    ok(prevented, "Default handling should have been prevented.");

    tb = document.getElementById("testbutton");
    dispatchTrustedContextMenuEvent(tb);
    is(popupshowingcount, 1, "Should have got 'popupShowing' event!");

    tb.addEventListener("contextmenu", contextMenuStopper, true);
    dispatchTrustedContextMenuEvent(tb);
    is(popupshowingcount, 2, "Should have got 'popupShowing' event!");

    tb.addEventListener("contextmenu", contextMenuPreventer, true);
    dispatchTrustedContextMenuEvent(tb);
    is(popupshowingcount, 2, "Should not have got 'popupShowing' event!");

    SpecialPowers.pushPrefEnv({"set": [["dom.event.contextmenu.enabled", false]]}, test2);
  }

  function test2() {
    dispatchTrustedContextMenuEvent(tb);
    is(popupshowingcount, 3, "Should have got 'popupShowing' event!");

    SpecialPowers.pushPrefEnv({"set": [["dom.event.contextmenu.enabled", true]]}, test3);
  }

  function test3() {
    dispatchTrustedContextMenuEvent(tb);
    is(popupshowingcount, 3, "Should not have got 'popupshowing' event!");

    var s = document.getElementById("select");
    s.addEventListener("click", clickListener, true);
    s.addEventListener("mousedown", mouseDownListener, true);
    s.addEventListener("mouseup", mouseUpListener, true);

    synthesizeMouse(s, 1, 10, {}, window);
    is(clickCount, 1, "Should have got click event!");
    is(mouseDownCount, 1, "Should have got mousedown event!");
    is(mouseUpCount, 1, "Should have got mouseup event!");

    // Dispatch to scrollbar.
    synthesizeMouse(s, s.getBoundingClientRect().right - 3, 10, {}, window);
    is(clickCount, 1, "Should not have got click event!");
    is(mouseDownCount, 2, "Should have got mousedown event!");
    is(mouseUpCount, 2, "Should have got mouseup event!");

    SimpleTest.finish();
  }

  function dispatchTrustedContextMenuEvent(target) {
    return sendMouseEvent({type:"contextmenu"}, target, window);
  }

  ]]>
  </script>
</window>