summaryrefslogtreecommitdiffstats
path: root/toolkit/components/translations/tests/browser
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/translations/tests/browser')
-rw-r--r--toolkit/components/translations/tests/browser/browser.toml2
-rw-r--r--toolkit/components/translations/tests/browser/browser_translations_actor.js26
-rw-r--r--toolkit/components/translations/tests/browser/browser_translations_pdf_is_disabled.js2
-rw-r--r--toolkit/components/translations/tests/browser/browser_translations_translation_document.js90
-rw-r--r--toolkit/components/translations/tests/browser/shared-head.js30
-rw-r--r--toolkit/components/translations/tests/browser/translations-test.mjs13
-rw-r--r--toolkit/components/translations/tests/browser/translations-tester-empty-pdf-file.pdf0
-rw-r--r--toolkit/components/translations/tests/browser/translations-tester-pdf-file.pdfbin0 -> 150611 bytes
8 files changed, 114 insertions, 49 deletions
diff --git a/toolkit/components/translations/tests/browser/browser.toml b/toolkit/components/translations/tests/browser/browser.toml
index c940bea9a0..acfd83c138 100644
--- a/toolkit/components/translations/tests/browser/browser.toml
+++ b/toolkit/components/translations/tests/browser/browser.toml
@@ -3,7 +3,7 @@ support-files = [
"head.js",
"shared-head.js",
"translations-test.mjs",
- "translations-tester-empty-pdf-file.pdf",
+ "translations-tester-pdf-file.pdf",
"translations-tester-en.html",
"translations-tester-es.html",
"translations-tester-es-2.html",
diff --git a/toolkit/components/translations/tests/browser/browser_translations_actor.js b/toolkit/components/translations/tests/browser/browser_translations_actor.js
index 457d032ea9..03d3e40c91 100644
--- a/toolkit/components/translations/tests/browser/browser_translations_actor.js
+++ b/toolkit/components/translations/tests/browser/browser_translations_actor.js
@@ -232,3 +232,29 @@ add_task(async function test_translating_to_and_from_app_language() {
return cleanup();
});
+
+add_task(async function test_firstVisualChange() {
+ const { cleanup } = await setupActorTest({
+ languagePairs: [{ fromLang: "en", toLang: "es" }],
+ });
+
+ const parent = getTranslationsParent();
+
+ Assert.equal(
+ parent.languageState.hasVisibleChange,
+ false,
+ "No visual translation change has occurred yet"
+ );
+
+ parent.receiveMessage({
+ name: "Translations:ReportFirstVisibleChange",
+ });
+
+ Assert.equal(
+ parent.languageState.hasVisibleChange,
+ true,
+ "A change occurred."
+ );
+
+ return cleanup();
+});
diff --git a/toolkit/components/translations/tests/browser/browser_translations_pdf_is_disabled.js b/toolkit/components/translations/tests/browser/browser_translations_pdf_is_disabled.js
index b3ac09169f..902a5ad248 100644
--- a/toolkit/components/translations/tests/browser/browser_translations_pdf_is_disabled.js
+++ b/toolkit/components/translations/tests/browser/browser_translations_pdf_is_disabled.js
@@ -8,7 +8,7 @@
*/
add_task(async function test_translations_button_disabled_in_pdf() {
const { cleanup } = await loadTestPage({
- page: EMPTY_PDF_URL,
+ page: PDF_TEST_PAGE_URL,
});
const appMenuButton = document.getElementById("PanelUI-menu-button");
diff --git a/toolkit/components/translations/tests/browser/browser_translations_translation_document.js b/toolkit/components/translations/tests/browser/browser_translations_translation_document.js
index d3d56fd387..9119b0ddae 100644
--- a/toolkit/components/translations/tests/browser/browser_translations_translation_document.js
+++ b/toolkit/components/translations/tests/browser/browser_translations_translation_document.js
@@ -12,7 +12,8 @@ const { TranslationsDocument, LRUCache } = ChromeUtils.importESModule(
/**
* @param {string} html
* @param {{
- * mockedTranslatorPort?: (message: string) => Promise<string>
+ * mockedTranslatorPort?: (message: string) => Promise<string>,
+ * mockedReportVisibleChange?: () => void
* }} [options]
*/
async function createDoc(html, options) {
@@ -42,6 +43,7 @@ async function createDoc(html, options) {
() => {
throw new Error("Cannot request a new port");
},
+ options?.mockedReportVisibleChange ?? (() => {}),
performance.now(),
() => performance.now(),
new LRUCache()
@@ -81,12 +83,21 @@ async function createDoc(html, options) {
return { htmlMatches, cleanup, translate, document };
}
-add_task(async function test_translated_div_element() {
- const { translate, htmlMatches, cleanup } = await createDoc(/* html */ `
+add_task(async function test_translated_div_element_and_visible_change() {
+ let hasVisibleChangeOccurred = false;
+ const { translate, htmlMatches, cleanup } = await createDoc(
+ /* html */ `
<div>
This is a simple translation.
</div>
- `);
+ `,
+ {
+ mockedTranslatorPort: createMockedTranslatorPort(),
+ mockedReportVisibleChange: () => {
+ hasVisibleChangeOccurred = true;
+ },
+ }
+ );
translate();
@@ -99,6 +110,7 @@ add_task(async function test_translated_div_element() {
`
);
+ Assert.ok(hasVisibleChangeOccurred, "A visible change was reported.");
cleanup();
});
@@ -197,18 +209,18 @@ add_task(async function test_translated_nested_elements() {
<div class="menu-main-menu-container">
<ul class="menu-list">
<li class="menu-item menu-item-top-level">
- <a href="/" data-moz-translations-id="0">
+ <a href="/">
LATEST WORK
</a>
</li>
<li class="menu-item menu-item-top-level">
- <a href="/category/interactive/" data-moz-translations-id="0">
+ <a href="/category/interactive/">
CREATIVE CODING
</a>
</li>
<li id="menu-id-categories" class="menu-item menu-item-top-level">
- <a href="#" data-moz-translations-id="0">
- <span class="category-arrow" data-moz-translations-id="1">
+ <a href="#">
+ <span class="category-arrow">
CATEGORIES
</span>
</a>
@@ -434,11 +446,11 @@ add_task(async function test_translation_batching() {
aaaa aa a aaaaaa aaaaaaa.
</div>
<div>
- <span data-moz-translations-id="0">
+ <span>
bbbb bbbbbb
</span>
bbbbbbb bbbbbbbbb bb b
- <b data-moz-translations-id="1">
+ <b>
bbbbb
</b>
.
@@ -479,7 +491,7 @@ add_task(async function test_translation_inline_styling() {
aaaa aaaa aa aaaa aa a aaaaa.
<span>
bbbbbb bbbb bb bbbb bb b
- <b data-moz-translations-id="0">
+ <b>
bbbbb
</b>
.
@@ -529,22 +541,22 @@ add_task(async function test_many_inlines() {
"Batching",
/* html */ `
<div>
- <span data-moz-translations-id="0">
+ <span>
aaaa aa a
</span>
- <span data-moz-translations-id="1">
+ <span>
aaaa aaaaaa
</span>
- <span data-moz-translations-id="2">
+ <span>
aaaaaaa aaaa aaaaaaaa
</span>
- <span data-moz-translations-id="3">
+ <span>
aaaa aaaa aaaaaaaa
</span>
- <span data-moz-translations-id="4">
+ <span>
aa aaaa aaaa aaaaaaa
</span>
- <span data-moz-translations-id="5">
+ <span>
aa aaaaa aaaa aaaa.
</span>
</div>
@@ -746,10 +758,10 @@ add_task(async function test_display_none() {
/* html */ `
<p>
aaaa aa aaaa aaaa.
- <span data-moz-translations-id="0">
+ <span>
aa aaa aaaaaa aaaaaaaa
</span>
- <style data-moz-translations-id="1">
+ <style>
</style>
</p>
`
@@ -882,13 +894,13 @@ add_task(async function test_reordering() {
await htmlMatches(
"Nodes can be re-ordered by the translator",
/* html */ `
- <span data-moz-translations-id="1">
+ <span>
A - THIS WAS SECOND.
</span>
- <span data-moz-translations-id="0">
+ <span>
B - THIS WAS FIRST.
</span>
- <span data-moz-translations-id="2">
+ <span>
C - THIS WAS THIRD.
</span>
`
@@ -916,7 +928,7 @@ add_task(async function test_reordering2() {
await htmlMatches(
"Text nodes can be re-ordered.",
/* html */ `
- <span data-moz-translations-id="0">
+ <span>
A - THIS WAS SECOND.
</span>
B - THIS WAS FIRST.
@@ -1271,11 +1283,11 @@ add_task(async function test_title_attribute_subnodes() {
"Titles are translated",
/* html */ `
<div>
- <span data-moz-translations-id="0">SPAN TEXT 1</span>
- <span data-moz-translations-id="1">SPAN TEXT 2</span>
- <span data-moz-translations-id="2">SPAN TEXT 3</span>
- <span data-moz-translations-id="3">SPAN TEXT 4</span>
- <span data-moz-translations-id="4">SPAN TEXT 5</span>
+ <span>SPAN TEXT 1</span>
+ <span>SPAN TEXT 2</span>
+ <span>SPAN TEXT 3</span>
+ <span>SPAN TEXT 4</span>
+ <span>SPAN TEXT 5</span>
THIS IS TEXT.
</div>
`
@@ -1302,11 +1314,11 @@ add_task(async function test_title_attribute_subnodes() {
"Titles are translated",
/* html */ `
<div title="TITLE IN DIV">
- <span title="TITLE 1" data-moz-translations-id="0">SPAN TEXT 1</span>
- <span title="TITLE 2" data-moz-translations-id="1">SPAN TEXT 2</span>
- <span title="TITLE 3" data-moz-translations-id="2">SPAN TEXT 3</span>
- <span title="TITLE 4" data-moz-translations-id="3">SPAN TEXT 4</span>
- <span title="TITLE 5" data-moz-translations-id="4">SPAN TEXT 5</span>
+ <span title="TITLE 1">SPAN TEXT 1</span>
+ <span title="TITLE 2">SPAN TEXT 2</span>
+ <span title="TITLE 3">SPAN TEXT 3</span>
+ <span title="TITLE 4">SPAN TEXT 4</span>
+ <span title="TITLE 5">SPAN TEXT 5</span>
THIS IS TEXT.
</div>
`
@@ -1334,9 +1346,9 @@ add_task(async function test_attributes() {
/* html */ `
<div>
THIS IS THE OUTER DIV
- <label data-moz-translations-id="0">
+ <label>
ENTER INFORMATION:
- <input type="text" data-moz-translations-id="1">
+ <input type="text">
</label>
</div>
`
@@ -1364,9 +1376,9 @@ add_task(async function test_attributes() {
/* html */ `
<div title="TITLES ARE USER VISIBLE">
THIS IS THE OUTER DIV
- <label data-moz-translations-id="0">
+ <label>
ENTER INFORMATION:
- <input type="text" placeholder="THIS IS A PLACEHOLDER" data-moz-translations-id="1">
+ <input type="text" placeholder="THIS IS A PLACEHOLDER">
</label>
</div>
`
@@ -1395,9 +1407,9 @@ add_task(async function test_attributes() {
/* html */ `
<div>
THIS IS THE OUTER DIV
- <label data-moz-translations-id="0">
+ <label>
ENTER INFORMATION 1:
- <label data-moz-translations-id="1">
+ <label>
ENTER INFORMATION 2:
</label>
</label>
diff --git a/toolkit/components/translations/tests/browser/shared-head.js b/toolkit/components/translations/tests/browser/shared-head.js
index afa060c8a3..021534c2e0 100644
--- a/toolkit/components/translations/tests/browser/shared-head.js
+++ b/toolkit/components/translations/tests/browser/shared-head.js
@@ -33,8 +33,8 @@ const SPANISH_PAGE_URL_DOT_ORG =
URL_ORG_PREFIX + DIR_PATH + "translations-tester-es.html";
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 PDF_TEST_PAGE_URL =
+ URL_COM_PREFIX + DIR_PATH + "translations-tester-pdf-file.pdf";
const SELECT_TEST_PAGE_URL =
URL_COM_PREFIX + DIR_PATH + "translations-tester-select.html";
@@ -358,8 +358,9 @@ function getTranslationsParent() {
* @param {ChromeWindow} [win]
*/
async function closeAllOpenPanelsAndMenus(win) {
- await closeSettingsMenuIfOpen(win);
+ await closeFullPagePanelSettingsMenuIfOpen(win);
await closeFullPageTranslationsPanelIfOpen(win);
+ await closeSelectPanelSettingsMenuIfOpen(win);
await closeSelectTranslationsPanelIfOpen(win);
await closeContextMenuIfOpen(win);
}
@@ -400,11 +401,11 @@ async function closeContextMenuIfOpen(win) {
}
/**
- * Closes the translations panel settings menu if it is open.
+ * Closes the full-page translations panel settings menu if it is open.
*
* @param {ChromeWindow} [win]
*/
-async function closeSettingsMenuIfOpen(win) {
+async function closeFullPagePanelSettingsMenuIfOpen(win) {
await closePopupIfOpen(
"full-page-translations-panel-settings-menupopup",
win
@@ -412,6 +413,15 @@ async function closeSettingsMenuIfOpen(win) {
}
/**
+ * Closes the select translations panel settings menu if it is open.
+ *
+ * @param {ChromeWindow} [win]
+ */
+async function closeSelectPanelSettingsMenuIfOpen(win) {
+ await closePopupIfOpen("select-translations-panel-settings-menupopup", win);
+}
+
+/**
* Closes the translations panel if it is open.
*
* @param {ChromeWindow} [win]
@@ -543,6 +553,10 @@ async function loadTestPage({
["browser.translations.automaticallyPopup", true],
["browser.translations.alwaysTranslateLanguages", ""],
["browser.translations.neverTranslateLanguages", ""],
+ // Bug 1893100 - This is needed to ensure that switching focus
+ // with tab works in tests independent of macOS settings that
+ // would otherwise disable keyboard navigation at the OS level.
+ ["accessibility.tabfocus_applies_to_xul", false],
...(prefs ?? []),
],
});
@@ -956,21 +970,21 @@ async function selectAboutPreferencesElements() {
);
const frenchLabel = frenchRow.querySelector("label");
const frenchDownload = frenchRow.querySelector(
- `[data-l10n-id="translations-manage-language-install-button"]`
+ `[data-l10n-id="translations-manage-language-download-button"]`
);
const frenchDelete = frenchRow.querySelector(
`[data-l10n-id="translations-manage-language-remove-button"]`
);
const spanishLabel = spanishRow.querySelector("label");
const spanishDownload = spanishRow.querySelector(
- `[data-l10n-id="translations-manage-language-install-button"]`
+ `[data-l10n-id="translations-manage-language-download-button"]`
);
const spanishDelete = spanishRow.querySelector(
`[data-l10n-id="translations-manage-language-remove-button"]`
);
const ukrainianLabel = ukrainianRow.querySelector("label");
const ukrainianDownload = ukrainianRow.querySelector(
- `[data-l10n-id="translations-manage-language-install-button"]`
+ `[data-l10n-id="translations-manage-language-download-button"]`
);
const ukrainianDelete = ukrainianRow.querySelector(
`[data-l10n-id="translations-manage-language-remove-button"]`
diff --git a/toolkit/components/translations/tests/browser/translations-test.mjs b/toolkit/components/translations/tests/browser/translations-test.mjs
index 3ff107a699..7d9910b9a0 100644
--- a/toolkit/components/translations/tests/browser/translations-test.mjs
+++ b/toolkit/components/translations/tests/browser/translations-test.mjs
@@ -35,6 +35,19 @@ export function getSelectors() {
getH1() {
return content.document.querySelector("h1");
},
+ getPdfSpan() {
+ return ContentTaskUtils.waitForCondition(
+ () =>
+ !!content.document.querySelector(
+ `.page[data-page-number='1'] .textLayer .endOfContent`
+ ),
+ "The text layer must be displayed"
+ ).then(() =>
+ content.document.querySelector(
+ ".page[data-page-number='1'] .textLayer span"
+ )
+ );
+ },
getHeader() {
return content.document.querySelector("header");
},
diff --git a/toolkit/components/translations/tests/browser/translations-tester-empty-pdf-file.pdf b/toolkit/components/translations/tests/browser/translations-tester-empty-pdf-file.pdf
deleted file mode 100644
index e69de29bb2..0000000000
--- a/toolkit/components/translations/tests/browser/translations-tester-empty-pdf-file.pdf
+++ /dev/null
diff --git a/toolkit/components/translations/tests/browser/translations-tester-pdf-file.pdf b/toolkit/components/translations/tests/browser/translations-tester-pdf-file.pdf
new file mode 100644
index 0000000000..7ad87e3c2e
--- /dev/null
+++ b/toolkit/components/translations/tests/browser/translations-tester-pdf-file.pdf
Binary files differ