OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script> | 3 <script> |
4 function setup() | 4 function setup() |
5 { | 5 { |
6 var results = document.createElement('div'); | 6 var results = document.createElement('div'); |
7 results.id = "res"; | 7 results.id = "res"; |
8 results.appendChild(document.createTextNode("Results:")); | 8 results.appendChild(document.createTextNode("Results:")); |
9 document.body.appendChild(results); | 9 document.body.appendChild(results); |
10 } | 10 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 keyDownOnSelect("sl1", "K", false, false); | 112 keyDownOnSelect("sl1", "K", false, false); |
113 checkSelection("4"); | 113 checkSelection("4"); |
114 | 114 |
115 log("18) Make sure onChange doesn't fire when leaving the select
"); | 115 log("18) Make sure onChange doesn't fire when leaving the select
"); |
116 document.getElementById("sl1").blur(); | 116 document.getElementById("sl1").blur(); |
117 checkSelection("4"); | 117 checkSelection("4"); |
118 | 118 |
119 if (window.testRunner) | 119 if (window.testRunner) |
120 testRunner.notifyDone(); | 120 testRunner.notifyDone(); |
121 } | 121 } |
| 122 |
| 123 function buildModifiers(shift, metaOrCtrl) { |
| 124 modifiers = []; |
| 125 if (shift) |
| 126 modifiers.push("shiftKey"); |
| 127 if (metaOrCtrl) |
| 128 modifiers.push("addSelectionKey"); |
| 129 return modifiers; |
| 130 } |
122 | 131 |
123 function mouseDownOnSelect(selId, index, shift, metaOrCtrl) | 132 function mouseDownOnSelect(selId, index, shift, metaOrCtrl) |
124 { | 133 { |
125 var meta = false; | 134 modifiers = buildModifiers(shift, metaOrCtrl); |
126 var ctrl = false; | 135 var sl = document.getElementById(selId); |
127 if (metaOrCtrl) { | 136 var rect = sl.options[index].getBoundingClientRect(); |
128 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 137 if (window.eventSender) { |
129 meta = true; | 138 eventSender.mouseMoveTo(rect.left + 1, rect.top + 1); |
130 else | 139 eventSender.mouseDown(0, modifiers); |
131 ctrl = true; | 140 } else { |
| 141 testFailed("This test requires window.eventSender."); |
132 } | 142 } |
133 var sl = document.getElementById(selId); | |
134 var event = document.createEvent("MouseEvent"); | |
135 event.initMouseEvent("mousedown", true, true, document.defaultVi
ew, 1, 0, 0, 0, 0, ctrl, false, shift, meta, 0, document); | |
136 sl.options[index].dispatchEvent(event); | |
137 } | 143 } |
138 | 144 |
139 function mouseUpOnSelect(selId, index, shift, metaOrCtrl) | 145 function mouseUpOnSelect(selId, index, shift, metaOrCtrl) |
140 { | 146 { |
141 var meta = false; | 147 modifiers = buildModifiers(shift, metaOrCtrl); |
142 var ctrl = false; | 148 var sl = document.getElementById(selId); |
143 if (metaOrCtrl) { | 149 var rect = sl.options[index].getBoundingClientRect(); |
144 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 150 if (window.eventSender) { |
145 meta = true; | 151 eventSender.mouseMoveTo(rect.left + 1, rect.top + 1); |
146 else | 152 eventSender.mouseUp(0, modifiers); |
147 ctrl = true; | 153 } else { |
| 154 testFailed("This test requires window.eventSender."); |
148 } | 155 } |
149 var sl = document.getElementById(selId); | |
150 var event = document.createEvent("MouseEvent"); | |
151 event.initMouseEvent("mouseup", true, true, document.defaultView
, 1, 0, 0, 0, 0, ctrl, false, shift, meta, 0, document); | |
152 sl.options[index].dispatchEvent(event); | |
153 } | 156 } |
154 | 157 |
155 function keyDownOnSelect(selId, identifier, shift, metaOrCtrl) | 158 function keyDownOnSelect(selId, identifier, shift, metaOrCtrl) |
156 { | 159 { |
157 modifiers = []; | 160 modifiers = buildModifiers(shift, metaOrCtrl); |
158 if (shift) | 161 document.getElementById(selId).focus(); |
159 modifiers[0] = "shiftKey"; | 162 if (window.eventSender) { |
160 if (metaOrCtrl) { | 163 eventSender.keyDown(identifier, modifiers); |
161 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 164 } else { |
162 modifiers[modifiers.length] = "metaKey"; | 165 testFailed("This test requires window.eventSender."); |
163 else | |
164 modifiers[modifiers.length] = "controlKey"; | |
165 } | 166 } |
166 | |
167 document.getElementById(selId).focus(); | |
168 eventSender.keyDown(identifier, modifiers); | |
169 } | 167 } |
170 | 168 |
171 function getSelectedOptions(selId) | 169 function getSelectedOptions(selId) |
172 { | 170 { |
173 result = new Array; | 171 result = new Array; |
174 var sl = document.getElementById(selId); | 172 var sl = document.getElementById(selId); |
175 for (i = 0; i < sl.options.length; ++i) | 173 for (i = 0; i < sl.options.length; ++i) |
176 if (sl.item(i).selected) | 174 if (sl.item(i).selected) |
177 result.push(i); | 175 result.push(i); |
178 return result; | 176 return result; |
179 } | 177 } |
180 | 178 |
181 function log(msg) | 179 function log(msg) |
182 { | 180 { |
183 var r = document.getElementById('res'); | 181 var r = document.getElementById('res'); |
184 r.innerHTML = r.innerHTML + "<br>" + msg; | 182 r.innerHTML = r.innerHTML + "<br>" + msg; |
185 } | 183 } |
186 </script> | 184 </script> |
187 </head> | 185 </head> |
188 <body onload="test()"> | 186 <body onload="test()"> |
189 <select id="sl1" size=5 multiple onchange="log('onChange fired')"> | 187 <select id="sl1" size=5 multiple onchange="log('onChange fired')"> |
190 <option selected value="0">item 0</option> | 188 <option selected value="0">item 0</option> |
191 <option value="1">item 1 | 189 <option value="1">item 1 |
192 <option value="2">item 2 | 190 <option value="2">item 2 |
193 <option value="3">item 3 | 191 <option value="3">item 3 |
194 </select> | 192 </select> |
195 </body> | 193 </body> |
196 </html> | 194 </html> |
OLD | NEW |