summaryrefslogtreecommitdiffstats
path: root/toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js
blob: b6e7f2b131a1b799f28b483a12435c4a039c65fc (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
"use strict";

// Opening non-popup from a popup should open a new tab in the most recent
// non-popup window.
add_task(async function test_non_popup_from_popup() {
  const BLANK_PAGE = "data:text/html,";

  // A page opened in a new tab.
  const OPEN_PAGE = "data:text/plain,hello";

  // A page opened in a new popup.
  // This opens a new non-popup page with OPEN_PAGE,
  // tha should be opened in a new tab in most recent window.
  const NON_POPUP_OPENER = btoa(
    `data:text/html,<script>window.open('${OPEN_PAGE}', '', '')</script>`
  );

  // A page opened in a new tab.
  // This opens a popup with NON_POPUP_OPENER.
  const POPUP_OPENER = `data:text/html,<script>window.open(atob("${NON_POPUP_OPENER}"), "", "width=500");</script>`;

  await SpecialPowers.pushPrefEnv({
    set: [["browser.link.open_newwindow", 3]],
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: BLANK_PAGE,
    },
    async function () {
      // Wait for a popup opened by POPUP_OPENER.
      const newPopupPromise = BrowserTestUtils.waitForNewWindow();

      // Wait for a new tab opened by NON_POPUP_OPENER.
      const newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, OPEN_PAGE);

      // Open a new tab that opens a popup with NON_POPUP_OPENER.
      BrowserTestUtils.startLoadingURIString(gBrowser, POPUP_OPENER);

      let win = await newPopupPromise;
      Assert.ok(true, "popup is opened");

      let tab = await newTabPromise;
      Assert.ok(true, "new tab is opened in the recent window");

      BrowserTestUtils.removeTab(tab);
      await BrowserTestUtils.closeWindow(win);
    }
  );

  await SpecialPowers.popPrefEnv();
});