test_bug569988.html (2671B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=569988 5 --> 6 <head> 7 <title>Test for Bug 569988</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=569988">Mozilla Bug 569988</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 569988 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 SimpleTest.waitForFocus(runTest); 25 26 27 function runTest() { 28 var script = SpecialPowers.loadChromeScript(function() { 29 /* eslint-env mozilla/chrome-script */ 30 var gPromptInput = null; 31 var os = Services.obs; 32 33 os.addObserver(onPromptLoad, "common-dialog-loaded"); 34 35 function onPromptLoad(subject) { 36 let ui = subject.Dialog.ui; 37 sendAsyncMessage("ok", [true, "onPromptLoad is called"]); 38 gPromptInput = ui.loginTextbox; 39 gPromptInput.addEventListener("focus", onPromptFocus); 40 // shift focus to ensure it fires. 41 ui.button0.focus(); 42 gPromptInput.focus(); 43 } 44 45 function onPromptFocus() { 46 sendAsyncMessage("ok", [true, "onPromptFocus is called"]); 47 gPromptInput.removeEventListener("focus", onPromptFocus); 48 49 var listener = { 50 handleEvent: function _hv(aEvent) { 51 var isPrevented = aEvent.defaultPrevented; 52 sendAsyncMessage("ok", [!isPrevented, 53 "ESC key event is prevented by editor"]); 54 gPromptInput.removeEventListener("keypress", listener, { mozSystemGroup: true }); 55 }, 56 }; 57 gPromptInput.addEventListener("keypress", listener, { mozSystemGroup: true }); 58 59 sendAsyncMessage("info", "sending key"); 60 var EventUtils = {}; 61 EventUtils.window = {}; 62 EventUtils._EU_Ci = Ci; 63 EventUtils._EU_Cc = Cc; 64 Services.scriptloader 65 .loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", 66 EventUtils); 67 EventUtils.synthesizeKey("VK_ESCAPE", {}, 68 gPromptInput.ownerGlobal); 69 } 70 71 addMessageListener("destroy", function() { 72 os.removeObserver(onPromptLoad, "common-dialog-loaded"); 73 }); 74 }); 75 script.addMessageListener("ok", ([val, msg]) => ok(val, msg)); 76 script.addMessageListener("info", msg => info(msg)); 77 78 info("opening prompt..."); 79 prompt("summary", "text"); 80 info("prompt is closed"); 81 82 script.sendAsyncMessage("destroy"); 83 84 SimpleTest.finish(); 85 } 86 87 </script> 88 </pre> 89 </body> 90 </html>