| <html> |
| <head> |
| <script> |
| function setup() |
| { |
| createSelect("sl1", 5, false, -1, " 1) Select one item with mouse (no previous selection)"); |
| createSelect("sl2", 5, false, 1, " 2) Select one item with mouse (with previous selection)"); |
| createSelect("sl3", 5, false, -1, " 3) Select one item with the keyboard (no previous selection)"); |
| createSelect("sl4", 5, false, 1, " 4) Select one item with the keyboard (with previous selection)"); |
| createSelect("sl5", 5, false, 2, " 5) Attempt to select an item cmd-clicking"); |
| createSelect("sl6", 5, false, 3, " 6) Attempt to select a range shift-clicking"); |
| createSelect("sl7", 5, false, 1, " 7) Attempt to select a range with the keyboard"); |
| |
| createSelect("sl8", 5, true, -1, " 8) Select one item with mouse (no previous selection)"); |
| createSelect("sl9", 5, true, 1, " 9) Select one item with mouse (with previous selection)"); |
| createSelect("sl10", 5, true, -1, " 10) Select one item with the keyboard (no previous selection)"); |
| createSelect("sl11", 5, true, 1, " 11) Select one item with the keyboard (with previous selection)"); |
| createSelect("sl12", 5, true, 2, " 12) Select an item cmd-clicking"); |
| createSelect("sl13", 5, true, 0, " 13) Select a range shift-clicking"); |
| createSelect("sl14", 5, true, 1, " 14) Select a range with the keyboard"); |
| |
| var results = document.createElement('div'); |
| results.id = "res"; |
| results.appendChild(document.createTextNode("Results:")); |
| document.body.appendChild(results); |
| } |
| function test() |
| { |
| setup(); |
| |
| if (window.layoutTestController) { |
| layoutTestController.dumpAsText(); |
| layoutTestController.waitUntilDone(); |
| } |
| |
| // 1) Select one item with mouse (no previous selection) |
| mouseDownOnSelect("sl1", 0, false, false); |
| var expectedSelectionResults = new Array(true, false, false, false, false); |
| testResults(expectedSelectionResults, 1); |
| |
| // 2) Select one item with mouse (with previous selection) |
| mouseDownOnSelect("sl2", 0, false, false); |
| expectedSelectionResults = new Array(true, false, false, false, false); |
| testResults(expectedSelectionResults, 2); |
| |
| // 3) Select one item with the keyboard (no previous selection) |
| keyDownOnSelect("sl3", "upArrow", false, false); |
| expectedSelectionResults = new Array(false, false, false, false, true); |
| testResults(expectedSelectionResults, 3); |
| |
| // 4) Select one item with the keyboard (with previous selection) |
| keyDownOnSelect("sl4", "downArrow", false, false); |
| expectedSelectionResults = new Array(false, false, true, false, false); |
| testResults(expectedSelectionResults, 4); |
| |
| // 5) Attempt to select an item cmd-clicking |
| mouseDownOnSelect("sl5", 1, false, true); |
| expectedSelectionResults = new Array(false, true, false, false, false); |
| testResults(expectedSelectionResults, 5); |
| |
| // 6) Attempt to select a range shift-clicking |
| mouseDownOnSelect("sl6", 1, true, false); |
| expectedSelectionResults = new Array(false, true, false, false, false); |
| testResults(expectedSelectionResults, 6); |
| |
| // 7) Attempt to select a range with the keyboard |
| keyDownOnSelect("sl7", "downArrow", true, false); |
| expectedSelectionResults = new Array(false, false, true, false, false); |
| testResults(expectedSelectionResults, 7); |
| |
| // Multiple selection tests |
| |
| // 8) Select one item with mouse (no previous selection) |
| mouseDownOnSelect("sl8", 0, false, false); |
| expectedSelectionResults = new Array(true, false, false, false, false); |
| testResults(expectedSelectionResults, 8); |
| |
| // 9) Select one item with mouse (with previous selection) |
| var sl0 = document.getElementById('sl9'); |
| mouseDownOnSelect("sl9", 0, false, false); |
| expectedSelectionResults = new Array(true, false, false, false, false); |
| testResults(expectedSelectionResults, 9); |
| |
| // 10) Select one item with the keyboard (no previous selection) |
| keyDownOnSelect("sl10", "upArrow", false, false); |
| expectedSelectionResults = new Array(false, false, false, false, true); |
| testResults(expectedSelectionResults, 10); |
| |
| // 11) Select one item with the keyboard (with previous selection) |
| keyDownOnSelect("sl11", "downArrow", false, false); |
| expectedSelectionResults = new Array(false, false, true, false, false); |
| testResults(expectedSelectionResults, 11); |
| |
| // 12) Select an item cmd-clicking |
| mouseDownOnSelect("sl12", 1, false, true); |
| expectedSelectionResults = new Array(false, true, true, false, false); |
| testResults(expectedSelectionResults, 12); |
| |
| // 13) Select a range shift-clicking |
| mouseDownOnSelect("sl13", 3, true, false); |
| expectedSelectionResults = new Array(true, true, true, true, false); |
| testResults(expectedSelectionResults, 13); |
| |
| // 14) Select a range with the keyboard |
| keyDownOnSelect("sl14", "downArrow", true, false); |
| expectedSelectionResults = new Array(false, true, true, false, false); |
| testResults(expectedSelectionResults, 14); |
| |
| if (window.layoutTestController) |
| layoutTestController.notifyDone(); |
| |
| } |
| |
| function mouseDownOnSelect(selId, index, shift, metaOrCtrl) |
| { |
| var meta = false; |
| var ctrl = false; |
| if (metaOrCtrl) { |
| if (navigator.userAgent.search(/\bMac OS X\b/) != -1) |
| meta = true; |
| else |
| ctrl = true; |
| } |
| var sl = document.getElementById(selId); |
| var itemHeight = 14; |
| var border = 1; |
| var y = border + index * itemHeight - window.pageYOffset; |
| var event = document.createEvent("MouseEvent"); |
| event.initMouseEvent("mousedown", true, true, document.defaultView, 1, sl.offsetLeft + border, sl.offsetTop + y, sl.offsetLeft + border, sl.offsetTop + y, ctrl, false, shift, meta, 0, document); |
| sl.dispatchEvent(event); |
| } |
| |
| function keyDownOnSelect(selId, identifier, shift, metaOrCtrl) |
| { |
| modifiers = []; |
| if (shift) |
| modifiers[0] = "shiftKey"; |
| if (metaOrCtrl) { |
| if (navigator.userAgent.search(/\bMac OS X\b/) != -1) |
| modifiers[modifiers.length] = "metaKey"; |
| else |
| modifiers[modifiers.length] = "controlKey"; |
| } |
| |
| document.getElementById(selId).focus(); |
| eventSender.keyDown(identifier, modifiers); |
| } |
| |
| function createSelect(idName, sz, mlt, selIndex, testMsg) |
| { |
| var sl = document.createElement("select"); |
| var i = 0; |
| while (i < sz) { |
| var opt = document.createElement("option"); |
| if (i == selIndex) |
| opt.selected = true; |
| opt.innerText = "item " + i; |
| sl.appendChild(opt); |
| i++; |
| } |
| sl.size = sz; |
| sl.multiple = mlt; |
| sl.id = idName; |
| document.body.appendChild(sl); |
| document.body.appendChild(document.createTextNode(testMsg)); |
| document.body.appendChild(document.createElement("br")); |
| } |
| |
| function testResults(expectedArr, testNum) |
| { |
| var sl = document.getElementById("sl" + testNum); |
| var res = document.getElementById('res'); |
| var resultsArr = new Array(sl.options.length); |
| |
| var i; |
| for (i=0; i < sl.options.length; i++) { |
| resultsArr[i] = sl.options[i].selected; |
| } |
| var successString = "Failed"; |
| var success = false; |
| if (expectedArr.join() == resultsArr.join()) { |
| success = true; |
| successString = "Passed"; |
| } |
| |
| log("Test " + testNum + " " + successString); |
| if (!success) { |
| log("<pre> Expected: " + expectedArr.join() + "<br>" + " Actual: " + resultsArr.join() + "</pre>"); |
| } |
| } |
| |
| function log(msg) |
| { |
| var r = document.getElementById('res'); |
| r.innerHTML = r.innerHTML + "<br>" + msg; |
| } |
| </script> |
| </head> |
| <body onload="test()"> |
| </body> |
| </html> |