tor-browser

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

commit 42f5c9811494b98304c4eea31baf2e0a56d26600
parent 6e55eaa041e15b85df9afde96af7d139e6730024
Author: Erik Nordin <enordin@mozilla.com>
Date:   Wed,  1 Oct 2025 16:07:09 +0000

Bug 1991224 - Wait for more paints in `about:translations` tests r=translations-reviewers,gregtatum

This patch ensures that the AboutTranslationsTestUtils
waits for the browser to paint in between assertions.

This shouldn't have any effect on intermittents, nor
should it significantly slow down tests.

I just like to be able to see what actually happens
when I'm running the tests without `--headless`,
where as without this the test sometimes completes
before the change has even visually occurred.

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

Diffstat:
Mtoolkit/components/translations/tests/browser/shared-head.js | 36++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+), 0 deletions(-)

diff --git a/toolkit/components/translations/tests/browser/shared-head.js b/toolkit/components/translations/tests/browser/shared-head.js @@ -3169,6 +3169,9 @@ class AboutTranslationsTestUtils { * @returns {Promise<void>} */ async assertEvents({ expected = [], unexpected = [] } = {}, callback) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + try { const expectedEventWaiters = Object.fromEntries( expected.map(([eventName]) => [eventName, this.waitForEvent(eventName)]) @@ -3211,6 +3214,9 @@ class AboutTranslationsTestUtils { } catch (error) { AboutTranslationsTestUtils.#reportTestFailure(error); } + + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); } /** @@ -3227,6 +3233,9 @@ class AboutTranslationsTestUtils { showsPlaceholder, scriptDirection, } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let pageResult = {}; try { pageResult = await this.#runInPage( @@ -3292,6 +3301,9 @@ class AboutTranslationsTestUtils { showsPlaceholder, scriptDirection, } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let pageResult = {}; try { pageResult = await this.#runInPage( @@ -3357,6 +3369,9 @@ class AboutTranslationsTestUtils { options, detectedLanguage, } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let pageResult = {}; try { pageResult = await this.#runInPage(selectors => { @@ -3427,6 +3442,9 @@ class AboutTranslationsTestUtils { * @returns {Promise<void>} */ async assertTargetLanguageSelector({ value, options } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let pageResult = {}; try { pageResult = await this.#runInPage( @@ -3488,6 +3506,9 @@ class AboutTranslationsTestUtils { defaultValue, language, } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + if (language !== undefined && defaultValue) { throw new Error( "assertDetectLanguageOption: `language` and `defaultValue: true` are mutually exclusive." @@ -3568,6 +3589,9 @@ class AboutTranslationsTestUtils { * @returns {Promise<void>} */ async assertSwapLanguagesButton({ enabled } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let pageResult = {}; try { pageResult = await this.#runInPage( @@ -3602,6 +3626,9 @@ class AboutTranslationsTestUtils { * @returns {Promise<void>} */ async assertTranslatingPlaceholder() { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + let actualValue; try { actualValue = await this.#runInPage(selectors => { @@ -3637,6 +3664,9 @@ class AboutTranslationsTestUtils { targetLanguage, sourceText, }) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + if (sourceLanguage !== undefined && detectedLanguage !== undefined) { throw new Error( "assertTranslatedText: sourceLanguage and detectedLanguage are mutually exclusive assertion options." @@ -3694,6 +3724,9 @@ class AboutTranslationsTestUtils { targetLanguage = "", sourceText = "", } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + try { // First verify that the UI controls contain the expected values. await this.assertSourceLanguageSelector({ value: sourceLanguage }); @@ -3787,6 +3820,9 @@ class AboutTranslationsTestUtils { unsupportedInfoMessage = false, languageLoadErrorMessage = false, } = {}) { + // This helps the test visually render at each step without significantly slowing test speed. + await doubleRaf(document); + try { const visibilityMap = await this.#runInPage(selectors => { const { document, window } = content;