tor-browser

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

browser_panelUINotifications_bannerVisibility.js (4093B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { AppMenuNotifications } = ChromeUtils.importESModule(
      7  "resource://gre/modules/AppMenuNotifications.sys.mjs"
      8 );
      9 
     10 /**
     11 * The update banner should become visible when the badge-only notification is
     12 * shown before opening the menu.
     13 */
     14 add_task(async function testBannerVisibilityBeforeOpen() {
     15  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     16 
     17  AppMenuNotifications.showBadgeOnlyNotification("update-restart");
     18 
     19  let menuButton = newWin.document.getElementById("PanelUI-menu-button");
     20  let shown = BrowserTestUtils.waitForEvent(
     21    newWin.PanelUI.mainView,
     22    "ViewShown"
     23  );
     24  menuButton.click();
     25  await shown;
     26 
     27  let banner = newWin.document.getElementById("appMenu-update-banner");
     28 
     29  let labelPromise = BrowserTestUtils.waitForMutationCondition(
     30    banner,
     31    { attributes: true, attributeFilter: ["label"] },
     32    () => banner.hasAttribute("label")
     33  );
     34 
     35  ok(!banner.hidden, "Update banner should be shown");
     36 
     37  await labelPromise;
     38 
     39  Assert.notEqual(
     40    banner.getAttribute("label"),
     41    "",
     42    "Update banner should contain text"
     43  );
     44 
     45  AppMenuNotifications.removeNotification(/.*/);
     46 
     47  await BrowserTestUtils.closeWindow(newWin);
     48 });
     49 
     50 /**
     51 * The update banner should become visible when the badge-only notification is
     52 * shown during the menu is opened.
     53 */
     54 add_task(async function testBannerVisibilityDuringOpen() {
     55  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     56 
     57  let menuButton = newWin.document.getElementById("PanelUI-menu-button");
     58  let shown = BrowserTestUtils.waitForEvent(
     59    newWin.PanelUI.mainView,
     60    "ViewShown"
     61  );
     62  menuButton.click();
     63  await shown;
     64 
     65  let banner = newWin.document.getElementById("appMenu-update-banner");
     66  ok(
     67    !banner.hasAttribute("label"),
     68    "Update banner shouldn't contain text before notification"
     69  );
     70 
     71  let labelPromise = BrowserTestUtils.waitForMutationCondition(
     72    banner,
     73    { attributes: true, attributeFilter: ["label"] },
     74    () => banner.hasAttribute("label")
     75  );
     76 
     77  AppMenuNotifications.showNotification("update-restart");
     78 
     79  ok(!banner.hidden, "Update banner should be shown");
     80 
     81  await labelPromise;
     82 
     83  Assert.notEqual(
     84    banner.getAttribute("label"),
     85    "",
     86    "Update banner should contain text"
     87  );
     88 
     89  AppMenuNotifications.removeNotification(/.*/);
     90 
     91  await BrowserTestUtils.closeWindow(newWin);
     92 });
     93 
     94 /**
     95 * The update banner should become visible when the badge-only notification is
     96 * shown after opening/closing the menu, so that the DOM tree is there but
     97 * the menu is closed.
     98 */
     99 add_task(async function testBannerVisibilityAfterClose() {
    100  let newWin = await BrowserTestUtils.openNewBrowserWindow();
    101 
    102  let menuButton = newWin.document.getElementById("PanelUI-menu-button");
    103  let shown = BrowserTestUtils.waitForEvent(
    104    newWin.PanelUI.mainView,
    105    "ViewShown"
    106  );
    107  menuButton.click();
    108  await shown;
    109 
    110  ok(newWin.PanelUI.mainView.hasAttribute("visible"));
    111 
    112  let banner = newWin.document.getElementById("appMenu-update-banner");
    113 
    114  ok(banner.hidden, "Update banner should be hidden before notification");
    115  ok(
    116    !banner.hasAttribute("label"),
    117    "Update banner shouldn't contain text before notification"
    118  );
    119 
    120  let labelPromise = BrowserTestUtils.waitForMutationCondition(
    121    banner,
    122    { attributes: true, attributeFilter: ["label"] },
    123    () => banner.hasAttribute("label")
    124  );
    125 
    126  let hidden = BrowserTestUtils.waitForCondition(() => {
    127    return !newWin.PanelUI.mainView.hasAttribute("visible");
    128  });
    129  menuButton.click();
    130  await hidden;
    131 
    132  AppMenuNotifications.showBadgeOnlyNotification("update-restart");
    133 
    134  shown = BrowserTestUtils.waitForEvent(newWin.PanelUI.mainView, "ViewShown");
    135  menuButton.click();
    136  await shown;
    137 
    138  ok(!banner.hidden, "Update banner should be shown");
    139 
    140  await labelPromise;
    141 
    142  Assert.notEqual(
    143    banner.getAttribute("label"),
    144    "",
    145    "Update banner should contain text"
    146  );
    147 
    148  AppMenuNotifications.removeNotification(/.*/);
    149 
    150  await BrowserTestUtils.closeWindow(newWin);
    151 });