browser_promise_userInteractionHandling.js (1658B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 "use strict"; 7 8 add_setup(async function () { 9 await SpecialPowers.pushPrefEnv({ 10 set: [["test.wait300msAfterTabSwitch", true]], 11 }); 12 }); 13 14 add_task(async function test_explicit_object_prototype() { 15 const url = 16 "http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_promise_userInteractionHandling.html"; 17 await BrowserTestUtils.withNewTab(url, async browser => { 18 await SpecialPowers.spawn(browser, [], async () => { 19 const DOMWindowUtils = EventUtils._getDOMWindowUtils(content.window); 20 is( 21 DOMWindowUtils.isHandlingUserInput, 22 false, 23 "not yet handling user input" 24 ); 25 const button = content.document.getElementById("button"); 26 27 let resolve; 28 const p = new Promise(r => { 29 resolve = r; 30 }); 31 32 button.addEventListener("click", () => { 33 is(DOMWindowUtils.isHandlingUserInput, true, "handling user input"); 34 content.document.hasStorageAccess().then(() => { 35 is( 36 DOMWindowUtils.isHandlingUserInput, 37 true, 38 "still handling user input" 39 ); 40 Promise.resolve().then(() => { 41 is( 42 DOMWindowUtils.isHandlingUserInput, 43 false, 44 "no more handling user input" 45 ); 46 resolve(); 47 }); 48 }); 49 }); 50 51 EventUtils.synthesizeMouseAtCenter(button, {}, content.window); 52 53 await p; 54 }); 55 }); 56 });