diff options
Diffstat (limited to 'browser/components/translations/tests/browser/browser_translations_select_context_menu_with_text_selected.js')
-rw-r--r-- | browser/components/translations/tests/browser/browser_translations_select_context_menu_with_text_selected.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/browser/components/translations/tests/browser/browser_translations_select_context_menu_with_text_selected.js b/browser/components/translations/tests/browser/browser_translations_select_context_menu_with_text_selected.js new file mode 100644 index 0000000000..deb5911a37 --- /dev/null +++ b/browser/components/translations/tests/browser/browser_translations_select_context_menu_with_text_selected.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * This test case verifies the functionality of the translate-selection context menu item + * when the selected text is not in the user's preferred language. The menu item should be + * localized to translate to the target language matching the user's top preferred language + * when the selected text is detected to be in a different language. + */ +add_task( + async function test_translate_selection_menuitem_when_selected_text_is_not_preferred_language() { + const { cleanup, runInPage } = await loadTestPage({ + page: SPANISH_PAGE_URL, + languagePairs: LANGUAGE_PAIRS, + prefs: [["browser.translations.select.enable", true]], + }); + + await FullPageTranslationsTestUtils.assertTranslationsButton( + { button: true, circleArrows: false, locale: false, icon: true }, + "The button is available." + ); + + await FullPageTranslationsTestUtils.assertPageIsUntranslated(runInPage); + + await SelectTranslationsTestUtils.assertContextMenuTranslateSelectionItem( + runInPage, + { + selectSpanishParagraph: true, + openAtSpanishParagraph: true, + expectMenuItemVisible: true, + expectedTargetLanguage: "en", + }, + "The translate-selection context menu item should display a target language " + + "when the selected text is not the preferred language." + ); + + await cleanup(); + } +); + +/** + * This test case verifies the functionality of the translate-selection context menu item + * when the selected text is detected to be in the user's preferred language. The menu item + * should not be localized to display a target language when the selected text matches the + * user's top preferred language. + */ +add_task( + async function test_translate_selection_menuitem_when_selected_text_is_preferred_language() { + const { cleanup, runInPage } = await loadTestPage({ + page: ENGLISH_PAGE_URL, + languagePairs: LANGUAGE_PAIRS, + prefs: [["browser.translations.select.enable", true]], + }); + + await FullPageTranslationsTestUtils.assertTranslationsButton( + { button: false }, + "The button is available." + ); + + await SelectTranslationsTestUtils.assertContextMenuTranslateSelectionItem( + runInPage, + { + selectFirstParagraph: true, + openAtFirstParagraph: true, + expectMenuItemVisible: true, + expectedTargetLanguage: null, + }, + "The translate-selection context menu item should not display a target language " + + "when the selected text is in the preferred language." + ); + + await cleanup(); + } +); |