/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; add_task(async function check_focus() { const extension = ExtensionTestUtils.loadExtension({ files: { "background.js": async () => { // Create a promise which waits until the script in the window is loaded // and the email field has focus, so we can send our fake keystrokes. const loadPromise = new Promise(resolve => { const listener = async (msg, sender) => { if (msg == "loaded") { browser.runtime.onMessage.removeListener(listener); resolve(sender.tab.windowId); } }; browser.runtime.onMessage.addListener(listener); }); const openedWin = await browser.windows.create({ url: "focus.html", type: "popup", // not requesting allowScriptsToClose: true here, to verify bug 1902844 }); const loadedWinId = await loadPromise; browser.test.assertEq( openedWin.id, loadedWinId, "The correct window should have been loaded" ); const removePromise = new Promise(resolve => { browser.windows.onRemoved.addListener(id => { if (id == openedWin.id) { resolve(); } }); }); window.sendMessage("sendKeyStrokes", openedWin.id); await removePromise; browser.test.notifyPass("finished"); }, "focus.html": `