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