test_clickevent_on_input.html (2934B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test click event on input</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script 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 inputmode="none" 14 onclick="gClickCount++;"> 15 </p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 <script type="application/javascript"> 21 22 var gClickCount = 0; 23 24 SimpleTest.waitForExplicitFinish(); 25 SimpleTest.waitForFocus(runTests); 26 27 var input = document.getElementById("input"); 28 29 function runTests() 30 { 31 for (var i = 0; i < 3; i++) { 32 doTest(i); 33 } 34 35 // Re-test left clicking when the input element has some text. 36 gClickCount = 0; 37 input.value = "Long text Long text Long text Long text Long text Long text"; 38 doTest(0); 39 40 input.style.display = "none"; 41 SimpleTest.finish(); 42 } 43 44 function isEnabledMiddleClickPaste() 45 { 46 try { 47 return SpecialPowers.getBoolPref("middlemouse.paste"); 48 } catch (e) { 49 return false; 50 } 51 } 52 53 function isEnabledAccessibleCaret() 54 { 55 try { 56 return SpecialPowers.getBoolPref("layout.accessiblecaret.enabled"); 57 } catch (e) { 58 return false; 59 } 60 } 61 62 function doTest(aButton) 63 { 64 // NOTE #1: Non-primary buttons don't generate 'click' events 65 // NOTE #2: If touch caret is enabled, touch caret would ovelap input element, 66 // then, the click event isn't generated. 67 if (aButton != 2 && 68 aButton != 1 && 69 (aButton != 0 || !isEnabledAccessibleCaret())) { 70 gClickCount = 0; 71 // click on border of input 72 synthesizeMouse(input, 5, 5, { button: aButton }); 73 is(gClickCount, 1, 74 "click event doesn't fired on input element (button is " + 75 aButton + ")"); 76 77 gClickCount = 0; 78 // down on border 79 synthesizeMouse(input, 5, 5, { type: "mousedown", button: aButton }); 80 // up on anonymous div of input 81 synthesizeMouse(input, 20, 20, { type: "mouseup", button: aButton }); 82 is(gClickCount, 1, 83 "click event doesn't fired on input element (button is " + 84 aButton + ")"); 85 86 gClickCount = 0; 87 // down on anonymous div of input 88 synthesizeMouse(input, 20, 20, { type: "mousedown", button: aButton }); 89 // up on border 90 synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton }); 91 is(gClickCount, 1, 92 "click event doesn't fired on input element (button is " + 93 aButton + ")"); 94 } 95 96 gClickCount = 0; 97 // down on outside of input 98 synthesizeMouse(input, -3, -3, { type: "mousedown", button: aButton }); 99 // up on border 100 synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton }); 101 is(gClickCount, 0, 102 "click event is fired on input element unexpectedly (button is " + 103 aButton + ")"); 104 } 105 106 </script> 107 </pre> 108 </body> 109 </html>