test_bug633058.html (2075B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=633058 5 --> 6 <head> 7 <title>Test for Bug 633058</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633058">Mozilla Bug 633058</a> 14 <p id="display"></p> 15 <div id="content"> 16 <input> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 633058 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 25 SimpleTest.waitForFocus(startTest); 26 27 function startTest() { 28 var nbExpectedKeyDown = 8; 29 var nbExpectedKeyPress = 1; 30 var inputGotKeyPress = 0; 31 var inputGotKeyDown = 0; 32 var divGotKeyPress = 0; 33 var divGotKeyDown = 0; 34 35 var input = document.getElementsByTagName('input')[0]; 36 var content = document.getElementById('content'); 37 38 content.addEventListener("keydown", () => { divGotKeyDown++; }); 39 content.addEventListener("keypress", () => { divGotKeyPress++; }); 40 input.addEventListener("keydown", () => { inputGotKeyDown++; }); 41 input.addEventListener("keypress", () => { inputGotKeyPress++; }); 42 43 input.addEventListener('focus', function() { 44 SimpleTest.executeSoon(() => { 45 synthesizeKey('KEY_ArrowUp'); 46 synthesizeKey('KEY_ArrowLeft'); 47 synthesizeKey('KEY_ArrowRight'); 48 synthesizeKey('KEY_ArrowDown'); 49 synthesizeKey('KEY_Backspace'); 50 synthesizeKey('KEY_Delete'); 51 synthesizeKey('KEY_Escape'); 52 synthesizeKey('KEY_Enter'); // Will dispatch keypress event even in strict behavior. 53 54 is(inputGotKeyDown, nbExpectedKeyDown, "input got all keydown events"); 55 is(inputGotKeyPress, nbExpectedKeyPress, "input got all keypress events"); 56 is(divGotKeyDown, nbExpectedKeyDown, "div got all keydown events"); 57 is(divGotKeyPress, nbExpectedKeyPress, "div got all keypress events"); 58 SimpleTest.finish(); 59 }); 60 }, {once: true}); 61 input.focus(); 62 } 63 </script> 64 </pre> 65 </body> 66 </html>