зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1834014 - Update always- and never-translate menuitem tests r=gregtatum
Depends on D178512 Differential Revision: https://phabricator.services.mozilla.com/D178513
This commit is contained in:
Родитель
5e165ee981
Коммит
f97cfaa407
|
@ -4,10 +4,11 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* Tests the effects that toggling the always-translate-languages menuitem
|
||||
* has on subsequent page loads.
|
||||
* Tests the effect of toggling the always-translate-language menuitem.
|
||||
* Checking the box on an untranslated page should immediately translate the page.
|
||||
* Unchecking the box on a translated page should immediately restore the page.
|
||||
*/
|
||||
add_task(async function test_page_loads_with_always_translate_language() {
|
||||
add_task(async function test_toggle_always_translate_language_menuitem() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
|
@ -15,8 +16,8 @@ add_task(async function test_page_loads_with_always_translate_language() {
|
|||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The translations button is visible."
|
||||
);
|
||||
|
||||
info(
|
||||
|
@ -34,14 +35,57 @@ add_task(async function test_page_loads_with_always_translate_language() {
|
|||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"adding the document language from the alwaysTranslateLanguages pref"
|
||||
"adding the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
resolveDownloads(1);
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
info(
|
||||
"The page should now be automatically translated because the document language " +
|
||||
"should be added to the always-translate pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is translated automatically",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info("Navigate to a different Spanish page");
|
||||
await navigate(SPANISH_PAGE_URL_DOT_ORG);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
info(
|
||||
"The page should now be automatically translated because the document language " +
|
||||
|
@ -61,9 +105,15 @@ add_task(async function test_page_loads_with_always_translate_language() {
|
|||
"removing the document language from the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"Only the button appears"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should no longer automatically translated because the document language " +
|
||||
|
@ -80,3 +130,284 @@ add_task(async function test_page_loads_with_always_translate_language() {
|
|||
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests the effect of toggling the always-translate-language menuitem after the page has
|
||||
* been manually translated. This should not reload or retranslate the page, but just check
|
||||
* the box.
|
||||
*/
|
||||
add_task(
|
||||
async function test_activate_always_translate_language_after_manual_translation() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [["browser.translations.alwaysTranslateLanguages", "pl,fr"]],
|
||||
});
|
||||
|
||||
const { button } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button is available."
|
||||
);
|
||||
|
||||
info(
|
||||
'The document language "es" is not in the alwaysTranslateLanguages pref, ' +
|
||||
"so the page should be untranslated, in its original form"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popupshown", () => {
|
||||
click(button, "Opening the popup");
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popuphidden", () => {
|
||||
click(
|
||||
getByL10nId("translations-panel-default-translate-button"),
|
||||
"Start translating by clicking the translate button."
|
||||
);
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"adding the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The continues to present the locale without pending downloads."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu " +
|
||||
"removing the document language from the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"Only the button appears"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should no longer automatically translated because the document language " +
|
||||
"should be removed from the always-translate pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Tests the effect of unchecking the always-translate language menuitem after the page has
|
||||
* been manually restored to its original form.
|
||||
* This should have no effect on the page, and further page loads should no longer auto-translate.
|
||||
*/
|
||||
add_task(
|
||||
async function test_deactivate_always_translate_language_after_restore() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [["browser.translations.alwaysTranslateLanguages", "pl,fr"]],
|
||||
});
|
||||
|
||||
const { button } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The translations button is visible."
|
||||
);
|
||||
|
||||
info(
|
||||
'The document language "es" is not in the alwaysTranslateLanguages pref, ' +
|
||||
"so the page should be untranslated, in its original form"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"adding the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
info(
|
||||
"The page should now be automatically translated because the document language " +
|
||||
"should be added to the always-translate pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is translated automatically",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_DOT_ORG,
|
||||
"Navigate to a different Spanish page"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
info(
|
||||
"The page should now be automatically translated because the document language " +
|
||||
"should be added to the always-translate pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is translated automatically",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popupshown", () => {
|
||||
click(button, "Re-opening the popup");
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popuphidden", () => {
|
||||
click(
|
||||
getByL10nId("translations-panel-revisit-restore-button"),
|
||||
"Click the restore language button."
|
||||
);
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button is reverted to have an icon."
|
||||
);
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is restored to Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"removing the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button shows only the icon."
|
||||
);
|
||||
|
||||
await navigate(SPANISH_PAGE_URL_DOT_ORG, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button shows only the icon."
|
||||
);
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is restored to Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* Tests the effect that toggling the never-translate-languages menuitem
|
||||
* has on subsequent page loads.
|
||||
* Tests the effect of toggling the never-translate-language menuitem.
|
||||
* Checking the box on an untranslated page should immediately hide the button.
|
||||
* The button should not appear again for sites in the disabled language.
|
||||
*/
|
||||
add_task(async function test_page_loads_with_never_translate_language() {
|
||||
add_task(async function test_toggle_never_translate_language_menuitem() {
|
||||
const { cleanup, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
|
@ -15,8 +16,8 @@ add_task(async function test_page_loads_with_never_translate_language() {
|
|||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The translations button is visible."
|
||||
);
|
||||
|
||||
info(
|
||||
|
@ -37,10 +38,53 @@ add_task(async function test_page_loads_with_never_translate_language() {
|
|||
"adding the document language from the neverTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
await toggleNeverTranslateLanguage();
|
||||
|
||||
// Reload the page
|
||||
await navigate(SPANISH_PAGE_URL);
|
||||
await assertIsNeverTranslateLanguage("es", false);
|
||||
await toggleNeverTranslateLanguage();
|
||||
await assertIsNeverTranslateLanguage("es", true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_DOT_ORG,
|
||||
"Navigate to a different Spanish page"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
|
@ -62,3 +106,238 @@ add_task(async function test_page_loads_with_never_translate_language() {
|
|||
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests the effect of toggling the never-translate-language menuitem on a page where
|
||||
* where translation is already active.
|
||||
* Checking the box on a translated page should restore the page and hide the button.
|
||||
* The button should not appear again for sites in the disabled language.
|
||||
*/
|
||||
add_task(
|
||||
async function test_toggle_never_translate_language_menuitem_with_active_translations() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [["browser.translations.neverTranslateLanguages", "pl,fr"]],
|
||||
});
|
||||
|
||||
const { button } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button is available."
|
||||
);
|
||||
|
||||
info(
|
||||
'The document language "es" is not in the alwaysTranslateLanguages pref, ' +
|
||||
"so the page should be untranslated, in its original form"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popupshown", () => {
|
||||
click(button, "Opening the popup");
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popuphidden", () => {
|
||||
click(
|
||||
getByL10nId("translations-panel-default-translate-button"),
|
||||
"Start translating by clicking the translate button."
|
||||
);
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking never-translate-language in the settings menu, " +
|
||||
"adding the document language from the neverTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsNeverTranslateLanguage("es", false);
|
||||
await toggleNeverTranslateLanguage();
|
||||
await assertIsNeverTranslateLanguage("es", true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Tests the effect of toggling the never-translate-language menuitem on a page where
|
||||
* where translation is already active via always-translate.
|
||||
* Checking the box on a translated page should restore the page and hide the button.
|
||||
* The language should be moved from always-translate to never-translate.
|
||||
* The button should not appear again for sites in the disabled language.
|
||||
*/
|
||||
add_task(
|
||||
async function test_toggle_never_translate_language_menuitem_with_always_translate_active() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [
|
||||
["browser.translations.alwaysTranslateLanguages", "uk,it"],
|
||||
["browser.translations.neverTranslateLanguages", "pl,fr"],
|
||||
],
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button is available."
|
||||
);
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"adding the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await assertIsNeverTranslateLanguage("es", false);
|
||||
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await assertIsNeverTranslateLanguage("es", false);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking never-translate-language in the settings menu, " +
|
||||
"adding the document language from the neverTranslateLanguages pref " +
|
||||
"and removing it from the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await assertIsNeverTranslateLanguage("es", false);
|
||||
|
||||
await toggleNeverTranslateLanguage();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await assertIsNeverTranslateLanguage("es", true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should still be in its original, untranslated form because " +
|
||||
"the document language is in the neverTranslateLanguages pref"
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* Tests the effects that the never-translate-site menuitem has on
|
||||
* subsequent page loads.
|
||||
* Tests the effect of toggling the never-translate-site menuitem.
|
||||
* Checking the box on an untranslated page should immediately hide the button.
|
||||
* The button should not appear again for sites that share the same content principal
|
||||
* of the disabled site.
|
||||
*/
|
||||
add_task(async function test_page_loads_with_never_translate_site() {
|
||||
add_task(async function test_toggle_never_translate_site_menuitem() {
|
||||
const { cleanup, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
|
@ -15,13 +17,13 @@ add_task(async function test_page_loads_with_never_translate_site() {
|
|||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The translations button is visible."
|
||||
);
|
||||
|
||||
info(
|
||||
'The document language "es" is not in the alwaysTranslateLanguages pref, ' +
|
||||
"so the page should be untranslated, in its original form"
|
||||
"Translations permissions are currently allowed for this test page " +
|
||||
"and the page should be untranslated, in its original form."
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
|
@ -32,22 +34,22 @@ add_task(async function test_page_loads_with_never_translate_site() {
|
|||
);
|
||||
});
|
||||
|
||||
info("Disallow translations for this site");
|
||||
info(
|
||||
"Simulate clicking never-translate-site in the settings menu, " +
|
||||
"denying translations permissions for this content window principal"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, false);
|
||||
await toggleNeverTranslateSite();
|
||||
|
||||
info("Reload the page");
|
||||
await navigate(SPANISH_PAGE_URL);
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should no longer automatically translated because the site " +
|
||||
"no longer has permissions to be translated"
|
||||
);
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
|
@ -57,18 +59,14 @@ add_task(async function test_page_loads_with_never_translate_site() {
|
|||
);
|
||||
});
|
||||
|
||||
info("Go to another page from the same site principal");
|
||||
await navigate(SPANISH_PAGE_URL_2);
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"This page should also be untranslated because the entire site " +
|
||||
"no longer has permissions to be translated"
|
||||
);
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
|
@ -78,18 +76,38 @@ add_task(async function test_page_loads_with_never_translate_site() {
|
|||
);
|
||||
});
|
||||
|
||||
info("Go to another page from another site principal");
|
||||
await navigate(SPANISH_PAGE_URL_DOT_ORG);
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_2,
|
||||
"Navigate to a Spanish page with the same content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
{ button: false },
|
||||
"The translations button should be invisible, because this content principal is denied"
|
||||
);
|
||||
|
||||
info(
|
||||
"This page should be untranslated because there are no auto-translate " +
|
||||
"preferences set in this test"
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_DOT_ORG,
|
||||
"Navigate to a Spanish page with a different content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be visible, because this content principal " +
|
||||
"has not been denied translations permissions"
|
||||
);
|
||||
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
|
@ -103,54 +121,238 @@ add_task(async function test_page_loads_with_never_translate_site() {
|
|||
});
|
||||
|
||||
/**
|
||||
* Tests the effects that the never-translate-site menuitem has on
|
||||
* subsequent page loads when always-translate-language is active.
|
||||
* Tests the effect of toggling the never-translate-site menuitem on a page where
|
||||
* where translation is already active.
|
||||
* Checking the box on a translated page should restore the page and hide the button.
|
||||
* The button should not appear again for sites that share the same content principal
|
||||
* of the disabled site.
|
||||
*/
|
||||
add_task(
|
||||
async function test_page_loads_with_always_translate_language_and_never_translate_site() {
|
||||
async function test_toggle_never_translate_site_menuitem_with_active_translations() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [["browser.translations.alwaysTranslateLanguages", "es"]],
|
||||
permissionsUrls: [SPANISH_PAGE_URL],
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
const { button } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The translations button is visible."
|
||||
);
|
||||
|
||||
resolveDownloads(1);
|
||||
|
||||
info(
|
||||
"The page should be automatically translated because the document language " +
|
||||
"should be in the alwaysTranslateLanguages"
|
||||
"Translations permissions are currently allowed for this test page " +
|
||||
"and the page should be untranslated, in its original form."
|
||||
);
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is translated automatically",
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popupshown", () => {
|
||||
click(button, "Opening the popup");
|
||||
});
|
||||
|
||||
await waitForTranslationsPopupEvent("popuphidden", () => {
|
||||
click(
|
||||
getByL10nId("translations-panel-default-translate-button"),
|
||||
"Start translating by clicking the translate button."
|
||||
);
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info("Disallow translations for this site");
|
||||
info(
|
||||
"Simulate clicking never-translate-site in the settings menu, " +
|
||||
"denying translations permissions for this content window principal"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, false);
|
||||
await toggleNeverTranslateSite();
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_2,
|
||||
"Navigate to a Spanish page with the same content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible, because this content principal is denied"
|
||||
);
|
||||
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_DOT_ORG,
|
||||
"Navigate to a Spanish page with a different content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be visible, because this content principal " +
|
||||
"has not been denied translations permissions"
|
||||
);
|
||||
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Tests the effect of toggling the never-translate-site menuitem on a page where
|
||||
* where translation is already active via always-translate.
|
||||
* Checking the box on a translated page should restore the page and hide the button.
|
||||
* The button should not appear again for sites that share the same content principal
|
||||
* of the disabled site, and no auto-translation should occur.
|
||||
* Other sites should still auto-translate for this language.
|
||||
*/
|
||||
add_task(
|
||||
async function test_toggle_never_translate_site_menuitem_with_always_translate_active() {
|
||||
const { cleanup, resolveDownloads, runInPage } = await loadTestPage({
|
||||
page: SPANISH_PAGE_URL,
|
||||
languagePairs: LANGUAGE_PAIRS,
|
||||
prefs: [["browser.translations.alwaysTranslateLanguages", "uk,it"]],
|
||||
permissionsUrls: [SPANISH_PAGE_URL],
|
||||
});
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: false, icon: true },
|
||||
"The button is available."
|
||||
);
|
||||
|
||||
info(
|
||||
"Simulate clicking always-translate-language in the settings menu, " +
|
||||
"adding the document language to the alwaysTranslateLanguages pref"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", false);
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, false);
|
||||
|
||||
await toggleAlwaysTranslateLanguage();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, false);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
const { locale } = await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Simulate clicking never-translate-site in the settings menu, " +
|
||||
"denying translations permissions for this content window principal"
|
||||
);
|
||||
await openSettingsMenu();
|
||||
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, false);
|
||||
|
||||
await toggleNeverTranslateSite();
|
||||
|
||||
info("Reload the page");
|
||||
await navigate(SPANISH_PAGE_URL);
|
||||
await assertIsAlwaysTranslateLanguage("es", true);
|
||||
await assertIsNeverTranslateSite(SPANISH_PAGE_URL, true);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"The page should no longer automatically translated because the site " +
|
||||
"no longer has permissions to be translated"
|
||||
);
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
|
@ -160,18 +362,14 @@ add_task(
|
|||
);
|
||||
});
|
||||
|
||||
info("Go to another page from the same site principal");
|
||||
await navigate(SPANISH_PAGE_URL_2);
|
||||
await navigate(SPANISH_PAGE_URL, "Reload the page");
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: false },
|
||||
"The translations button should be invisible"
|
||||
);
|
||||
|
||||
info(
|
||||
"This page should also be untranslated because the entire site " +
|
||||
"no longer has permissions to be translated"
|
||||
);
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
|
@ -181,24 +379,49 @@ add_task(
|
|||
);
|
||||
});
|
||||
|
||||
info("Go to another page from a different site principal");
|
||||
await navigate(SPANISH_PAGE_URL_DOT_ORG);
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_2,
|
||||
"Navigate to a Spanish page with the same content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true },
|
||||
"The translations button should be visible"
|
||||
{ button: false },
|
||||
"The translations button should be invisible, because this content principal is denied"
|
||||
);
|
||||
|
||||
resolveDownloads(1);
|
||||
|
||||
info(
|
||||
"The page should be automatically translated because the document language " +
|
||||
"should be in the alwaysTranslateLanguages and this is a different site principal"
|
||||
);
|
||||
info("The page should still be in its original, untranslated form");
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The page's H1 is translated automatically",
|
||||
"The page's H1 is in Spanish.",
|
||||
getH1,
|
||||
"Don Quijote de La Mancha"
|
||||
);
|
||||
});
|
||||
|
||||
await navigate(
|
||||
SPANISH_PAGE_URL_DOT_ORG,
|
||||
"Navigate to a Spanish page with a different content principal"
|
||||
);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: true, locale: false, icon: true },
|
||||
"The icon presents the loading indicator."
|
||||
);
|
||||
|
||||
await resolveDownloads(1);
|
||||
|
||||
await assertTranslationsButton(
|
||||
{ button: true, circleArrows: false, locale: true, icon: true },
|
||||
"The icon presents the locale."
|
||||
);
|
||||
|
||||
is(locale.innerText, "en", "The English language tag is shown.");
|
||||
|
||||
await runInPage(async TranslationsTest => {
|
||||
const { getH1 } = TranslationsTest.getSelectors();
|
||||
await TranslationsTest.assertTranslationResult(
|
||||
"The pages H1 is translated.",
|
||||
getH1,
|
||||
"DON QUIJOTE DE LA MANCHA [es to en, html]"
|
||||
);
|
||||
|
|
|
@ -230,6 +230,7 @@ function isVisible(element) {
|
|||
* The `l10nId` represents the text that a user would actually see.
|
||||
*
|
||||
* @param {string} l10nId
|
||||
* @param {Document} doc
|
||||
* @returns {Element}
|
||||
*/
|
||||
function getByL10nId(l10nId, doc = document) {
|
||||
|
@ -245,6 +246,21 @@ function getByL10nId(l10nId, doc = document) {
|
|||
throw new Error("The element is not visible in the DOM: " + l10nId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all elements that match the l10n id.
|
||||
*
|
||||
* @param {string} l10nId
|
||||
* @param {Document} doc
|
||||
* @returns {Element}
|
||||
*/
|
||||
function getAllByL10nId(l10nId, doc = document) {
|
||||
const elements = doc.querySelectorAll(`[data-l10n-id="${l10nId}"]`);
|
||||
if (elements.length === 0) {
|
||||
throw new Error("Could not find the element by l10n id: " + l10nId);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {Document} [doc]
|
||||
|
|
Загрузка…
Ссылка в новой задаче