test_focus_keyboard_event.html (1410B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=552255 5 --> 6 <head> 7 <title>Test for bug 552255</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=552255">Mozilla Bug 552255</a> 14 <p id="display"></p> 15 <input type="text"><br> 16 <iframe src="http://example.org/tests/dom/base/test/file_empty.html"></iframe> 17 <script> 18 add_task(async function cross_origin_iframe() { 19 await SimpleTest.promiseFocus(); 20 21 // Setup test in iframe 22 let iframe = document.querySelector("iframe"); 23 await SpecialPowers.spawn(iframe, [], () => { 24 content.document.body.addEventListener("keydown", (e) => { 25 ok(false, `should not receive any keydown event, ${e.key}`); 26 }); 27 content.addEventListener("focus", (e) => { 28 ok(false, `should not receive any focus event`); 29 }); 30 }); 31 32 let input = document.querySelector("input"); 33 input.focus(); 34 35 input.addEventListener("keydown", (e) => { 36 iframe.focus(); 37 }); 38 39 // Start test. 40 synthesizeKey("a"); 41 42 await new Promise(SimpleTest.executeSoon); 43 ok(document.hasFocus(), "document should still have focus"); 44 is(document.activeElement, input, "input should still have focus"); 45 }); 46 </script> 47 </body> 48 </html>