[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/tor-browser][base-browser-128.2.0esr-14.0-1] 2 commits: Bug 1919363 - Only show one app menu "new window" item in permanent private browsing. r=mconley



Title: GitLab

morgan pushed to branch base-browser-128.2.0esr-14.0-1 at The Tor Project / Applications / Tor Browser

Commits:

  • 104d7d03
    by Henry Wilkes at 2024-09-23T18:19:58+00:00
    Bug 1919363 - Only show one app menu "new window" item in permanent private browsing. r=mconley
    
    We also update the browser_private_browsing_window.js test.
    The previous test was limited because it was referring to non-existent
    "appmenu_newNavigator" and "appmenu_newPrivateWindow".
    
    Differential Revision: https://phabricator.services.mozilla.com/D222507
    
  • 26180332
    by Henry Wilkes at 2024-09-23T18:19:58+00:00
    fixup! Bug 18905: Hide unwanted items from help menu
    
    Bug 42362: Stop hiding the Tools:PrivateBrowsing command and shortcut.
    

3 changed files:

Changes:

  • browser/base/content/browser-init.js
    ... ... @@ -289,10 +289,7 @@ var gBrowserInit = {
    289 289
         this._boundDelayedStartup = this._delayedStartup.bind(this);
    
    290 290
         window.addEventListener("MozAfterPaint", this._boundDelayedStartup);
    
    291 291
     
    
    292
    -    if (
    
    293
    -      PrivateBrowsingUtils.permanentPrivateBrowsing ||
    
    294
    -      !PrivateBrowsingUtils.enabled
    
    295
    -    ) {
    
    292
    +    if (!PrivateBrowsingUtils.enabled) {
    
    296 293
           document.getElementById("Tools:PrivateBrowsing").hidden = true;
    
    297 294
           // Setting disabled doesn't disable the shortcut, so we just remove
    
    298 295
           // the keybinding.
    

  • browser/base/content/browser.js
    ... ... @@ -6795,15 +6795,34 @@ var gPrivateBrowsingUI = {
    6795 6795
         }
    
    6796 6796
     
    
    6797 6797
         if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
    
    6798
    -      // Adjust the New Window menu entries
    
    6799
    -      let newWindow = document.getElementById("menu_newNavigator");
    
    6800
    -      let newPrivateWindow = document.getElementById("menu_newPrivateWindow");
    
    6801
    -      if (newWindow && newPrivateWindow) {
    
    6802
    -        newPrivateWindow.hidden = true;
    
    6803
    -        newWindow.label = newPrivateWindow.label;
    
    6804
    -        newWindow.accessKey = newPrivateWindow.accessKey;
    
    6805
    -        newWindow.command = newPrivateWindow.command;
    
    6806
    -      }
    
    6798
    +      let hideNewWindowItem = (windowItem, privateWindowItem) => {
    
    6799
    +        // In permanent browsing mode command "cmd_newNavigator" should act the
    
    6800
    +        // same as "Tools:PrivateBrowsing".
    
    6801
    +        // So we hide the redundant private window item. But we also rename the
    
    6802
    +        // "new window" item to be "new private window".
    
    6803
    +        // NOTE: We choose to hide privateWindowItem rather than windowItem so
    
    6804
    +        // that we still show the "key" for "cmd_newNavigator" (Ctrl+N) rather
    
    6805
    +        // than (Ctrl+Shift+P).
    
    6806
    +        privateWindowItem.hidden = true;
    
    6807
    +        windowItem.setAttribute(
    
    6808
    +          "data-l10n-id",
    
    6809
    +          privateWindowItem.getAttribute("data-l10n-id")
    
    6810
    +        );
    
    6811
    +      };
    
    6812
    +
    
    6813
    +      // Adjust the File menu items.
    
    6814
    +      hideNewWindowItem(
    
    6815
    +        document.getElementById("menu_newNavigator"),
    
    6816
    +        document.getElementById("menu_newPrivateWindow")
    
    6817
    +      );
    
    6818
    +      // Adjust the App menu items.
    
    6819
    +      hideNewWindowItem(
    
    6820
    +        PanelMultiView.getViewNode(document, "appMenu-new-window-button2"),
    
    6821
    +        PanelMultiView.getViewNode(
    
    6822
    +          document,
    
    6823
    +          "appMenu-new-private-window-button2"
    
    6824
    +        )
    
    6825
    +      );
    
    6807 6826
         }
    
    6808 6827
       },
    
    6809 6828
     };
    

  • browser/base/content/test/general/browser_private_browsing_window.js
    1
    -// Make sure that we can open private browsing windows
    
    1
    +/* This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    + * License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    
    2 4
     
    
    3
    -function test() {
    
    4
    -  waitForExplicitFinish();
    
    5
    -  var nonPrivateWin = OpenBrowserWindow();
    
    6
    -  ok(
    
    7
    -    !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
    
    5
    +add_task(async function testOpenBrowserWindow() {
    
    6
    +  let win = OpenBrowserWindow();
    
    7
    +  Assert.ok(
    
    8
    +    !PrivateBrowsingUtils.isWindowPrivate(win),
    
    8 9
         "OpenBrowserWindow() should open a normal window"
    
    9 10
       );
    
    10
    -  nonPrivateWin.close();
    
    11
    +  await BrowserTestUtils.closeWindow(win);
    
    11 12
     
    
    12
    -  var privateWin = OpenBrowserWindow({ private: true });
    
    13
    -  ok(
    
    14
    -    PrivateBrowsingUtils.isWindowPrivate(privateWin),
    
    13
    +  win = OpenBrowserWindow({ private: true });
    
    14
    +  Assert.ok(
    
    15
    +    PrivateBrowsingUtils.isWindowPrivate(win),
    
    15 16
         "OpenBrowserWindow({private: true}) should open a private window"
    
    16 17
       );
    
    18
    +  await BrowserTestUtils.closeWindow(win);
    
    17 19
     
    
    18
    -  nonPrivateWin = OpenBrowserWindow({ private: false });
    
    19
    -  ok(
    
    20
    -    !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
    
    20
    +  win = OpenBrowserWindow({ private: false });
    
    21
    +  Assert.ok(
    
    22
    +    !PrivateBrowsingUtils.isWindowPrivate(win),
    
    21 23
         "OpenBrowserWindow({private: false}) should open a normal window"
    
    22 24
       );
    
    23
    -  nonPrivateWin.close();
    
    25
    +  await BrowserTestUtils.closeWindow(win);
    
    24 26
     
    
    25
    -  whenDelayedStartupFinished(privateWin, function () {
    
    26
    -    nonPrivateWin = privateWin.OpenBrowserWindow({ private: false });
    
    27
    -    ok(
    
    28
    -      !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
    
    29
    -      "privateWin.OpenBrowserWindow({private: false}) should open a normal window"
    
    30
    -    );
    
    27
    +  // In permanent browsing mode.
    
    28
    +  await SpecialPowers.pushPrefEnv({
    
    29
    +    set: [["browser.privatebrowsing.autostart", true]],
    
    30
    +  });
    
    31
    +
    
    32
    +  win = OpenBrowserWindow();
    
    33
    +  Assert.ok(
    
    34
    +    PrivateBrowsingUtils.isWindowPrivate(win),
    
    35
    +    "OpenBrowserWindow() in PBM should open a private window"
    
    36
    +  );
    
    37
    +  await BrowserTestUtils.closeWindow(win);
    
    38
    +
    
    39
    +  win = OpenBrowserWindow({ private: true });
    
    40
    +  Assert.ok(
    
    41
    +    PrivateBrowsingUtils.isWindowPrivate(win),
    
    42
    +    "OpenBrowserWindow({private: true}) in PBM should open a private window"
    
    43
    +  );
    
    44
    +  await BrowserTestUtils.closeWindow(win);
    
    45
    +
    
    46
    +  win = OpenBrowserWindow({ private: false });
    
    47
    +  Assert.ok(
    
    48
    +    PrivateBrowsingUtils.isWindowPrivate(win),
    
    49
    +    "OpenBrowserWindow({private: false}) in PBM should open a private window"
    
    50
    +  );
    
    51
    +  await BrowserTestUtils.closeWindow(win);
    
    52
    +
    
    53
    +  await SpecialPowers.popPrefEnv();
    
    54
    +});
    
    31 55
     
    
    32
    -    nonPrivateWin.close();
    
    33
    -
    
    34
    -    [
    
    35
    -      {
    
    36
    -        normal: "menu_newNavigator",
    
    37
    -        private: "menu_newPrivateWindow",
    
    38
    -        accesskey: true,
    
    39
    -      },
    
    40
    -      {
    
    41
    -        normal: "appmenu_newNavigator",
    
    42
    -        private: "appmenu_newPrivateWindow",
    
    43
    -        accesskey: false,
    
    44
    -      },
    
    45
    -    ].forEach(function (menu) {
    
    46
    -      let newWindow = privateWin.document.getElementById(menu.normal);
    
    47
    -      let newPrivateWindow = privateWin.document.getElementById(menu.private);
    
    48
    -      if (newWindow && newPrivateWindow) {
    
    49
    -        ok(
    
    50
    -          !newPrivateWindow.hidden,
    
    51
    -          "New Private Window menu item should be hidden"
    
    52
    -        );
    
    53
    -        isnot(
    
    54
    -          newWindow.label,
    
    55
    -          newPrivateWindow.label,
    
    56
    -          "New Window's label shouldn't be overwritten"
    
    57
    -        );
    
    58
    -        if (menu.accesskey) {
    
    59
    -          isnot(
    
    60
    -            newWindow.accessKey,
    
    61
    -            newPrivateWindow.accessKey,
    
    62
    -            "New Window's accessKey shouldn't be overwritten"
    
    63
    -          );
    
    64
    -        }
    
    65
    -        isnot(
    
    66
    -          newWindow.command,
    
    67
    -          newPrivateWindow.command,
    
    68
    -          "New Window's command shouldn't be overwritten"
    
    69
    -        );
    
    70
    -      }
    
    71
    -    });
    
    72
    -
    
    73
    -    is(
    
    74
    -      privateWin.gBrowser.tabs[0].label,
    
    75
    -      "New Private Tab",
    
    76
    -      "New tabs in the private browsing windows should have 'New Private Tab' as the title."
    
    56
    +/**
    
    57
    + * Check that the "new window" menu items have the expected properties.
    
    58
    + *
    
    59
    + * @param {Element} newWindowItem - The "new window" item to check.
    
    60
    + * @param {Element} privateWindowItem - The "new private window" item to check.
    
    61
    + * @param {Object} expect - The expected properties.
    
    62
    + * @param {boolean} expect.privateVisible - Whether we expect the private item
    
    63
    + *   to be visible or not.
    
    64
    + * @param {string} expect.newWindowL10nId - The expected string ID used by the
    
    65
    + *   "new window" item.
    
    66
    + * @param {string} expect.privateWindowL10nId - The expected string ID used by
    
    67
    + *   the "new private window" item.
    
    68
    + * @param {boolean} [useIsVisible=true] - Whether to test the "true" visibility
    
    69
    + *   of the item. Otherwise only the "hidden" attribute is checked.
    
    70
    + */
    
    71
    +function assertMenuItems(
    
    72
    +  newWindowItem,
    
    73
    +  privateWindowItem,
    
    74
    +  expect,
    
    75
    +  useIsVisible = true
    
    76
    +) {
    
    77
    +  Assert.ok(newWindowItem);
    
    78
    +  Assert.ok(privateWindowItem);
    
    79
    +
    
    80
    +  if (useIsVisible) {
    
    81
    +    Assert.ok(
    
    82
    +      BrowserTestUtils.isVisible(newWindowItem),
    
    83
    +      "New window item should be visible"
    
    77 84
         );
    
    85
    +  } else {
    
    86
    +    // The application menu is not accessible on macOS, just check the hidden
    
    87
    +    // attribute.
    
    88
    +    Assert.ok(!newWindowItem.hidden, "New window item should be visible");
    
    89
    +  }
    
    90
    +
    
    91
    +  Assert.equal(
    
    92
    +    newWindowItem.getAttribute("key"),
    
    93
    +    "key_newNavigator",
    
    94
    +    "New window item should use the same key"
    
    95
    +  );
    
    96
    +  Assert.equal(
    
    97
    +    newWindowItem.getAttribute("data-l10n-id"),
    
    98
    +    expect.newWindowL10nId
    
    99
    +  );
    
    78 100
     
    
    79
    -    privateWin.close();
    
    80
    -
    
    81
    -    Services.prefs.setBoolPref("browser.privatebrowsing.autostart", true);
    
    82
    -    privateWin = OpenBrowserWindow({ private: true });
    
    83
    -    whenDelayedStartupFinished(privateWin, function () {
    
    84
    -      [
    
    85
    -        {
    
    86
    -          normal: "menu_newNavigator",
    
    87
    -          private: "menu_newPrivateWindow",
    
    88
    -          accessKey: true,
    
    89
    -        },
    
    90
    -        {
    
    91
    -          normal: "appmenu_newNavigator",
    
    92
    -          private: "appmenu_newPrivateWindow",
    
    93
    -          accessKey: false,
    
    94
    -        },
    
    95
    -      ].forEach(function (menu) {
    
    96
    -        let newWindow = privateWin.document.getElementById(menu.normal);
    
    97
    -        let newPrivateWindow = privateWin.document.getElementById(menu.private);
    
    98
    -        if (newWindow && newPrivateWindow) {
    
    99
    -          ok(
    
    100
    -            newPrivateWindow.hidden,
    
    101
    -            "New Private Window menu item should be hidden"
    
    102
    -          );
    
    103
    -          is(
    
    104
    -            newWindow.label,
    
    105
    -            newPrivateWindow.label,
    
    106
    -            "New Window's label should be overwritten"
    
    107
    -          );
    
    108
    -          if (menu.accesskey) {
    
    109
    -            is(
    
    110
    -              newWindow.accessKey,
    
    111
    -              newPrivateWindow.accessKey,
    
    112
    -              "New Window's accessKey should be overwritten"
    
    113
    -            );
    
    114
    -          }
    
    115
    -          is(
    
    116
    -            newWindow.command,
    
    117
    -            newPrivateWindow.command,
    
    118
    -            "New Window's command should be overwritten"
    
    119
    -          );
    
    120
    -        }
    
    121
    -      });
    
    122
    -
    
    123
    -      is(
    
    124
    -        privateWin.gBrowser.tabs[0].label,
    
    125
    -        "New Tab",
    
    126
    -        "Normal tab title is used also in the permanent private browsing mode."
    
    101
    +  if (!expect.privateVisible) {
    
    102
    +    if (useIsVisible) {
    
    103
    +      Assert.ok(
    
    104
    +        BrowserTestUtils.isHidden(privateWindowItem),
    
    105
    +        "Private window item should be hidden"
    
    127 106
           );
    
    128
    -      privateWin.close();
    
    129
    -      Services.prefs.clearUserPref("browser.privatebrowsing.autostart");
    
    130
    -      finish();
    
    131
    -    });
    
    132
    -  });
    
    107
    +    } else {
    
    108
    +      Assert.ok(
    
    109
    +        privateWindowItem.hidden,
    
    110
    +        "Private window item should be hidden"
    
    111
    +      );
    
    112
    +    }
    
    113
    +    // Don't check attributes since hidden.
    
    114
    +  } else {
    
    115
    +    if (useIsVisible) {
    
    116
    +      Assert.ok(
    
    117
    +        BrowserTestUtils.isVisible(privateWindowItem),
    
    118
    +        "Private window item should be visible"
    
    119
    +      );
    
    120
    +    } else {
    
    121
    +      Assert.ok(
    
    122
    +        !privateWindowItem.hidden,
    
    123
    +        "Private window item should be visible"
    
    124
    +      );
    
    125
    +    }
    
    126
    +    Assert.equal(
    
    127
    +      privateWindowItem.getAttribute("key"),
    
    128
    +      "key_privatebrowsing",
    
    129
    +      "Private window item should use the same key"
    
    130
    +    );
    
    131
    +    Assert.equal(
    
    132
    +      privateWindowItem.getAttribute("data-l10n-id"),
    
    133
    +      expect.privateWindowL10nId
    
    134
    +    );
    
    135
    +  }
    
    136
    +}
    
    137
    +
    
    138
    +/**
    
    139
    + * Check that a window has the expected "new window" items in the "File" and app
    
    140
    + * menus.
    
    141
    + *
    
    142
    + * @param {Window} win - The window to check.
    
    143
    + * @param {boolean} expectBoth - Whether we expect the window to contain both
    
    144
    + *   "new window" and "new private window" as separate controls.
    
    145
    + */
    
    146
    +async function checkWindowMenus(win, expectBoth) {
    
    147
    +  // Check the File menu.
    
    148
    +  assertMenuItems(
    
    149
    +    win.document.getElementById("menu_newNavigator"),
    
    150
    +    win.document.getElementById("menu_newPrivateWindow"),
    
    151
    +    {
    
    152
    +      privateVisible: expectBoth,
    
    153
    +      // If in permanent private browsing, expect the new window item to use the
    
    154
    +      // "New private window" string.
    
    155
    +      newWindowL10nId: expectBoth
    
    156
    +        ? "menu-file-new-window"
    
    157
    +        : "menu-file-new-private-window",
    
    158
    +      privateWindowL10nId: "menu-file-new-private-window",
    
    159
    +    },
    
    160
    +    // The file menu is difficult to open cross-platform, so we do not open it
    
    161
    +    // for this test.
    
    162
    +    false
    
    163
    +  );
    
    164
    +
    
    165
    +  // Open the app menu.
    
    166
    +  let appMenuButton = win.document.getElementById("PanelUI-menu-button");
    
    167
    +  let appMenu = win.document.getElementById("appMenu-popup");
    
    168
    +  let menuShown = BrowserTestUtils.waitForEvent(appMenu, "popupshown");
    
    169
    +  EventUtils.synthesizeMouseAtCenter(appMenuButton, {}, win);
    
    170
    +  await menuShown;
    
    171
    +
    
    172
    +  // Check the app menu.
    
    173
    +  assertMenuItems(
    
    174
    +    win.document.getElementById("appMenu-new-window-button2"),
    
    175
    +    win.document.getElementById("appMenu-new-private-window-button2"),
    
    176
    +    {
    
    177
    +      privateVisible: expectBoth,
    
    178
    +      // If in permanent private browsing, expect the new window item to use the
    
    179
    +      // "New private window" string.
    
    180
    +      newWindowL10nId: expectBoth
    
    181
    +        ? "appmenuitem-new-window"
    
    182
    +        : "appmenuitem-new-private-window",
    
    183
    +      privateWindowL10nId: "appmenuitem-new-private-window",
    
    184
    +    }
    
    185
    +  );
    
    186
    +
    
    187
    +  appMenu.hidePopup();
    
    133 188
     }
    
    189
    +
    
    190
    +add_task(async function testNewWindowMenuItems() {
    
    191
    +  // In non-private window, expect both menu items.
    
    192
    +  let win = await BrowserTestUtils.openNewBrowserWindow({
    
    193
    +    private: false,
    
    194
    +  });
    
    195
    +  await checkWindowMenus(win, true);
    
    196
    +  Assert.equal(win.gBrowser.currentURI.spec, "about:blank");
    
    197
    +  await BrowserTestUtils.closeWindow(win);
    
    198
    +
    
    199
    +  // In non-permanent private window, still expect both menu items.
    
    200
    +  win = await BrowserTestUtils.openNewBrowserWindow({
    
    201
    +    private: true,
    
    202
    +  });
    
    203
    +  await checkWindowMenus(win, true);
    
    204
    +  Assert.equal(win.gBrowser.currentURI.spec, "about:privatebrowsing");
    
    205
    +  await BrowserTestUtils.closeWindow(win);
    
    206
    +
    
    207
    +  // In permanent private browsing, expect only one menu item.
    
    208
    +  await SpecialPowers.pushPrefEnv({
    
    209
    +    set: [["browser.privatebrowsing.autostart", true]],
    
    210
    +  });
    
    211
    +
    
    212
    +  win = await BrowserTestUtils.openNewBrowserWindow();
    
    213
    +  await checkWindowMenus(win, false);
    
    214
    +  Assert.equal(win.gBrowser.currentURI.spec, "about:blank");
    
    215
    +  await BrowserTestUtils.closeWindow(win);
    
    216
    +
    
    217
    +  await SpecialPowers.popPrefEnv();
    
    218
    +});

  • _______________________________________________
    tor-commits mailing list
    tor-commits@xxxxxxxxxxxxxxxxxxxx
    https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits