summaryrefslogtreecommitdiffstats
path: root/browser/components/translations/tests/browser/browser_translations_full_page_multiple_windows.js
blob: 9bdee2c406c86a020f5a123042e776e8f6607ee5 (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
65
66
67
68
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * @param {Window} win
 */
function focusWindow(win) {
  const promise = BrowserTestUtils.waitForEvent(win, "focus");
  win.focus();
  return promise;
}

/**
 * Test that the full page translation panel works when multiple windows are used.
 */
add_task(async function test_browser_translations_full_page_multiple_windows() {
  const window1 = window;
  const testPage1 = await loadTestPage({
    page: SPANISH_PAGE_URL,
    languagePairs: LANGUAGE_PAIRS,
  });

  const window2 = await BrowserTestUtils.openNewBrowserWindow();

  const testPage2 = await loadTestPage({
    win: window2,
    page: SPANISH_PAGE_URL,
    languagePairs: LANGUAGE_PAIRS,
  });

  // Focus back to the original window first. This ensures coverage for invalid caching
  // logic involving multiple windows.
  await focusWindow(window1);

  info("Testing window 1");
  await FullPageTranslationsTestUtils.openPanel({
    onOpenPanel: FullPageTranslationsTestUtils.assertPanelViewDefault,
  });
  await FullPageTranslationsTestUtils.clickTranslateButton({
    downloadHandler: testPage1.resolveDownloads,
  });
  await FullPageTranslationsTestUtils.assertPageIsTranslated(
    "es",
    "en",
    testPage1.runInPage,
    "Window 1 gets translated",
    window1
  );

  await focusWindow(window2);

  info("Testing window 2");
  await FullPageTranslationsTestUtils.openPanel({ win: window2 });
  await FullPageTranslationsTestUtils.clickTranslateButton({ win: window2 });
  await FullPageTranslationsTestUtils.assertPageIsTranslated(
    "es",
    "en",
    testPage2.runInPage,
    "Window 2 gets translated",
    window2
  );

  await testPage2.cleanup();
  await BrowserTestUtils.closeWindow(window2);
  await testPage1.cleanup();
});