dom/events/test/test_clickevent_on_input.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test click event on input</title>
     5   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10 <p id="display">
    11 <input id="input"
    12   style="position: absolute; top: 5px; left: 5px; border: solid 15px blue; width: 100px; height: 20px;"
    13   onclick="gClickCount++;">
    14 </p>
    15 <div id="content" style="display: none">
    17 </div>
    18 <pre id="test">
    19 <script type="application/javascript">
    21 var gClickCount = 0;
    23 SimpleTest.waitForExplicitFinish();
    24 SimpleTest.waitForFocus(runTests);
    26 var input = document.getElementById("input");
    28 function runTests()
    29 {
    30   for (var i = 0; i < 3; i++) {
    31     doTest(i);
    32   }
    34   // Re-test left clicking when the input element has some text. 
    35   gClickCount = 0;
    36   input.value = "Long text Long text Long text Long text Long text Long text";
    37   doTest(0);
    39   input.style.display = "none";
    40   SimpleTest.finish();
    41 }
    43 function isEnabledMiddleClickPaste()
    44 {
    45   try {
    46     return SpecialPowers.getBoolPref("middlemouse.paste");
    47   } catch (e) {
    48     return false;
    49   }
    50 }
    52 function doTest(aButton)
    53 {
    54   // NOTE #1: Right click causes a context menu to popup, then, the click event
    55   //          isn't generated.
    56   // NOTE #2: If middle click causes text to be pasted, then, the click event
    57   //          isn't generated.
    58   if (aButton != 2 && (aButton != 1 || !isEnabledMiddleClickPaste())) {
    59     gClickCount = 0;
    60     // click on border of input
    61     synthesizeMouse(input, 5, 5, { button: aButton });
    62     is(gClickCount, 1,
    63        "click event doesn't fired on input element (button is " +
    64          aButton + ")");
    66     gClickCount = 0;
    67     // down on border
    68     synthesizeMouse(input, 5, 5, { type: "mousedown", button: aButton });
    69     // up on anonymous div of input
    70     synthesizeMouse(input, 20, 20, { type: "mouseup", button: aButton });
    71     is(gClickCount, 1,
    72        "click event doesn't fired on input element (button is " +
    73          aButton + ")");
    75     gClickCount = 0;
    76     // down on anonymous div of input
    77     synthesizeMouse(input, 20, 20, { type: "mousedown", button: aButton });
    78     // up on border
    79     synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton });
    80     is(gClickCount, 1,
    81        "click event doesn't fired on input element (button is " +
    82          aButton + ")");
    83   }
    85   gClickCount = 0;
    86   // down on outside of input
    87   synthesizeMouse(input, -3, -3, { type: "mousedown", button: aButton });
    88   // up on border
    89   synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton });
    90   is(gClickCount, 0,
    91      "click event is fired on input element unexpectedly (button is " +
    92        aButton + ")");
    93 }
    95 </script>
    96 </pre>
    97 </body>
    98 </html>

mercurial