tor-browser

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

head.js (2049B)


      1 // Platforms may default to reducing motion. We override this to ensure the
      2 // alert slide animation is enabled in tests.
      3 SpecialPowers.pushPrefEnv({
      4  set: [["ui.prefersReducedMotion", 0]],
      5 });
      6 
      7 async function addNotificationPermission(originString) {
      8  return SpecialPowers.pushPermissions([
      9    {
     10      type: "desktop-notification",
     11      allow: true,
     12      context: originString,
     13    },
     14  ]);
     15 }
     16 
     17 /**
     18 * Similar to `BrowserTestUtils.closeWindow`, but
     19 * doesn't call `window.close()`.
     20 */
     21 function promiseWindowClosed(window) {
     22  return new Promise(function (resolve) {
     23    Services.ww.registerNotification(function observer(subject, topic) {
     24      if (topic == "domwindowclosed" && subject == window) {
     25        Services.ww.unregisterNotification(observer);
     26        resolve();
     27      }
     28    });
     29  });
     30 }
     31 
     32 /**
     33 * These two functions work with file_dom_notifications.html to open the
     34 * notification and close it.
     35 *
     36 * |fn| can be showNotification1 or showNotification2.
     37 * if |timeout| is passed, then the promise returned from this function is
     38 * rejected after the requested number of miliseconds.
     39 */
     40 function openNotification(aBrowser, fn, timeout) {
     41  info(`openNotification: ${fn}`);
     42  return SpecialPowers.spawn(
     43    aBrowser,
     44    [[fn, timeout]],
     45    async function ([contentFn, contentTimeout]) {
     46      await new Promise((resolve, reject) => {
     47        let win = content.wrappedJSObject;
     48        let notification = win[contentFn]();
     49        win._notification = notification;
     50 
     51        function listener() {
     52          notification.removeEventListener("show", listener);
     53          resolve();
     54        }
     55 
     56        notification.addEventListener("show", listener);
     57 
     58        if (contentTimeout) {
     59          content.setTimeout(() => {
     60            notification.removeEventListener("show", listener);
     61            reject("timed out");
     62          }, contentTimeout);
     63        }
     64      });
     65    }
     66  );
     67 }
     68 
     69 function closeNotification(aBrowser) {
     70  return SpecialPowers.spawn(aBrowser, [], function () {
     71    content.wrappedJSObject._notification.close();
     72  });
     73 }