tor-browser

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

browser_macos_indicator_hiding.js (3677B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 *
      5 * This test only runs for MacOS 14.0 and above to test the case for
      6 * Bug 1857254 - MacOS 14 displays two camera in use icons in menu bar
      7 */
      8 
      9 "use strict";
     10 
     11 const TEST_ROOT = getRootDirectory(gTestPath).replace(
     12  "chrome://mochitests/content/",
     13  "https://example.com/"
     14 );
     15 const TEST_PAGE = TEST_ROOT + "get_user_media.html";
     16 
     17 const { MockRegistrar } = ChromeUtils.importESModule(
     18  "resource://testing-common/MockRegistrar.sys.mjs"
     19 );
     20 
     21 var systemStatusBarService = {
     22  counter: 0,
     23  _reset() {
     24    this.counter = 0;
     25  },
     26  QueryInterface: ChromeUtils.generateQI(["nsISystemStatusBar"]),
     27 
     28  addItem(element) {
     29    info(
     30      `Add item call was fired for element ${element}, updating counter from ${
     31        this.counter
     32      } to ${this.counter + 1}`
     33    );
     34    this.counter += 1;
     35  },
     36 
     37  removeItem(element) {
     38    info(`remove item call was fired for element ${element}`);
     39  },
     40 };
     41 
     42 /**
     43 * Helper to test if the indicators are shown based on the params
     44 *
     45 * @param {object}
     46 *   expectedCount (number) - expected number of indicators turned on
     47 *   cameraState (boolean) - if the camera indicator should be shown
     48 *   microphoneState (boolean) - if the microphone indicator should be shown
     49 *   screenShareState (string) - if the screen share indicator should be shown
     50 *                                  (SCREEN_SHARE or "")
     51 */
     52 async function indicatorHelper({
     53  expectedCount,
     54  cameraState,
     55  microphoneState,
     56  shareScreenState,
     57 }) {
     58  await BrowserTestUtils.withNewTab(TEST_PAGE, async browser => {
     59    let indicatorPromise = promiseIndicatorWindow();
     60 
     61    await shareDevices(browser, cameraState, microphoneState, shareScreenState);
     62    await indicatorPromise;
     63  });
     64 
     65  is(
     66    systemStatusBarService.counter,
     67    expectedCount,
     68    `${expectedCount} indicator(s) should be shown`
     69  );
     70 
     71  systemStatusBarService._reset();
     72 }
     73 
     74 add_task(async function testIconChanges() {
     75  SpecialPowers.pushPrefEnv({
     76    set: [["privacy.webrtc.showIndicatorsOnMacos14AndAbove", false]],
     77  });
     78 
     79  let fakeStatusBarService = MockRegistrar.register(
     80    "@mozilla.org/widget/systemstatusbar;1",
     81    systemStatusBarService
     82  );
     83 
     84  systemStatusBarService._reset();
     85 
     86  registerCleanupFunction(function () {
     87    MockRegistrar.unregister(fakeStatusBarService);
     88  });
     89 
     90  info("Created mock system status bar service");
     91 
     92  let prefs = [
     93    [PREF_PERMISSION_FAKE, true],
     94    [PREF_AUDIO_LOOPBACK, ""],
     95    [PREF_VIDEO_LOOPBACK, ""],
     96    [PREF_FAKE_STREAMS, true],
     97    [PREF_FOCUS_SOURCE, false],
     98  ];
     99  await SpecialPowers.pushPrefEnv({ set: prefs });
    100 
    101  await indicatorHelper({
    102    expectedCount: 0,
    103    cameraState: true,
    104    microphoneState: true,
    105    shareScreenState: SHARE_SCREEN,
    106  });
    107  await indicatorHelper({
    108    expectedCount: 0,
    109    cameraState: true,
    110    microphoneState: false,
    111    shareScreenState: SHARE_SCREEN,
    112  });
    113 
    114  // In case we want to be able to see the indicator
    115  SpecialPowers.pushPrefEnv({
    116    set: [["privacy.webrtc.showIndicatorsOnMacos14AndAbove", true]],
    117  });
    118 
    119  await indicatorHelper({
    120    expectedCount: 3,
    121    cameraState: true,
    122    microphoneState: true,
    123    shareScreenState: SHARE_SCREEN,
    124  });
    125  await indicatorHelper({
    126    expectedCount: 1,
    127    cameraState: false,
    128    microphoneState: false,
    129    shareScreenState: SHARE_SCREEN,
    130  });
    131  await indicatorHelper({
    132    expectedCount: 1,
    133    cameraState: true,
    134    microphoneState: false,
    135    shareScreenState: "",
    136  });
    137  await indicatorHelper({
    138    expectedCount: 1,
    139    cameraState: false,
    140    microphoneState: true,
    141    shareScreenState: "",
    142  });
    143 
    144  await SpecialPowers.popPrefEnv();
    145 });