summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_file_to_http_named_popup.js
blob: 57e5ec7ad354666e6995739a4d93ed4ca328d81a (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */

const TEST_FILE = fileURL("dummy_page.html");
const TEST_HTTP = httpURL("dummy_page.html");

// Test for Bug 1634252
add_task(async function () {
  await BrowserTestUtils.withNewTab(TEST_FILE, async function (fileBrowser) {
    info("Tab ready");

    async function summonPopup(firstRun) {
      var winPromise;
      if (firstRun) {
        winPromise = BrowserTestUtils.waitForNewWindow({
          url: TEST_HTTP,
        });
      }

      await SpecialPowers.spawn(
        fileBrowser,
        [TEST_HTTP, firstRun],
        (target, firstRun_) => {
          var win = content.open(target, "named", "width=400,height=400");
          win.focus();
          ok(win, "window.open was successful");
          if (firstRun_) {
            content.document.firstWindow = win;
          } else {
            content.document.otherWindow = win;
          }
        }
      );

      if (firstRun) {
        // We should only wait for the window the first time, because only the
        // later times no new window should be created.
        info("Waiting for new window");
        var win = await winPromise;
        ok(win, "Got a window");
      }
    }

    info("Opening window");
    await summonPopup(true);
    info("Opening window again");
    await summonPopup(false);

    await SpecialPowers.spawn(fileBrowser, [], () => {
      ok(content.document.firstWindow, "Window is non-null");
      is(
        content.document.otherWindow,
        content.document.firstWindow,
        "Windows are the same"
      );

      content.document.firstWindow.close();
    });
  });
});