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.

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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test click event on input</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display">
<input id="input"
  style="position: absolute; top: 5px; left: 5px; border: solid 15px blue; width: 100px; height: 20px;"
  onclick="gClickCount++;">
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

var gClickCount = 0;

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests);

var input = document.getElementById("input");

function runTests()
{
  for (var i = 0; i < 3; i++) {
    doTest(i);
  }

  // Re-test left clicking when the input element has some text. 
  gClickCount = 0;
  input.value = "Long text Long text Long text Long text Long text Long text";
  doTest(0);

  input.style.display = "none";
  SimpleTest.finish();
}

function isEnabledMiddleClickPaste()
{
  try {
    return SpecialPowers.getBoolPref("middlemouse.paste");
  } catch (e) {
    return false;
  }
}

function isEnabledAccessibleCaret()
{
  try {
    return SpecialPowers.getBoolPref("layout.accessiblecaret.enabled");
  } catch (e) {
    return false;
  }
}

function doTest(aButton)
{
  // NOTE #1: Right click causes a context menu to popup, then, the click event
  //          isn't generated.
  // NOTE #2: If middle click causes text to be pasted, then, the click event
  //          isn't generated.
  // NOTE #3: If touch caret is enabled, touch caret would ovelap input element,
  //          then, the click event isn't generated.
  if (aButton != 2 &&
      (aButton != 1 || !isEnabledMiddleClickPaste()) &&
      (aButton != 0 || !isEnabledAccessibleCaret())) {
    gClickCount = 0;
    // click on border of input
    synthesizeMouse(input, 5, 5, { button: aButton });
    is(gClickCount, 1,
       "click event doesn't fired on input element (button is " +
         aButton + ")");

    gClickCount = 0;
    // down on border
    synthesizeMouse(input, 5, 5, { type: "mousedown", button: aButton });
    // up on anonymous div of input
    synthesizeMouse(input, 20, 20, { type: "mouseup", button: aButton });
    is(gClickCount, 1,
       "click event doesn't fired on input element (button is " +
         aButton + ")");

    gClickCount = 0;
    // down on anonymous div of input
    synthesizeMouse(input, 20, 20, { type: "mousedown", button: aButton });
    // up on border
    synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton });
    is(gClickCount, 1,
       "click event doesn't fired on input element (button is " +
         aButton + ")");
  }

  gClickCount = 0;
  // down on outside of input
  synthesizeMouse(input, -3, -3, { type: "mousedown", button: aButton });
  // up on border
  synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton });
  is(gClickCount, 0,
     "click event is fired on input element unexpectedly (button is " +
       aButton + ")");
}

</script>
</pre>
</body>
</html>