summaryrefslogtreecommitdiffstats
path: root/browser/components/translations/tests/browser/browser_translations_panel_engine_unsupported.js
blob: f0804f35aa3c263bd1f5633789ed1ab512215191 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that the translations button does not appear when the translations
 * engine is not supported.
 */
add_task(async function test_translations_button_hidden_when_cpu_unsupported() {
  const { cleanup, runInPage } = await loadTestPage({
    page: SPANISH_PAGE_URL,
    languagePairs: LANGUAGE_PAIRS,
    prefs: [["browser.translations.simulateUnsupportedEngine", true]],
  });

  await FullPageTranslationsTestUtils.assertPageIsUntranslated(runInPage);

  await FullPageTranslationsTestUtils.assertTranslationsButton(
    { button: false },
    "The button is not available."
  );

  await cleanup();
});

/**
 * Tests that the translate-page menuitem is not available in the app menu
 * when the translations engine is not supported.
 */
add_task(
  async function test_translate_page_app_menu_item_hidden_when_cpu_unsupported() {
    const { cleanup, runInPage } = await loadTestPage({
      page: SPANISH_PAGE_URL,
      languagePairs: LANGUAGE_PAIRS,
      prefs: [["browser.translations.simulateUnsupportedEngine", true]],
    });

    await FullPageTranslationsTestUtils.assertPageIsUntranslated(runInPage);

    const appMenuButton = getById("PanelUI-menu-button");

    click(appMenuButton, "Opening the app menu");
    await BrowserTestUtils.waitForEvent(window.PanelUI.mainView, "ViewShown");

    const translateSiteButton = document.getElementById(
      "appMenu-translate-button"
    );
    is(
      translateSiteButton.hidden,
      true,
      "The app-menu translate button should be hidden because when the engine is not supported."
    );

    click(appMenuButton, "Closing the app menu");

    await cleanup();
  }
);