| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../resources/js-test.js"></script> |
| </head> |
| <body onload="startTests()"> |
| <input id="inputId" value="abcd"></input> |
| <textarea id="textAreaId">abcd</textarea> |
| <script> |
| description("Test select event is triggered on input and textarea Elements."); |
| var input = document.getElementById("inputId"); |
| var textarea = document.getElementById("textAreaId"); |
| var jsTestIsAsync = true; |
| var currentCase; |
| var lastCase; |
| |
| var tests = [ |
| function() { |
| input.focus(); |
| return "input.focus()"; |
| }, |
| function() { |
| input.select(); |
| return "input.select()"; |
| }, |
| function() { |
| input.setSelectionRange(1, 2); |
| return "input.setSelectionRange()"; |
| }, |
| function() { |
| input.setRangeText("efgh"); |
| return "input.setRangeText()"; |
| }, |
| function() { |
| input.selectionStart = 1; |
| return "input.selectionStart"; |
| }, |
| function() { |
| input.selectionEnd = 3; |
| return "input.selectionEnd"; |
| }, |
| function() { |
| input.selectionDirection = "forward"; |
| return "input.selectionDirection"; |
| }, |
| function() { |
| textarea.focus(); |
| return "textarea.focus()"; |
| }, |
| function() { |
| textarea.select(); |
| return "textarea.select()"; |
| }, |
| function() { |
| textarea.setSelectionRange(1, 2); |
| return "textarea.setSelectionRange()"; |
| }, |
| function() { |
| textarea.setRangeText("efgh"); |
| return "textarea.setRangeText()"; |
| }, |
| function() { |
| textarea.selectionStart = 1; |
| return "textarea.selectionStart"; |
| }, |
| function() { |
| textarea.selectionEnd = 3; |
| return "textarea.selectionEnd"; |
| }, |
| function() { |
| textarea.selectionDirection = "forward"; |
| return "textarea.selectionDirection"; |
| } |
| ]; |
| |
| function runNext() { |
| if (tests.length <= 0) |
| finishJSTest(); |
| currentCase = tests.shift()(); |
| } |
| |
| function handleSelectEvent() { |
| if (lastCase == currentCase) { |
| testFailed("The above test dispatched mulitiple select events."); |
| return; |
| } |
| testPassed(currentCase); |
| lastCase = currentCase; |
| setTimeout(runNext, 0); |
| } |
| |
| function startTests() { |
| input.addEventListener("select", handleSelectEvent); |
| textarea.addEventListener("select", handleSelectEvent); |
| runNext(); |
| } |
| </script> |
| </body> |
| </html> |