summaryrefslogtreecommitdiffstats
path: root/browser/components/contextualidentity/test/browser/browser_windowOpen.js
blob: d550b03ed832c0ee215d9229f6bc55b85ce50ad1 (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
"use strict";

// Here we want to test that a new opened window shows the same UI of the
// parent one if this has been loaded from a particular container.

const BASE_URI =
  "http://mochi.test:8888/browser/browser/components/" +
  "contextualidentity/test/browser/empty_file.html";

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["privacy.userContext.enabled", true],
      ["browser.link.open_newwindow", 2],
    ],
  });
});

add_task(async function test() {
  info("Creating a tab with UCI = 1...");
  let tab = BrowserTestUtils.addTab(gBrowser, BASE_URI, { userContextId: 1 });
  is(tab.getAttribute("usercontextid"), "1", "New tab has UCI equal 1");

  let browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  info("Opening a new window from this tab...");
  let newWinPromise = BrowserTestUtils.waitForNewWindow({ url: BASE_URI });
  SpecialPowers.spawn(browser, [BASE_URI], function (url) {
    content.window.newWindow = content.window.open(url, "_blank");
  });

  let newWin = await newWinPromise;
  let newTab = newWin.gBrowser.selectedTab;

  is(newTab.getAttribute("usercontextid"), "1", "New tab has UCI equal 1");

  info("Closing the new window and tab...");
  await BrowserTestUtils.closeWindow(newWin);
  BrowserTestUtils.removeTab(tab);
});