| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 <p>This tests changing the focus on keypress event. The character typed by user
should be inserted into input. This test only runs in DRT.</p> | 4 <p>This tests changing the focus on keypress event. The character typed by user
should be inserted into input. This test only runs in DRT.</p> |
| 5 <pre><script> | 5 <pre><script> |
| 6 | 6 |
| 7 function runTest(name, shouldChangeSelection) { | 7 function runTest(name, shouldChangeSelection) { |
| 8 var dummy = document.createElement('input'); | 8 var dummy = document.createElement('input'); |
| 9 document.body.appendChild(dummy); | 9 document.body.appendChild(dummy); |
| 10 | 10 |
| 11 var element = document.createElement(name); | 11 var element = document.createElement(name); |
| 12 document.body.appendChild(element); | 12 document.body.appendChild(element); |
| 13 element.addEventListener('keypress', function() { | 13 element.addEventListener('keypress', function() { |
| 14 if (element.value.length >= 2) | 14 if (element.value.length >= 2) |
| 15 dummy.focus(); | 15 dummy.focus(); |
| 16 }) | 16 }) |
| 17 | 17 |
| 18 document.writeln(name + (shouldChangeSelection ? ' with selectionchange' : '
without selectionchange')); | 18 document.writeln(name + (shouldChangeSelection ? ' with selectionchange' : '
without selectionchange')); |
| 19 | 19 |
| 20 element.focus(); | 20 element.focus(); |
| 21 eventSender.keyDown('a'); | 21 eventSender.keyDown('a'); |
| 22 eventSender.leapForward(100); | 22 eventSender.leapForward(100); |
| 23 eventSender.keyDown(name == 'textarea' ? '\n' : 'b'); | 23 eventSender.keyDown(name == 'textarea' ? 'Enter' : 'b'); |
| 24 eventSender.leapForward(100); | 24 eventSender.leapForward(100); |
| 25 if (shouldChangeSelection) { | 25 if (shouldChangeSelection) { |
| 26 element.selectionStart = 1; | 26 element.selectionStart = 1; |
| 27 element.selectionEnd = 1; | 27 element.selectionEnd = 1; |
| 28 } | 28 } |
| 29 eventSender.keyDown('c'); | 29 eventSender.keyDown('c'); |
| 30 eventSender.leapForward(100); | 30 eventSender.leapForward(100); |
| 31 | 31 |
| 32 var expected = null; | 32 var expected = null; |
| 33 if (name == 'textarea') | 33 if (name == 'textarea') |
| (...skipping 15 matching lines...) Expand all Loading... |
| 49 runTest('input', true); | 49 runTest('input', true); |
| 50 runTest('textarea', false); | 50 runTest('textarea', false); |
| 51 runTest('textarea', true); | 51 runTest('textarea', true); |
| 52 | 52 |
| 53 document.writeln('DONE'); | 53 document.writeln('DONE'); |
| 54 } | 54 } |
| 55 | 55 |
| 56 </script></pre> | 56 </script></pre> |
| 57 </body> | 57 </body> |
| 58 </html> | 58 </html> |
| OLD | NEW |