diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /toolkit/components/translations/tests/browser | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/translations/tests/browser')
6 files changed, 199 insertions, 73 deletions
diff --git a/toolkit/components/translations/tests/browser/browser.toml b/toolkit/components/translations/tests/browser/browser.toml index 50a1be7150..c940bea9a0 100644 --- a/toolkit/components/translations/tests/browser/browser.toml +++ b/toolkit/components/translations/tests/browser/browser.toml @@ -9,6 +9,7 @@ support-files = [ "translations-tester-es-2.html", "translations-tester-fr.html", "translations-tester-no-tag.html", + "translations-tester-select.html", "translations-tester-shadow-dom-es.html", "translations-tester-shadow-dom-mutation-es.html", "translations-tester-shadow-dom-mutation-es-2.html", diff --git a/toolkit/components/translations/tests/browser/browser_about_translations_dropdowns.js b/toolkit/components/translations/tests/browser/browser_about_translations_dropdowns.js index 6aed512952..381903e5b1 100644 --- a/toolkit/components/translations/tests/browser/browser_about_translations_dropdowns.js +++ b/toolkit/components/translations/tests/browser/browser_about_translations_dropdowns.js @@ -13,7 +13,7 @@ add_task(async function test_about_translations_dropdowns() { await openAboutTranslations({ languagePairs, dataForContent: languagePairs, - runInPage: async ({ dataForContent: languagePairs, selectors }) => { + runInPage: async ({ selectors }) => { const { document } = content; await ContentTaskUtils.waitForCondition( diff --git a/toolkit/components/translations/tests/browser/shared-head.js b/toolkit/components/translations/tests/browser/shared-head.js index 82b3e783a7..afa060c8a3 100644 --- a/toolkit/components/translations/tests/browser/shared-head.js +++ b/toolkit/components/translations/tests/browser/shared-head.js @@ -9,6 +9,9 @@ const { EngineProcess } = ChromeUtils.importESModule( "chrome://global/content/ml/EngineProcess.sys.mjs" ); +const { TranslationsPanelShared } = ChromeUtils.importESModule( + "chrome://browser/content/translations/TranslationsPanelShared.sys.mjs" +); // Avoid about:blank's non-standard behavior. const BLANK_PAGE = @@ -32,6 +35,8 @@ const NO_LANGUAGE_URL = URL_COM_PREFIX + DIR_PATH + "translations-tester-no-tag.html"; const EMPTY_PDF_URL = URL_COM_PREFIX + DIR_PATH + "translations-tester-empty-pdf-file.pdf"; +const SELECT_TEST_PAGE_URL = + URL_COM_PREFIX + DIR_PATH + "translations-tester-select.html"; const PIVOT_LANGUAGE = "en"; const LANGUAGE_PAIRS = [ @@ -349,33 +354,37 @@ function getTranslationsParent() { /** * Closes all open panels and menu popups related to Translations. + * + * @param {ChromeWindow} [win] */ -async function closeAllOpenPanelsAndMenus() { - await closeSettingsMenuIfOpen(); - await closeFullPageTranslationsPanelIfOpen(); - await closeSelectTranslationsPanelIfOpen(); - await closeContextMenuIfOpen(); +async function closeAllOpenPanelsAndMenus(win) { + await closeSettingsMenuIfOpen(win); + await closeFullPageTranslationsPanelIfOpen(win); + await closeSelectTranslationsPanelIfOpen(win); + await closeContextMenuIfOpen(win); } /** * Closes the popup element with the given Id if it is open. * * @param {string} popupElementId + * @param {ChromeWindow} [win] */ -async function closePopupIfOpen(popupElementId) { +async function closePopupIfOpen(popupElementId, win = window) { await waitForCondition(async () => { - const contextMenu = document.getElementById(popupElementId); - if (!contextMenu) { + const popupElement = win.document.getElementById(popupElementId); + if (!popupElement) { return true; } - if (contextMenu.state === "closed") { + if (popupElement.state === "closed") { return true; } let popuphiddenPromise = BrowserTestUtils.waitForEvent( - contextMenu, + popupElement, "popuphidden" ); - PanelMultiView.hidePopup(contextMenu); + popupElement.hidePopup(); + PanelMultiView.hidePopup(popupElement); await popuphiddenPromise; return false; }); @@ -383,30 +392,41 @@ async function closePopupIfOpen(popupElementId) { /** * Closes the context menu if it is open. + * + * @param {ChromeWindow} [win] */ -async function closeContextMenuIfOpen() { - await closePopupIfOpen("contentAreaContextMenu"); +async function closeContextMenuIfOpen(win) { + await closePopupIfOpen("contentAreaContextMenu", win); } /** * Closes the translations panel settings menu if it is open. + * + * @param {ChromeWindow} [win] */ -async function closeSettingsMenuIfOpen() { - await closePopupIfOpen("full-page-translations-panel-settings-menupopup"); +async function closeSettingsMenuIfOpen(win) { + await closePopupIfOpen( + "full-page-translations-panel-settings-menupopup", + win + ); } /** * Closes the translations panel if it is open. + * + * @param {ChromeWindow} [win] */ -async function closeFullPageTranslationsPanelIfOpen() { - await closePopupIfOpen("full-page-translations-panel"); +async function closeFullPageTranslationsPanelIfOpen(win) { + await closePopupIfOpen("full-page-translations-panel", win); } /** * Closes the translations panel if it is open. + * + * @param {ChromeWindow} [win] */ -async function closeSelectTranslationsPanelIfOpen() { - await closePopupIfOpen("select-translations-panel"); +async function closeSelectTranslationsPanelIfOpen(win) { + await closePopupIfOpen("select-translations-panel", win); } /** @@ -471,6 +491,7 @@ async function createAndMockRemoteSettings({ // The TranslationsParent will pull the language pair values from the JSON dump // of Remote Settings. Clear these before mocking the translations engine. TranslationsParent.clearCache(); + TranslationsPanelShared.clearCache(); TranslationsParent.mockTranslationsEngine( remoteClients.translationModels.client, @@ -485,6 +506,7 @@ async function createAndMockRemoteSettings({ TranslationsParent.unmockTranslationsEngine(); TranslationsParent.clearCache(); + TranslationsPanelShared.clearCache(); }, remoteClients, }; @@ -497,38 +519,56 @@ async function loadTestPage({ prefs, autoOffer, permissionsUrls, + win = window, }) { info(`Loading test page starting at url: ${page}`); - // Ensure no engine is being carried over from a previous test. - await EngineProcess.destroyTranslationsEngine(); - Services.fog.testResetFOG(); - await SpecialPowers.pushPrefEnv({ - set: [ - // Enabled by default. - ["browser.translations.enable", true], - ["browser.translations.logLevel", "All"], - ["browser.translations.panelShown", true], - ["browser.translations.automaticallyPopup", true], - ["browser.translations.alwaysTranslateLanguages", ""], - ["browser.translations.neverTranslateLanguages", ""], - ...(prefs ?? []), - ], - }); - await SpecialPowers.pushPermissions( - [ - ENGLISH_PAGE_URL, - FRENCH_PAGE_URL, - NO_LANGUAGE_URL, - SPANISH_PAGE_URL, - SPANISH_PAGE_URL_2, - SPANISH_PAGE_URL_DOT_ORG, - ...(permissionsUrls || []), - ].map(url => ({ - type: TRANSLATIONS_PERMISSION, - allow: true, - context: url, - })) - ); + + // If there are multiple windows, only do the first time setup on the main window. + const isFirstTimeSetup = win === window; + + let remoteClients = null; + let removeMocks = () => {}; + + if (isFirstTimeSetup) { + // Ensure no engine is being carried over from a previous test. + await EngineProcess.destroyTranslationsEngine(); + + Services.fog.testResetFOG(); + await SpecialPowers.pushPrefEnv({ + set: [ + // Enabled by default. + ["browser.translations.enable", true], + ["browser.translations.logLevel", "All"], + ["browser.translations.panelShown", true], + ["browser.translations.automaticallyPopup", true], + ["browser.translations.alwaysTranslateLanguages", ""], + ["browser.translations.neverTranslateLanguages", ""], + ...(prefs ?? []), + ], + }); + await SpecialPowers.pushPermissions( + [ + ENGLISH_PAGE_URL, + FRENCH_PAGE_URL, + NO_LANGUAGE_URL, + SPANISH_PAGE_URL, + SPANISH_PAGE_URL_2, + SPANISH_PAGE_URL_DOT_ORG, + ...(permissionsUrls || []), + ].map(url => ({ + type: TRANSLATIONS_PERMISSION, + allow: true, + context: url, + })) + ); + + const result = await createAndMockRemoteSettings({ + languagePairs, + autoDownloadFromRemoteSettings, + }); + remoteClients = result.remoteClients; + removeMocks = result.removeMocks; + } if (autoOffer) { TranslationsParent.testAutomaticPopup = true; @@ -536,16 +576,11 @@ async function loadTestPage({ // Start the tab at a blank page. const tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, + win.gBrowser, BLANK_PAGE, true // waitForLoad ); - const { remoteClients, removeMocks } = await createAndMockRemoteSettings({ - languagePairs, - autoDownloadFromRemoteSettings, - }); - BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, page); await BrowserTestUtils.browserLoaded(tab.linkedBrowser); @@ -1377,7 +1412,7 @@ async function waitForCloseDialogWindow(dialogWindow) { // Extracted from https://searchfox.org/mozilla-central/rev/40ef22080910c2e2c27d9e2120642376b1d8b8b2/browser/components/preferences/in-content/tests/head.js#41 function promiseLoadSubDialog(aURL) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { content.gSubDialog._dialogStack.addEventListener( "dialogopen", function dialogopen(aEvent) { @@ -1444,3 +1479,10 @@ async function loadBlankPage() { BrowserTestUtils.startLoadingURIString(gBrowser.selectedBrowser, BLANK_PAGE); await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); } + +/** + * Destroys the Translations Engine process. + */ +async function destroyTranslationsEngine() { + await EngineProcess.destroyTranslationsEngine(); +} diff --git a/toolkit/components/translations/tests/browser/translations-test.mjs b/toolkit/components/translations/tests/browser/translations-test.mjs index a740a2d1cc..3ff107a699 100644 --- a/toolkit/components/translations/tests/browser/translations-test.mjs +++ b/toolkit/components/translations/tests/browser/translations-test.mjs @@ -38,21 +38,36 @@ export function getSelectors() { getHeader() { return content.document.querySelector("header"); }, - getFirstParagraph() { - return content.document.querySelector("p:first-of-type"); - }, getLastParagraph() { return content.document.querySelector("p:last-of-type"); }, - getSpanishParagraph() { - return content.document.getElementById("spanish-paragraph"); + getFrenchSection() { + return content.document.getElementById("french-section"); }, - getSpanishHyperlink() { - return content.document.getElementById("spanish-hyperlink"); + getEnglishSection() { + return content.document.getElementById("english-section"); + }, + getSpanishSection() { + return content.document.getElementById("spanish-section"); + }, + getFrenchSentence() { + return content.document.getElementById("french-sentence"); + }, + getEnglishSentence() { + return content.document.getElementById("english-sentence"); + }, + getSpanishSentence() { + return content.document.getElementById("spanish-sentence"); }, getEnglishHyperlink() { return content.document.getElementById("english-hyperlink"); }, + getFrenchHyperlink() { + return content.document.getElementById("french-hyperlink"); + }, + getSpanishHyperlink() { + return content.document.getElementById("spanish-hyperlink"); + }, }; } diff --git a/toolkit/components/translations/tests/browser/translations-tester-es.html b/toolkit/components/translations/tests/browser/translations-tester-es.html index f589df0649..abf2d42c62 100644 --- a/toolkit/components/translations/tests/browser/translations-tester-es.html +++ b/toolkit/components/translations/tests/browser/translations-tester-es.html @@ -20,7 +20,7 @@ <header lang="en">The following is an excerpt from Don Quijote de la Mancha, which is in the public domain</header> <h1>Don Quijote de La Mancha</h1> <h2>Capítulo VIII.</h2> - <p id="spanish-paragraph">Del buen suceso que el valeroso don Quijote tuvo en la espantable y jamás imaginada aventura de los molinos de viento, con otros sucesos dignos de felice recordación</p> + <p>Del buen suceso que el valeroso don Quijote tuvo en la espantable y jamás imaginada aventura de los molinos de viento, con otros sucesos dignos de felice recordación</p> <p>En esto, descubrieron treinta o cuarenta molinos de viento que hay en aquel campo; y, así como don Quijote los vio, dijo a su escudero:</p> <p>— La ventura va guiando nuestras cosas mejor de lo que acertáramos a desear, porque ves allí, amigo Sancho Panza, donde se descubren treinta, o pocos más, desaforados gigantes, con quien pienso hacer batalla y quitarles a todos las vidas, con cuyos despojos comenzaremos a enriquecer; que ésta es buena guerra, y es gran servicio de Dios quitar tan mala simiente de sobre la faz de la tierra.</p> <p>— ¿Qué gigantes? —dijo Sancho Panza.</p> @@ -32,13 +32,5 @@ <p>Levantóse en esto un poco de viento y las grandes aspas comenzaron a moverse, lo cual visto por don Quijote, dijo:</p> <p>— Pues, aunque mováis más brazos que los del gigante Briareo, me lo habéis de pagar.</p> </div> - <div> - <header lang="en">The following is a link to another test page in Spanish.</header> - <p><a id="spanish-hyperlink" href="https://example.org/browser/translations-tester-es.html">Otra pagina en español.</a></p> - </div> - <div> - <header lang="en">The following is a link to another test page in English.</header> - <p lang="en"><a id="english-hyperlink" href="https://example.org/browser/translations-tester-en.html">Another page in English.</a></p> - </div> </body> </html> diff --git a/toolkit/components/translations/tests/browser/translations-tester-select.html b/toolkit/components/translations/tests/browser/translations-tester-select.html new file mode 100644 index 0000000000..034d89a95b --- /dev/null +++ b/toolkit/components/translations/tests/browser/translations-tester-select.html @@ -0,0 +1,76 @@ +<!DOCTYPE html> +<html lang="es"> +<head> + <meta charset="utf-8" /> + <title>Select Translations Test</title> + <style> + div { + margin: 10px auto; + width: 600px + } + p { + margin: 47px 0; + font-size: 21px; + line-height: 2; + } + </style> +</head> +<body> + <div> + <header lang="en">The following is an excerpt from Don Quijote de la Mancha, which is in the public domain</header> + <div id="spanish-section"> + <h1>Don Quijote de La Mancha</h1> + <h2>Capítulo VIII.</h2> + <p id="spanish-sentence">Del buen suceso que el valeroso don Quijote tuvo en la espantable y jamás imaginada aventura de los molinos de viento, con otros sucesos dignos de felice recordación</p> + <p>En esto, descubrieron treinta o cuarenta molinos de viento que hay en aquel campo; y, así como don Quijote los vio, dijo a su escudero:</p> + <p>— La ventura va guiando nuestras cosas mejor de lo que acertáramos a desear, porque ves allí, amigo Sancho Panza, donde se descubren treinta, o pocos más, desaforados gigantes, con quien pienso hacer batalla y quitarles a todos las vidas, con cuyos despojos comenzaremos a enriquecer; que ésta es buena guerra, y es gran servicio de Dios quitar tan mala simiente de sobre la faz de la tierra.</p> + <p>— ¿Qué gigantes? —dijo Sancho Panza.</p> + <p>— Aquellos que allí ves —respondió su amo— de los brazos largos, que los suelen tener algunos de casi dos leguas.</p> + <p>— Mire vuestra merced —respondió Sancho— que aquellos que allí se parecen no son gigantes, sino molinos de viento, y lo que en ellos parecen brazos son las aspas, que, volteadas del viento, hacen andar la piedra del molino.</p> + <p>— Bien parece —respondió don Quijote— que no estás cursado en esto de las aventuras: ellos son gigantes; y si tienes miedo, quítate de ahí, y ponte en oración en el espacio que yo voy a entrar con ellos en fiera y desigual batalla.</p> + <p>Y, diciendo esto, dio de espuelas a su caballo Rocinante, sin atender a las voces que su escudero Sancho le daba, advirtiéndole que, sin duda alguna, eran molinos de viento, y no gigantes, aquellos que iba a acometer. Pero él iba tan puesto en que eran gigantes, que ni oía las voces de su escudero Sancho ni echaba de ver, aunque estaba ya bien cerca, lo que eran; antes, iba diciendo en voces altas:</p> + <p>— Non fuyades, cobardes y viles criaturas, que un solo caballero es el que os acomete.</p> + <p>Levantóse en esto un poco de viento y las grandes aspas comenzaron a moverse, lo cual visto por don Quijote, dijo:</p> + <p>— Pues, aunque mováis más brazos que los del gigante Briareo, me lo habéis de pagar.</p> + </div> + </div> + <div> + <header lang="en">The following is an excerpt from Frankenstein, which is in the public domain</header> + <div id="english-section"> + <h1>Frankenstein</h1> + <h2>Letter 3</h2> + <p>To Mrs. Saville, England.</p> + <p>July 7th, 17—.</p> + <p>My dear Sister,</p> + <p>I write a few lines in haste to say that I am safe—and well advanced on my voyage. This letter will reach England by a merchantman now on its homeward voyage from Archangel; more fortunate than I, who may not see my native land, perhaps, for many years. I am, however, in good spirits: my men are bold and apparently firm of purpose, nor do the floating sheets of ice that continually pass us, indicating the dangers of the region towards which we are advancing, appear to dismay them. We have already reached a very high latitude; but it is the height of summer, and although not so warm as in England, the southern gales, which blow us speedily towards those shores which I so ardently desire to attain, breathe a degree of renovating warmth which I had not expected.</p> + <p>No incidents have hitherto befallen us that would make a figure in a letter. One or two stiff gales and the springing of a leak are accidents which experienced navigators scarcely remember to record, and I shall be well content if nothing worse happen to us during our voyage.</p> + <p>Adieu, my dear Margaret. Be assured that for my own sake, as well as yours, I will not rashly encounter danger. I will be cool, persevering, and prudent.</p> + <p>But success shall crown my endeavours. Wherefore not? Thus far I have gone, tracing a secure way over the pathless seas, the very stars themselves being witnesses and testimonies of my triumph. Why not still proceed over the untamed yet obedient element? What can stop the determined heart and resolved will of man?</p> + <p id="english-sentence">My swelling heart involuntarily pours itself out thus. But I must finish. Heaven bless my beloved sister!</p> + </div> + </div> + <div> + <header lang="en">The following is an excerpt from Les Misérables, which is in the public domain</header> + <div id="french-section"> + <h1>Les Misérables</h1> + <h2>Chapitre II</h2> + <p>Monsieur Myriel devient monseigneur Bienvenu</p> + <p id="french-sentence">Le palais épiscopal de Digne était attenant à l'hôpital.</p> + <p>Le palais épiscopal était un vaste et bel hôtel bâti en pierre au commencement du siècle dernier par monseigneur Henri Puget, docteur en théologie de la faculté de Paris, abbé de Simore, lequel était évêque de Digne en 1712. Ce palais était un vrai logis seigneurial. Tout y avait grand air, les appartements de l'évêque, les salons, les chambres, la cour d'honneur, fort large, avec promenoirs à arcades, selon l'ancienne mode florentine, les jardins plantés de magnifiques arbres. Dans la salle à manger, longue et superbe galerie qui était au rez-de-chaussée et s'ouvrait sur les jardins, monseigneur Henri Puget avait donné à manger en cérémonie le 29 juillet 1714 à messeigneurs Charles Brûlart de Genlis, archevêque-prince d'Embrun, Antoine de Mesgrigny, capucin, évêque de Grasse, Philippe de Vendôme, grand prieur de France, abbé de Saint-Honoré de Lérins, François de Berton de Grillon, évêque-baron de Vence, César de Sabran de Forcalquier, évêque-seigneur de Glandève, et Jean Soanen, prêtre de l'oratoire, prédicateur ordinaire du roi, évêque-seigneur de Senez. Les portraits de ces sept révérends personnages décoraient cette salle, et cette date mémorable, 29 juillet 1714, y était gravée en lettres d'or sur une table de marbre blanc.</p> + <p>L'hôpital était une maison étroite et basse à un seul étage avec un petit jardin. Trois jours après son arrivée, l'évêque visita l'hôpital. La visite terminée, il fit prier le directeur de vouloir bien venir jusque chez lui.</p> + </div> + </div> + <div> + <header lang="en">The following is a link to another test page in Spanish.</header> + <p lang="es"><a id="spanish-hyperlink" href="https://example.org/browser/translations-tester-es.html">Otra pagina en español.</a></p> + </div> + <div> + <header lang="en">The following is a link to another test page in French.</header> + <p lang="fr"><a id="french-hyperlink" href="https://example.org/browser/translations-tester-fr.html">Une autre page en français.</a></p> + </div> + <div> + <header lang="en">The following is a link to another test page in English.</header> + <p lang="en"><a id="english-hyperlink" href="https://example.org/browser/translations-tester-en.html">Another page in English.</a></p> + </div> +</body> +</html> |