summaryrefslogtreecommitdiffstats
path: root/browser/components/translations/tests/browser/browser_translations_full_page_move_tab_to_new_window.js
blob: f384fc59c8ac98da0876bd940fa979ea7549109c (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
60
61
62
63
64
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test case tests a specific situation described in Bug 1893776
 * where the Translations panels were not initializing correctly after
 * dragging a tab to become its own new window after opening the panel
 * in the previous window.
 */
add_task(async function test_browser_translations_full_page_multiple_windows() {
  const window1 = window;
  const testPage = await loadTestPage({
    page: SPANISH_PAGE_URL,
    languagePairs: LANGUAGE_PAIRS,
  });

  await FullPageTranslationsTestUtils.assertTranslationsButton(
    { button: true, circleArrows: false, locale: false, icon: true },
    "The translations button is visible.",
    window1
  );

  info("Opening FullPageTranslationsPanel in window1");
  await FullPageTranslationsTestUtils.openPanel({
    onOpenPanel: FullPageTranslationsTestUtils.assertPanelViewDefault,
  });

  await FullPageTranslationsTestUtils.clickCancelButton();

  info("Moving the tab to a new window of its own");
  const window2 = await window1.gBrowser.replaceTabWithWindow(testPage.tab);
  const swapDocShellPromise = BrowserTestUtils.waitForEvent(
    testPage.tab.linkedBrowser,
    "SwapDocShells"
  );
  await swapDocShellPromise;

  await FullPageTranslationsTestUtils.assertTranslationsButton(
    { button: true, circleArrows: false, locale: false, icon: true },
    "The translations button is visible.",
    window2
  );

  info("Opening FullPageTranslationsPanel in window2");
  await FullPageTranslationsTestUtils.openPanel({
    win: window2,
  });

  info("Translating the same page in window2");
  await FullPageTranslationsTestUtils.clickTranslateButton({
    win: window2,
    downloadHandler: testPage.resolveDownloads,
  });
  await FullPageTranslationsTestUtils.assertLangTagIsShownOnTranslationsButton(
    "es",
    "en",
    window2
  );

  await testPage.cleanup();
  await BrowserTestUtils.closeWindow(window2);
});