|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=534833 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 534833</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=534833">Mozilla Bug 534833</a> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="display: none"> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript"> |
|
20 |
|
21 /** Test for Bug 534833 **/ |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 addLoadEvent(runTests); |
|
24 |
|
25 var input1GotClick = 0; |
|
26 var input2GotClick = 0; |
|
27 var textarea1GotClick = 0; |
|
28 var textarea2GotClick = 0; |
|
29 var div1GotClick = 0; |
|
30 var div2GotClick = 0; |
|
31 |
|
32 var tests = [ { element: "text", clickText: true }, |
|
33 { element: "text2", clickText: false }, |
|
34 { element: "area", clickText: true }, |
|
35 { element: "area2", clickText: false }, |
|
36 { element: "d", clickText: true }, |
|
37 { element: "d", clickText: false }, |
|
38 { element: "d2", clickText: true }, |
|
39 { element: "d2", clickText: false } |
|
40 ]; |
|
41 |
|
42 function nextTest_() { |
|
43 if (!tests.length) { |
|
44 finishTests(); |
|
45 return; |
|
46 } |
|
47 |
|
48 var test = tests.shift(); |
|
49 var el = document.getElementById(test.element); |
|
50 el.scrollIntoView(true); |
|
51 if (test.clickText) { |
|
52 synthesizeMouse(el, 5, 5, {type : "mousedown" }); |
|
53 synthesizeMouse(el, 5, 5, {type : "mouseup" }); |
|
54 } else { |
|
55 synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mousedown" }); |
|
56 synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mouseup" }); |
|
57 } |
|
58 nextTest(); |
|
59 } |
|
60 |
|
61 function nextTest() { |
|
62 var el = document.getElementById("initialfocus"); |
|
63 |
|
64 el.addEventListener("focus", function() { |
|
65 el.removeEventListener("focus", arguments.callee, false); |
|
66 setTimeout(nextTest_, 0); |
|
67 }, false); |
|
68 el.focus(); |
|
69 } |
|
70 |
|
71 function runTests() { |
|
72 var t = document.getElementById("text"); |
|
73 var t2 = document.getElementById("text2"); |
|
74 var a = document.getElementById("area"); |
|
75 var a2 = document.getElementById("area2"); |
|
76 var d = document.getElementById("d"); |
|
77 var d2 = document.getElementById("d2"); |
|
78 |
|
79 // input 1 |
|
80 t.onfocus = function(e) { |
|
81 t.value = ""; |
|
82 } |
|
83 t.onclick = function(e) { |
|
84 ++input1GotClick; |
|
85 } |
|
86 |
|
87 // input 2 |
|
88 t2.onfocus = function(e) { |
|
89 t2.value = ""; |
|
90 } |
|
91 t2.onclick = function(e) { |
|
92 ++input2GotClick; |
|
93 } |
|
94 |
|
95 // textarea 1 |
|
96 a.onfocus = function(e) { |
|
97 a.value = ""; |
|
98 } |
|
99 a.onclick = function(e) { |
|
100 ++textarea1GotClick; |
|
101 } |
|
102 |
|
103 // textarea 2 |
|
104 a2.onfocus = function(e) { |
|
105 a2.value = ""; |
|
106 } |
|
107 a2.onclick = function(e) { |
|
108 ++textarea2GotClick; |
|
109 } |
|
110 |
|
111 // div 1 |
|
112 var c = 0; |
|
113 d.onmousedown = function(e) { |
|
114 d.textContent = (++c) + " / click before or after |"; |
|
115 } |
|
116 d.onclick = function(e) { |
|
117 ++div1GotClick; |
|
118 } |
|
119 |
|
120 // div 2 |
|
121 var c2 = 0; |
|
122 d2.onmousedown = function(e) { |
|
123 d2.firstChild.data = (++c2) + " / click before or after |"; |
|
124 } |
|
125 d2.onclick = function(e) { |
|
126 ++div2GotClick; |
|
127 } |
|
128 nextTest(); |
|
129 } |
|
130 |
|
131 function finishTests() { |
|
132 is(input1GotClick, 1, "input element should have got a click!"); |
|
133 is(input2GotClick, 1, "input element should have got a click! (2)"); |
|
134 is(textarea1GotClick, 1, "textarea element should have got a click!"); |
|
135 is(textarea2GotClick, 1, "textarea element should have got a click! (2)"); |
|
136 is(div1GotClick, 2, "div element's content text was replaced, it should have got 2 click!"); |
|
137 is(div2GotClick, 2, "div element's content text was modified, it should have got 2 clicks!"); |
|
138 SimpleTest.finish(); |
|
139 } |
|
140 |
|
141 </script> |
|
142 </pre> |
|
143 <input type="text" id="initialfocus"><br> |
|
144 <input type="text" id="text" value="click before |" style="width: 95%;"><br> |
|
145 <input type="text" id="text2" value="click after |" style="width: 95%;"> |
|
146 <br> |
|
147 <textarea id="area" rows="2" style="width: 95%;"> |
|
148 click before |
|
149 | |
|
150 </textarea><br> |
|
151 <textarea id="area2" rows="2" style="width: 95%;"> |
|
152 click after | |
|
153 </textarea> |
|
154 <div id="d" style="border: 1px solid black;">click before or after |</div> |
|
155 <div id="d2" style="border: 1px solid black;">click before or after |</div> |
|
156 </body> |
|
157 </html> |