From cd9b1a656c26b7d376100e0c6ab6a49960e6ac70 Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Mon, 13 Jan 2025 14:39:33 +0000 Subject: [PATCH] Bug 1845152 - [devtools] Make sure the input is focused before triggering keyboard event in setProperty. r=devtools-reviewers,ochameau a=test-only Differential Revision: https://phabricator.services.mozilla.com/D233821 --- devtools/client/inspector/test/shared-head.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index 9e82d7e0870e..6d46be3f4d31 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -565,9 +565,7 @@ var focusEditableField = async function ( await onFocus; info("Editable field gained focus, returning the input field now"); - const onEdit = inplaceEditor(editable.ownerDocument.activeElement); - - return onEdit; + return inplaceEditor(editable.ownerDocument.activeElement); }; /** @@ -1083,7 +1081,7 @@ async function setProperty( { blurNewProperty = true, flushCount = 1 } = {} ) { info("Set property to: " + value); - await focusEditableField(ruleView, textProp.editor.valueSpan); + const editor = await focusEditableField(ruleView, textProp.editor.valueSpan); // Because of the manual flush approach used for tests, we might have an // unknown number of debounced "preview" requests . Each preview should @@ -1104,6 +1102,11 @@ async function setProperty( await onPopupOpened; } else { await wait(500); + // Since some time have passed since we made the input visible and focused it, + // we might have some previous async work that causes the input to be blurred + // (see intermittent Bug 1845152). + // Make sure the input is focused before triggering the keyboard event. + editor.input.focus(); EventUtils.sendString(value, ruleView.styleWindow); } @@ -1138,6 +1141,11 @@ async function setProperty( onPopupClosed = once(ruleView.popup, "popup-closed"); } + // Since some time have passed since we made the input visible and focused it, + // we might have some previous async work that causes the input to be blurred + // (see intermittent Bug 1845152). + // Make sure the input is focused before triggering the keyboard event. + editor.input.focus(); EventUtils.synthesizeKey( blurNewProperty ? "VK_RETURN" : "VK_TAB", {},