1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/test_clickevent_on_input.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test click event on input</title> 1.8 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.11 +</head> 1.12 +<body> 1.13 +<p id="display"> 1.14 +<input id="input" 1.15 + style="position: absolute; top: 5px; left: 5px; border: solid 15px blue; width: 100px; height: 20px;" 1.16 + onclick="gClickCount++;"> 1.17 +</p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +var gClickCount = 0; 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 +SimpleTest.waitForFocus(runTests); 1.28 + 1.29 +var input = document.getElementById("input"); 1.30 + 1.31 +function runTests() 1.32 +{ 1.33 + for (var i = 0; i < 3; i++) { 1.34 + doTest(i); 1.35 + } 1.36 + 1.37 + // Re-test left clicking when the input element has some text. 1.38 + gClickCount = 0; 1.39 + input.value = "Long text Long text Long text Long text Long text Long text"; 1.40 + doTest(0); 1.41 + 1.42 + input.style.display = "none"; 1.43 + SimpleTest.finish(); 1.44 +} 1.45 + 1.46 +function isEnabledMiddleClickPaste() 1.47 +{ 1.48 + try { 1.49 + return SpecialPowers.getBoolPref("middlemouse.paste"); 1.50 + } catch (e) { 1.51 + return false; 1.52 + } 1.53 +} 1.54 + 1.55 +function doTest(aButton) 1.56 +{ 1.57 + // NOTE #1: Right click causes a context menu to popup, then, the click event 1.58 + // isn't generated. 1.59 + // NOTE #2: If middle click causes text to be pasted, then, the click event 1.60 + // isn't generated. 1.61 + if (aButton != 2 && (aButton != 1 || !isEnabledMiddleClickPaste())) { 1.62 + gClickCount = 0; 1.63 + // click on border of input 1.64 + synthesizeMouse(input, 5, 5, { button: aButton }); 1.65 + is(gClickCount, 1, 1.66 + "click event doesn't fired on input element (button is " + 1.67 + aButton + ")"); 1.68 + 1.69 + gClickCount = 0; 1.70 + // down on border 1.71 + synthesizeMouse(input, 5, 5, { type: "mousedown", button: aButton }); 1.72 + // up on anonymous div of input 1.73 + synthesizeMouse(input, 20, 20, { type: "mouseup", button: aButton }); 1.74 + is(gClickCount, 1, 1.75 + "click event doesn't fired on input element (button is " + 1.76 + aButton + ")"); 1.77 + 1.78 + gClickCount = 0; 1.79 + // down on anonymous div of input 1.80 + synthesizeMouse(input, 20, 20, { type: "mousedown", button: aButton }); 1.81 + // up on border 1.82 + synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton }); 1.83 + is(gClickCount, 1, 1.84 + "click event doesn't fired on input element (button is " + 1.85 + aButton + ")"); 1.86 + } 1.87 + 1.88 + gClickCount = 0; 1.89 + // down on outside of input 1.90 + synthesizeMouse(input, -3, -3, { type: "mousedown", button: aButton }); 1.91 + // up on border 1.92 + synthesizeMouse(input, 5, 5, { type: "mouseup", button: aButton }); 1.93 + is(gClickCount, 0, 1.94 + "click event is fired on input element unexpectedly (button is " + 1.95 + aButton + ")"); 1.96 +} 1.97 + 1.98 +</script> 1.99 +</pre> 1.100 +</body> 1.101 +</html>