tor-browser

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

browser_notification_stacking.js (1982B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function addNotification(box, label, value, priorityName) {
      7  let added = BrowserTestUtils.waitForNotificationInNotificationBox(box, value);
      8  let priority = gNotificationBox[`PRIORITY_${priorityName}_MEDIUM`];
      9  let notification = box.appendNotification(value, { label, priority });
     10  await added;
     11  return notification;
     12 }
     13 
     14 add_task(async function testStackingOrder() {
     15  const tabNotificationBox = gBrowser.getNotificationBox();
     16  ok(
     17    gNotificationBox.stack.hasAttribute("prepend-notifications"),
     18    "Browser stack will prepend"
     19  );
     20  ok(
     21    !tabNotificationBox.stack.hasAttribute("prepend-notifications"),
     22    "Tab stack will append"
     23  );
     24 
     25  let browserOne = await addNotification(
     26    gNotificationBox,
     27    "My first browser notification",
     28    "browser-one",
     29    "INFO"
     30  );
     31 
     32  let tabOne = await addNotification(
     33    tabNotificationBox,
     34    "My first tab notification",
     35    "tab-one",
     36    "CRITICAL"
     37  );
     38 
     39  let browserTwo = await addNotification(
     40    gNotificationBox,
     41    "My second browser notification",
     42    "browser-two",
     43    "CRITICAL"
     44  );
     45  let browserThree = await addNotification(
     46    gNotificationBox,
     47    "My third browser notification",
     48    "browser-three",
     49    "WARNING"
     50  );
     51 
     52  let tabTwo = await addNotification(
     53    tabNotificationBox,
     54    "My second tab notification",
     55    "tab-two",
     56    "INFO"
     57  );
     58  let tabThree = await addNotification(
     59    tabNotificationBox,
     60    "My third tab notification",
     61    "tab-three",
     62    "WARNING"
     63  );
     64 
     65  Assert.deepEqual(
     66    [browserThree, browserTwo, browserOne],
     67    [...gNotificationBox.stack.children],
     68    "Browser notifications prepended"
     69  );
     70  Assert.deepEqual(
     71    [tabOne, tabTwo, tabThree],
     72    [...tabNotificationBox.stack.children],
     73    "Tab notifications appended"
     74  );
     75 
     76  gNotificationBox.removeAllNotifications(true);
     77  tabNotificationBox.removeAllNotifications(true);
     78 });