tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit fab0ce29d9bad364385b81054fbf656894948f11
parent 973529d127fbfbb49fc7fdb2895feaaa758a698f
Author: Nicolas Chevobbe <nchevobbe@mozilla.com>
Date:   Thu,  2 Oct 2025 14:05:14 +0000

Bug 1985681 - [devtools] Fix browser_rules_completion-existing-property_02.js intermittent failures. r=devtools-reviewers,ochameau.

Listen more accurately for events and wait for the input to have the value we expect.
This is similar to what we did in Bug 1990541 and Bug 1767686.

Differential Revision: https://phabricator.services.mozilla.com/D267180

Diffstat:
Mdevtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js | 54+++++++++++++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js b/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js @@ -42,17 +42,17 @@ const TEST_URI = "<h1 style='color: red'>Header</h1>"; add_task(async function () { await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); - const { toolbox, inspector, view } = await openRuleView(); + const { inspector, view } = await openRuleView(); info("Test autocompletion after 1st page load"); - await runAutocompletionTest(toolbox, inspector, view); + await runAutocompletionTest(inspector, view); info("Test autocompletion after page navigation"); await reloadBrowser(); - await runAutocompletionTest(toolbox, inspector, view); + await runAutocompletionTest(inspector, view); }); -async function runAutocompletionTest(toolbox, inspector, view) { +async function runAutocompletionTest(inspector, view) { info("Selecting the test node"); await selectNode("h1", inspector); @@ -75,40 +75,39 @@ async function testCompletion( editor, view ) { - info("Pressing key " + key); - info("Expecting " + completion); - info("Is popup opened: " + open); - info("Is item selected: " + selected); + info( + `Pressing key "${key}", expecting "${completion}", popup opened: ${open}, item selected: ${selected}` + ); + + const promises = []; - let onDone; if (change) { // If the key triggers a ruleview-changed, wait for that event, it will // always be the last to be triggered and tells us when the preview has // been done. - onDone = view.once("ruleview-changed"); - } else { - // Otherwise, expect an after-suggest event (except if the popup gets - // closed). - onDone = - key !== "VK_RIGHT" && key !== "VK_BACK_SPACE" - ? editor.once("after-suggest") - : null; + promises.push(view.once("ruleview-changed")); + } else if (key !== "VK_RIGHT" && key !== "VK_BACK_SPACE") { + // Otherwise, expect an after-suggest event (except if the autocomplete gets dismissed). + promises.push(editor.once("after-suggest")); } - info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers)); - - // Also listening for popup opened/closed events if needed. - const popupEvent = open ? "popup-opened" : "popup-closed"; - const onPopupEvent = - editor.popup.isOpen !== open ? once(editor.popup, popupEvent) : null; + if (editor.popup.isOpen !== open) { + // if the key does not submit the property name, we only want to wait for popup + // events if the current state of the popup is different from the one that is + // expected after + promises.push(editor.popup.once(open ? "popup-opened" : "popup-closed")); + } + info( + `Synthesizing key "${key}", modifiers: ${JSON.stringify(Object.keys(modifiers))}` + ); EventUtils.synthesizeKey(key, modifiers, view.styleWindow); // Flush the debounce for the preview text. view.debounce.flush(); - await onDone; - await onPopupEvent; + // Wait for all the events + await Promise.all(promises); // The key might have been a TAB or shift-TAB, in which case the editor will // be a new one @@ -116,6 +115,11 @@ async function testCompletion( info("Checking the state"); if (completion !== null) { + try { + await waitFor(() => editor.input.value === completion); + } catch (e) { + // catch the exception so we'll get a nicer failure in the assertion below + } is(editor.input.value, completion, "Correct value is autocompleted"); }