tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_panelUINotifications_multiWindow.js (6108B)


      1 "use strict";
      2 
      3 const { AppMenuNotifications } = ChromeUtils.importESModule(
      4  "resource://gre/modules/AppMenuNotifications.sys.mjs"
      5 );
      6 
      7 /**
      8 * Tests that when we try to show a notification in a background window, it
      9 * does not display until the window comes back into the foreground. However,
     10 * it should display a badge.
     11 */
     12 add_task(async function testDoesNotShowDoorhangerForBackgroundWindow() {
     13  let options = {
     14    gBrowser: window.gBrowser,
     15    url: "about:blank",
     16  };
     17 
     18  await BrowserTestUtils.withNewTab(options, async function () {
     19    let win = await BrowserTestUtils.openNewBrowserWindow();
     20    await SimpleTest.promiseFocus(win);
     21    let mainActionCalled = false;
     22    let mainAction = {
     23      callback: () => {
     24        mainActionCalled = true;
     25      },
     26    };
     27    AppMenuNotifications.showNotification("update-manual", mainAction);
     28    is(
     29      PanelUI.notificationPanel.state,
     30      "closed",
     31      "The background window's doorhanger is closed."
     32    );
     33    is(
     34      PanelUI.menuButton.hasAttribute("badge-status"),
     35      true,
     36      "The background window has a badge."
     37    );
     38 
     39    let popupShown = BrowserTestUtils.waitForEvent(
     40      PanelUI.notificationPanel,
     41      "popupshown"
     42    );
     43 
     44    await BrowserTestUtils.closeWindow(win);
     45    await SimpleTest.promiseFocus(window);
     46    await popupShown;
     47 
     48    let notifications = [...PanelUI.notificationPanel.children].filter(
     49      n => !n.hidden
     50    );
     51    is(
     52      notifications.length,
     53      1,
     54      "PanelUI doorhanger is only displaying one notification."
     55    );
     56    let doorhanger = notifications[0];
     57    is(
     58      doorhanger.id,
     59      "appMenu-update-manual-notification",
     60      "PanelUI is displaying the update-manual notification."
     61    );
     62 
     63    let button = doorhanger.button;
     64 
     65    Assert.equal(
     66      PanelUI.notificationPanel.state,
     67      "open",
     68      "Expect panel state to be open when clicking panel buttons"
     69    );
     70    button.click();
     71 
     72    ok(mainActionCalled, "Main action callback was called");
     73    is(
     74      PanelUI.notificationPanel.state,
     75      "closed",
     76      "update-manual doorhanger is closed."
     77    );
     78    is(
     79      PanelUI.menuButton.hasAttribute("badge-status"),
     80      false,
     81      "Should not have a badge status"
     82    );
     83  });
     84 });
     85 
     86 /**
     87 * Tests that when we try to show a notification in a background window and in
     88 * a foreground window, if the foreground window's main action is called, the
     89 * background window's doorhanger will be removed.
     90 */
     91 add_task(
     92  async function testBackgroundWindowNotificationsAreRemovedByForeground() {
     93    let options = {
     94      gBrowser: window.gBrowser,
     95      url: "about:blank",
     96    };
     97 
     98    await BrowserTestUtils.withNewTab(options, async function () {
     99      let win = await BrowserTestUtils.openNewBrowserWindow();
    100      await SimpleTest.promiseFocus(win);
    101      AppMenuNotifications.showNotification("update-manual", { callback() {} });
    102      let notifications = [...win.PanelUI.notificationPanel.children].filter(
    103        n => !n.hidden
    104      );
    105      is(
    106        notifications.length,
    107        1,
    108        "PanelUI doorhanger is only displaying one notification."
    109      );
    110      let doorhanger = notifications[0];
    111      doorhanger.button.click();
    112 
    113      await BrowserTestUtils.closeWindow(win);
    114      await SimpleTest.promiseFocus(window);
    115 
    116      is(
    117        PanelUI.notificationPanel.state,
    118        "closed",
    119        "update-manual doorhanger is closed."
    120      );
    121      is(
    122        PanelUI.menuButton.hasAttribute("badge-status"),
    123        false,
    124        "Should not have a badge status"
    125      );
    126    });
    127  }
    128 );
    129 
    130 /**
    131 * Tests that when we try to show a notification in a background window and in
    132 * a foreground window, if the foreground window's doorhanger is dismissed,
    133 * the background window's doorhanger will also be dismissed once the window
    134 * regains focus.
    135 */
    136 add_task(
    137  async function testBackgroundWindowNotificationsAreDismissedByForeground() {
    138    let options = {
    139      gBrowser: window.gBrowser,
    140      url: "about:blank",
    141    };
    142 
    143    await BrowserTestUtils.withNewTab(options, async function () {
    144      let win = await BrowserTestUtils.openNewBrowserWindow();
    145      await SimpleTest.promiseFocus(win);
    146      AppMenuNotifications.showNotification("update-manual", { callback() {} });
    147      let notifications = [...win.PanelUI.notificationPanel.children].filter(
    148        n => !n.hidden
    149      );
    150      is(
    151        notifications.length,
    152        1,
    153        "PanelUI doorhanger is only displaying one notification."
    154      );
    155      let doorhanger = notifications[0];
    156      let button = doorhanger.secondaryButton;
    157      button.click();
    158 
    159      await BrowserTestUtils.closeWindow(win);
    160      await SimpleTest.promiseFocus(window);
    161 
    162      is(
    163        PanelUI.notificationPanel.state,
    164        "closed",
    165        "The background window's doorhanger is closed."
    166      );
    167      is(
    168        PanelUI.menuButton.hasAttribute("badge-status"),
    169        true,
    170        "The dismissed notification should still have a badge status"
    171      );
    172 
    173      AppMenuNotifications.removeNotification(/.*/);
    174    });
    175  }
    176 );
    177 
    178 /**
    179 * Tests that when we open a new window while a notification is showing, the
    180 * notification also shows on the new window.
    181 */
    182 add_task(async function testOpenWindowAfterShowingNotification() {
    183  AppMenuNotifications.showNotification("update-manual", { callback() {} });
    184 
    185  let win = await BrowserTestUtils.openNewBrowserWindow();
    186  await SimpleTest.promiseFocus(win);
    187  let notifications = [...win.PanelUI.notificationPanel.children].filter(
    188    n => !n.hidden
    189  );
    190  is(
    191    notifications.length,
    192    1,
    193    "PanelUI doorhanger is only displaying one notification."
    194  );
    195  let doorhanger = notifications[0];
    196  let button = doorhanger.secondaryButton;
    197  button.click();
    198 
    199  await BrowserTestUtils.closeWindow(win);
    200  await SimpleTest.promiseFocus(window);
    201 
    202  is(
    203    PanelUI.notificationPanel.state,
    204    "closed",
    205    "The background window's doorhanger is closed."
    206  );
    207  is(
    208    PanelUI.menuButton.hasAttribute("badge-status"),
    209    true,
    210    "The dismissed notification should still have a badge status"
    211  );
    212 
    213  AppMenuNotifications.removeNotification(/.*/);
    214 });