browser_user_input_handling_delay_bfcache.js (3032B)
1 /* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 async function test_user_input_handling_delay_BFCache_helper(prefs) { 8 await SpecialPowers.pushPrefEnv({ 9 set: prefs, 10 }); 11 12 const tab = await BrowserTestUtils.openNewForegroundTab( 13 gBrowser, 14 `data:text/html,<body></body>`, 15 true 16 ); 17 18 let switchAwayPromise = BrowserTestUtils.browserLoaded( 19 browser, 20 false, 21 "about:blank" 22 ); 23 // Navigate away to make the page enters BFCache 24 await SpecialPowers.spawn(tab.linkedBrowser, [], () => { 25 content.location = "about:blank"; 26 }); 27 await switchAwayPromise; 28 29 // Navigate back to restore the page from BFCache 30 let pageShownPromise = BrowserTestUtils.waitForContentEvent( 31 tab.linkedBrowser, 32 "pageshow", 33 true 34 ); 35 36 await SpecialPowers.spawn(tab.linkedBrowser, [], () => { 37 content.history.back(); 38 }); 39 40 await pageShownPromise; 41 42 let canHandleInput = false; 43 let mouseDownPromise = BrowserTestUtils.waitForContentEvent( 44 tab.linkedBrowser, 45 "mousedown" 46 ).then(function () { 47 Assert.ok( 48 canHandleInput, 49 "This promise should be resolved after the 5 seconds mark has passed" 50 ); 51 }); 52 // Ensure the events are discarded initially 53 for (let i = 0; i < 10; ++i) { 54 await BrowserTestUtils.synthesizeMouseAtPoint( 55 10, 56 10, 57 { type: "mousedown" }, 58 tab.linkedBrowser 59 ); 60 } 61 62 // Wait for roughly 5 seconds to give chances for the 63 // above mousedown event to be handled. 64 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 65 for (let i = 0; i < 330; ++i) { 66 await new Promise(r => { 67 content.requestAnimationFrame(r); 68 }); 69 } 70 }); 71 72 // If any user input events were handled in the above 5 seconds 73 // the mouseDownPromise would be resolved with canHandleInput = false, 74 // so that the test would fail. 75 canHandleInput = true; 76 77 // Ensure the events can be handled eventually 78 await BrowserTestUtils.synthesizeMouseAtPoint( 79 10, 80 10, 81 { type: "mousedown" }, 82 tab.linkedBrowser 83 ); 84 85 await mouseDownPromise; 86 BrowserTestUtils.removeTab(tab); 87 } 88 89 add_task(async function test_MinRAF_BFCache() { 90 const prefs = [ 91 ["dom.input_events.security.minNumTicks", 100], 92 ["dom.input_events.security.minTimeElapsedInMS", 0], 93 ["dom.input_events.security.isUserInputHandlingDelayTest", true], 94 ]; 95 96 await test_user_input_handling_delay_BFCache_helper(prefs); 97 }); 98 99 add_task(async function test_MinElapsedTime_BFCache() { 100 const prefs = [ 101 ["dom.input_events.security.minNumTicks", 0], 102 ["dom.input_events.security.minTimeElapsedInMS", 5000], 103 ["dom.input_events.security.isUserInputHandlingDelayTest", true], 104 ]; 105 106 await test_user_input_handling_delay_BFCache_helper(prefs); 107 });