dom/events/test/test_clickevent_on_input.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:7722eedd9af5
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">
16
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
20
21 var gClickCount = 0;
22
23 SimpleTest.waitForExplicitFinish();
24 SimpleTest.waitForFocus(runTests);
25
26 var input = document.getElementById("input");
27
28 function runTests()
29 {
30 for (var i = 0; i < 3; i++) {
31 doTest(i);
32 }
33
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);
38
39 input.style.display = "none";
40 SimpleTest.finish();
41 }
42
43 function isEnabledMiddleClickPaste()
44 {
45 try {
46 return SpecialPowers.getBoolPref("middlemouse.paste");
47 } catch (e) {
48 return false;
49 }
50 }
51
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 + ")");
65
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 + ")");
74
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 }
84
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 }
94
95 </script>
96 </pre>
97 </body>
98 </html>

mercurial