browser_bug1316330.js (1450B)
1 const URL = 2 "data:text/html,<script>" + 3 "window.focus();" + 4 "var down = 0; var press = 0;" + 5 "onkeydown = function(e) {" + 6 " var startTime = Date.now();" + 7 " document.body.setAttribute('data-down', ++down);" + 8 " if (e.keyCode == KeyboardEvent.DOM_VK_D) while (Date.now() - startTime < 500) {}" + 9 "};" + 10 "onkeypress = function(e) {" + 11 " var startTime = Date.now();" + 12 " document.body.setAttribute('data-press', ++press);" + 13 " if (e.charCode == 'p'.charCodeAt(0)) while (Date.now() - startTime < 500) {}" + 14 "};" + 15 "</script>"; 16 17 add_task(async function () { 18 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); 19 let browser = tab.linkedBrowser; 20 21 await EventUtils.synthesizeAndWaitKey("d", { repeat: 3 }); 22 23 await SpecialPowers.spawn(browser, [], async function () { 24 is( 25 content.document.body.getAttribute("data-down"), 26 "2", 27 "Correct number of events" 28 ); 29 is( 30 content.document.body.getAttribute("data-press"), 31 "2", 32 "Correct number of events" 33 ); 34 }); 35 36 await EventUtils.synthesizeAndWaitKey("p", { repeat: 3 }); 37 38 await SpecialPowers.spawn(browser, [], async function () { 39 is( 40 content.document.body.getAttribute("data-down"), 41 "4", 42 "Correct number of events" 43 ); 44 is( 45 content.document.body.getAttribute("data-press"), 46 "4", 47 "Correct number of events" 48 ); 49 }); 50 51 gBrowser.removeCurrentTab(); 52 });