summaryrefslogtreecommitdiffstats
path: root/browser/components/translations/tests/browser/browser_translations_select_panel_fallback_to_doc_language.js
blob: d2c6f42486e24e83e9305fb3778dfb299b116934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test case tests the case of opening the SelectTranslationsPanel when the
 * detected language is unsupported, but the page language is known to be a supported
 * language. The panel should automatically fall back to the page language in an
 * effort to combat falsely identified selections.
 */
add_task(
  async function test_select_translations_panel_translate_sentence_on_open() {
    const { cleanup, runInPage, resolveDownloads } = await loadTestPage({
      page: SELECT_TEST_PAGE_URL,
      languagePairs: [
        // Do not include French.
        { fromLang: "es", toLang: "en" },
        { fromLang: "en", toLang: "es" },
      ],
      prefs: [["browser.translations.select.enable", true]],
    });

    await SelectTranslationsTestUtils.openPanel(runInPage, {
      selectFrenchSentence: true,
      openAtFrenchSentence: true,
      // French is not supported, but the page is in Spanish, so expect Spanish.
      expectedFromLanguage: "es",
      expectedToLanguage: "en",
      downloadHandler: resolveDownloads,
      onOpenPanel: SelectTranslationsTestUtils.assertPanelViewTranslated,
    });

    await SelectTranslationsTestUtils.clickDoneButton();

    await cleanup();
  }
);