Chromium Code Reviews| 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 } |
| 11 function checkSelection(expected) | 11 function checkSelection(expected) |
| 12 { | 12 { |
| 13 actual = getSelectedOptions("sl1"); | 13 actual = getSelectedOptions("sl1"); |
| 14 if (actual.toString() != expected) | 14 if (actual.toString() != expected) |
| 15 log('Incorrect selection: "' + actual + '" instead of "' + e xpected + '"'); | 15 log('Incorrect selection: "' + actual + '" instead of "' + e xpected + '"'); |
| 16 } | 16 } |
| 17 function test() | 17 function test() |
| 18 { | 18 { |
| 19 setup(); | 19 setup(); |
| 20 | 20 |
| 21 if (window.testRunner) { | 21 if (window.testRunner) { |
| 22 testRunner.dumpAsText(); | 22 testRunner.dumpAsText(); |
| 23 testRunner.waitUntilDone(); | 23 testRunner.waitUntilDone(); |
| 24 } | 24 } |
| 25 | 25 |
|
Rick Byers
2015/04/20 18:41:27
Nit: this test was originally designed to work dir
| |
| 26 checkSelection("0"); | 26 checkSelection("0"); |
| 27 | 27 |
| 28 log("1) Make sure onChange doesn't fire when clicking on an init ially selected item"); | 28 log("1) Make sure onChange doesn't fire when clicking on an init ially selected item"); |
| 29 mouseDownOnSelect("sl1", 0, false, false); | 29 mouseDownOnSelect("sl1", 0, false, false); |
| 30 mouseUpOnSelect("sl1", 0, false, false); | 30 mouseUpOnSelect("sl1", 0, false, false); |
| 31 checkSelection("0"); | 31 checkSelection("0"); |
| 32 | 32 |
| 33 log("2) Make sure onChange fires when deselecting an initially s elected item"); | 33 log("2) Make sure onChange fires when deselecting an initially s elected item"); |
| 34 mouseDownOnSelect("sl1", 0, false, true); | 34 mouseDownOnSelect("sl1", 0, false, true); |
| 35 mouseUpOnSelect("sl1", 0, false, true); | 35 mouseUpOnSelect("sl1", 0, false, true); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 122 |
| 123 function mouseDownOnSelect(selId, index, shift, metaOrCtrl) | 123 function mouseDownOnSelect(selId, index, shift, metaOrCtrl) |
| 124 { | 124 { |
| 125 var meta = false; | 125 modifiers = []; |
| 126 var ctrl = false; | 126 if (shift) |
| 127 modifiers[0] = "shiftKey"; | |
| 127 if (metaOrCtrl) { | 128 if (metaOrCtrl) { |
| 128 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 129 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) |
| 129 meta = true; | 130 modifiers[modifiers.length] = "metaKey"; |
| 130 else | 131 else |
| 131 ctrl = true; | 132 modifiers[modifiers.length] = "ctrlKey"; |
| 132 } | 133 } |
| 134 | |
| 133 var sl = document.getElementById(selId); | 135 var sl = document.getElementById(selId); |
| 134 var event = document.createEvent("MouseEvent"); | 136 var rect = sl.options[index].getBoundingClientRect(); |
| 135 event.initMouseEvent("mousedown", true, true, document.defaultVi ew, 1, 0, 0, 0, 0, ctrl, false, shift, meta, 0, document); | 137 eventSender.mouseMoveTo(rect.left + 1, rect.top + 1); |
| 136 sl.options[index].dispatchEvent(event); | 138 eventSender.mouseDown(0, modifiers); |
| 137 } | 139 } |
| 138 | 140 |
| 139 function mouseUpOnSelect(selId, index, shift, metaOrCtrl) | 141 function mouseUpOnSelect(selId, index, shift, metaOrCtrl) |
| 140 { | 142 { |
| 141 var meta = false; | 143 modifiers = []; |
| 142 var ctrl = false; | 144 if (shift) |
| 145 modifiers[0] = "shiftKey"; | |
| 143 if (metaOrCtrl) { | 146 if (metaOrCtrl) { |
| 144 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 147 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) |
| 145 meta = true; | 148 modifiers[modifiers.length] = "metaKey"; |
| 146 else | 149 else |
| 147 ctrl = true; | 150 modifiers[modifiers.length] = "ctrlKey"; |
| 148 } | 151 } |
| 152 | |
| 149 var sl = document.getElementById(selId); | 153 var sl = document.getElementById(selId); |
| 150 var event = document.createEvent("MouseEvent"); | 154 var rect = sl.options[index].getBoundingClientRect(); |
| 151 event.initMouseEvent("mouseup", true, true, document.defaultView , 1, 0, 0, 0, 0, ctrl, false, shift, meta, 0, document); | 155 eventSender.mouseMoveTo(rect.left + 1, rect.top + 1); |
| 152 sl.options[index].dispatchEvent(event); | 156 eventSender.mouseUp(0, modifiers); |
| 153 } | 157 } |
| 154 | 158 |
| 155 function keyDownOnSelect(selId, identifier, shift, metaOrCtrl) | 159 function keyDownOnSelect(selId, identifier, shift, metaOrCtrl) |
| 156 { | 160 { |
| 157 modifiers = []; | 161 modifiers = []; |
| 158 if (shift) | 162 if (shift) |
| 159 modifiers[0] = "shiftKey"; | 163 modifiers[0] = "shiftKey"; |
| 160 if (metaOrCtrl) { | 164 if (metaOrCtrl) { |
| 161 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) | 165 if (navigator.userAgent.search(/\bMac OS X\b/) != -1) |
| 162 modifiers[modifiers.length] = "metaKey"; | 166 modifiers[modifiers.length] = "metaKey"; |
| 163 else | 167 else |
| 164 modifiers[modifiers.length] = "controlKey"; | 168 modifiers[modifiers.length] = "ctrlKey"; |
| 165 } | 169 } |
| 166 | 170 |
| 167 document.getElementById(selId).focus(); | 171 document.getElementById(selId).focus(); |
| 168 eventSender.keyDown(identifier, modifiers); | 172 eventSender.keyDown(identifier, modifiers); |
| 169 } | 173 } |
| 170 | 174 |
| 171 function getSelectedOptions(selId) | 175 function getSelectedOptions(selId) |
| 172 { | 176 { |
| 173 result = new Array; | 177 result = new Array; |
| 174 var sl = document.getElementById(selId); | 178 var sl = document.getElementById(selId); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 187 </head> | 191 </head> |
| 188 <body onload="test()"> | 192 <body onload="test()"> |
| 189 <select id="sl1" size=5 multiple onchange="log('onChange fired')"> | 193 <select id="sl1" size=5 multiple onchange="log('onChange fired')"> |
| 190 <option selected value="0">item 0</option> | 194 <option selected value="0">item 0</option> |
| 191 <option value="1">item 1 | 195 <option value="1">item 1 |
| 192 <option value="2">item 2 | 196 <option value="2">item 2 |
| 193 <option value="3">item 3 | 197 <option value="3">item 3 |
| 194 </select> | 198 </select> |
| 195 </body> | 199 </body> |
| 196 </html> | 200 </html> |
| OLD | NEW |