tor-browser

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

browser_fxa_badge.js (1805B)


      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 add_task(async function test_unconfigured_no_badge() {
     11  const oldUIState = UIState.get;
     12 
     13  UIState.get = () => ({
     14    status: UIState.STATUS_NOT_CONFIGURED,
     15  });
     16  Services.obs.notifyObservers(null, UIState.ON_UPDATE);
     17  checkFxABadge(false);
     18 
     19  UIState.get = oldUIState;
     20 });
     21 
     22 add_task(async function test_signedin_no_badge() {
     23  const oldUIState = UIState.get;
     24 
     25  UIState.get = () => ({
     26    status: UIState.STATUS_SIGNED_IN,
     27    lastSync: new Date(),
     28    email: "foo@bar.com",
     29  });
     30  Services.obs.notifyObservers(null, UIState.ON_UPDATE);
     31  checkFxABadge(false);
     32 
     33  UIState.get = oldUIState;
     34 });
     35 
     36 add_task(async function test_unverified_badge_shown() {
     37  const oldUIState = UIState.get;
     38 
     39  UIState.get = () => ({
     40    status: UIState.STATUS_NOT_VERIFIED,
     41    email: "foo@bar.com",
     42  });
     43  Services.obs.notifyObservers(null, UIState.ON_UPDATE);
     44  checkFxABadge(true);
     45 
     46  UIState.get = oldUIState;
     47 });
     48 
     49 add_task(async function test_loginFailed_badge_shown() {
     50  const oldUIState = UIState.get;
     51 
     52  UIState.get = () => ({
     53    status: UIState.STATUS_LOGIN_FAILED,
     54    email: "foo@bar.com",
     55  });
     56  Services.obs.notifyObservers(null, UIState.ON_UPDATE);
     57  checkFxABadge(true);
     58 
     59  UIState.get = oldUIState;
     60 });
     61 
     62 function checkFxABadge(shouldBeShown) {
     63  let fxaButton = document.getElementById("fxa-toolbar-menu-button");
     64  let isShown =
     65    fxaButton.hasAttribute("badge-status") ||
     66    fxaButton
     67      .querySelector(".toolbarbutton-badge")
     68      .classList.contains("feature-callout");
     69  is(isShown, shouldBeShown, "Fxa badge shown matches expected value.");
     70 }