summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_UrlbarInput_privateFeature.js
blob: fb81e9f5361330453120d3b05842eb5d2b88d473 (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
69
70
71
72
73
74
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Tests that _loadURL correctly sets and passes on the `private` window
// attribute (or not) with various arguments.

add_task(async function privateFeatureSetOnNewWindowImplicitly() {
  let privateWin = await BrowserTestUtils.openNewBrowserWindow({
    private: true,
  });

  let newWinOpened = BrowserTestUtils.waitForNewWindow();

  privateWin.gURLBar._loadURL("about:blank", null, "window", {});

  let newWin = await newWinOpened;
  Assert.equal(
    newWin.docShell.treeOwner
      .QueryInterface(Ci.nsIInterfaceRequestor)
      .getInterface(Ci.nsIAppWindow).chromeFlags &
      Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    "New window opened from existing private window should be marked as private"
  );
  await BrowserTestUtils.closeWindow(newWin);
  await BrowserTestUtils.closeWindow(privateWin);
});

add_task(async function privateFeatureSetOnNewWindowExplicitly() {
  let privateWin = await BrowserTestUtils.openNewBrowserWindow({
    private: true,
  });

  let newWinOpened = BrowserTestUtils.waitForNewWindow();

  privateWin.gURLBar._loadURL("about:blank", null, "window", { private: true });

  let newWin = await newWinOpened;
  Assert.equal(
    newWin.docShell.treeOwner
      .QueryInterface(Ci.nsIInterfaceRequestor)
      .getInterface(Ci.nsIAppWindow).chromeFlags &
      Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    "New window opened from existing private window should be marked as private"
  );
  await BrowserTestUtils.closeWindow(newWin);
  await BrowserTestUtils.closeWindow(privateWin);
});

add_task(async function privateFeatureNotSetOnNewWindowExplicitly() {
  let privateWin = await BrowserTestUtils.openNewBrowserWindow({
    private: true,
  });

  let newWinOpened = BrowserTestUtils.waitForNewWindow();

  privateWin.gURLBar._loadURL("about:blank", null, "window", {
    private: false,
  });

  let newWin = await newWinOpened;
  Assert.notEqual(
    newWin.docShell.treeOwner
      .QueryInterface(Ci.nsIInterfaceRequestor)
      .getInterface(Ci.nsIAppWindow).chromeFlags &
      Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
    "New window opened from existing private window should be marked as private"
  );
  await BrowserTestUtils.closeWindow(newWin);
  await BrowserTestUtils.closeWindow(privateWin);
});