/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; /* import-globals-from ../file_ime_state_test_helper.js */ Services.scriptloader.loadSubScript( "chrome://mochitests/content/browser/widget/tests/browser/file_ime_state_test_helper.js", this ); add_task(async () => { await BrowserTestUtils.withNewTab( "data:text/html,
", async function (browser) { const tipWrapper = new TIPWrapper(window); ok( tipWrapper.isAvailable(), "TextInputProcessor should've been initialized" ); function promiseSelectionChange() { return new Promise(resolve => { tipWrapper.onSelectionChange = aSelection => { tipWrapper.onSelectionChange = null; resolve(aSelection); }; }); } function waitForTicks() { return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)) ); } function promiseConstructingPromiseToWaitForInput(aChar) { return SpecialPowers.spawn(browser, [aChar], ch => { const textarea = content.document.querySelector("textarea"); content.wrappedJSObject.promiseInput = new Promise(resolve => { function onInput() { if (textarea.value.includes(ch)) { textarea.removeEventListener("input", onInput); resolve(textarea.value); } } textarea.addEventListener("input", onInput); }); }); } function promiseGetTextAreaValueAfterInput() { return SpecialPowers.spawn(browser, [], () => { return content.wrappedJSObject.promiseInput; }); } await SpecialPowers.spawn(browser, [], () => { const textarea = content.document.querySelector("textarea"); textarea.focus(); }); await waitForTicks(); const windowUtils = window.windowUtils; // { const waitForSelectionChange = promiseSelectionChange(); await BrowserTestUtils.synthesizeKey("a", {}, browser); info(`Waiting for a selection change after inserting "a"...`); const selectionCache = await waitForSelectionChange; Assert.equal( selectionCache?.offset, 1, `Selection offset should be 1 after inserting "a"` ); } // await promiseConstructingPromiseToWaitForInput("A"); windowUtils.sendContentCommandEvent( "replaceText", null, "A", Math.max(tipWrapper.selectionCache?.offset - 1, 0), "a" ); info(`Waiting for