summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_private_browsing_window.js
blob: 34a4c8bbf0d865c05b89848f2067505a8261a9eb (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Make sure that we can open private browsing windows

function test() {
  waitForExplicitFinish();
  var nonPrivateWin = OpenBrowserWindow();
  ok(
    !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
    "OpenBrowserWindow() should open a normal window"
  );
  nonPrivateWin.close();

  var privateWin = OpenBrowserWindow({ private: true });
  ok(
    PrivateBrowsingUtils.isWindowPrivate(privateWin),
    "OpenBrowserWindow({private: true}) should open a private window"
  );

  nonPrivateWin = OpenBrowserWindow({ private: false });
  ok(
    !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
    "OpenBrowserWindow({private: false}) should open a normal window"
  );
  nonPrivateWin.close();

  whenDelayedStartupFinished(privateWin, function () {
    nonPrivateWin = privateWin.OpenBrowserWindow({ private: false });
    ok(
      !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
      "privateWin.OpenBrowserWindow({private: false}) should open a normal window"
    );

    nonPrivateWin.close();

    [
      {
        normal: "menu_newNavigator",
        private: "menu_newPrivateWindow",
        accesskey: true,
      },
      {
        normal: "appmenu_newNavigator",
        private: "appmenu_newPrivateWindow",
        accesskey: false,
      },
    ].forEach(function (menu) {
      let newWindow = privateWin.document.getElementById(menu.normal);
      let newPrivateWindow = privateWin.document.getElementById(menu.private);
      if (newWindow && newPrivateWindow) {
        ok(
          !newPrivateWindow.hidden,
          "New Private Window menu item should be hidden"
        );
        isnot(
          newWindow.label,
          newPrivateWindow.label,
          "New Window's label shouldn't be overwritten"
        );
        if (menu.accesskey) {
          isnot(
            newWindow.accessKey,
            newPrivateWindow.accessKey,
            "New Window's accessKey shouldn't be overwritten"
          );
        }
        isnot(
          newWindow.command,
          newPrivateWindow.command,
          "New Window's command shouldn't be overwritten"
        );
      }
    });

    is(
      privateWin.gBrowser.tabs[0].label,
      "New Private Tab",
      "New tabs in the private browsing windows should have 'New Private Tab' as the title."
    );

    privateWin.close();

    Services.prefs.setBoolPref("browser.privatebrowsing.autostart", true);
    privateWin = OpenBrowserWindow({ private: true });
    whenDelayedStartupFinished(privateWin, function () {
      [
        {
          normal: "menu_newNavigator",
          private: "menu_newPrivateWindow",
          accessKey: true,
        },
        {
          normal: "appmenu_newNavigator",
          private: "appmenu_newPrivateWindow",
          accessKey: false,
        },
      ].forEach(function (menu) {
        let newWindow = privateWin.document.getElementById(menu.normal);
        let newPrivateWindow = privateWin.document.getElementById(menu.private);
        if (newWindow && newPrivateWindow) {
          ok(
            newPrivateWindow.hidden,
            "New Private Window menu item should be hidden"
          );
          is(
            newWindow.label,
            newPrivateWindow.label,
            "New Window's label should be overwritten"
          );
          if (menu.accesskey) {
            is(
              newWindow.accessKey,
              newPrivateWindow.accessKey,
              "New Window's accessKey should be overwritten"
            );
          }
          is(
            newWindow.command,
            newPrivateWindow.command,
            "New Window's command should be overwritten"
          );
        }
      });

      is(
        privateWin.gBrowser.tabs[0].label,
        "New Tab",
        "Normal tab title is used also in the permanent private browsing mode."
      );
      privateWin.close();
      Services.prefs.clearUserPref("browser.privatebrowsing.autostart");
      finish();
    });
  });
}