tor-browser

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

browser_tab_sharing_state.js (2848B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Tests gBrowser#updateBrowserSharing
      6 */
      7 add_task(async function testBrowserSharingStateSetter() {
      8  const WEBRTC_TEST_STATE = {
      9    camera: 0,
     10    microphone: 1,
     11    paused: false,
     12    sharing: "microphone",
     13    showMicrophoneIndicator: true,
     14    showScreenSharingIndicator: "",
     15    windowId: 0,
     16  };
     17 
     18  const WEBRTC_TEST_STATE2 = {
     19    camera: 1,
     20    microphone: 1,
     21    paused: false,
     22    sharing: "camera",
     23    showCameraIndicator: true,
     24    showMicrophoneIndicator: true,
     25    showScreenSharingIndicator: "",
     26    windowId: 1,
     27  };
     28 
     29  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
     30    let tab = gBrowser.selectedTab;
     31    is(tab._sharingState, undefined, "No sharing state initially.");
     32    ok(!tab.hasAttribute("sharing"), "No tab sharing attribute initially.");
     33 
     34    // Set an active sharing state for webrtc
     35    gBrowser.updateBrowserSharing(browser, { webRTC: WEBRTC_TEST_STATE });
     36    Assert.deepEqual(
     37      tab._sharingState,
     38      { webRTC: WEBRTC_TEST_STATE },
     39      "Should have correct webRTC sharing state."
     40    );
     41    is(
     42      tab.getAttribute("sharing"),
     43      WEBRTC_TEST_STATE.sharing,
     44      "Tab sharing attribute reflects webRTC sharing state."
     45    );
     46 
     47    // Set sharing state for geolocation
     48    gBrowser.updateBrowserSharing(browser, { geo: true });
     49    Assert.deepEqual(
     50      tab._sharingState,
     51      {
     52        webRTC: WEBRTC_TEST_STATE,
     53        geo: true,
     54      },
     55      "Should have sharing state for both webRTC and geolocation."
     56    );
     57    is(
     58      tab.getAttribute("sharing"),
     59      WEBRTC_TEST_STATE.sharing,
     60      "Geolocation sharing doesn't update the tab sharing attribute."
     61    );
     62 
     63    // Update webRTC sharing state
     64    gBrowser.updateBrowserSharing(browser, { webRTC: WEBRTC_TEST_STATE2 });
     65    Assert.deepEqual(
     66      tab._sharingState,
     67      { geo: true, webRTC: WEBRTC_TEST_STATE2 },
     68      "Should have updated webRTC sharing state while maintaining geolocation state."
     69    );
     70    is(
     71      tab.getAttribute("sharing"),
     72      WEBRTC_TEST_STATE2.sharing,
     73      "Tab sharing attribute reflects webRTC sharing state."
     74    );
     75 
     76    // Clear webRTC sharing state
     77    gBrowser.updateBrowserSharing(browser, { webRTC: null });
     78    Assert.deepEqual(
     79      tab._sharingState,
     80      { geo: true, webRTC: null },
     81      "Should only have sharing state for geolocation."
     82    );
     83    ok(
     84      !tab.hasAttribute("sharing"),
     85      "Ending webRTC sharing should remove tab sharing attribute."
     86    );
     87 
     88    // Clear geolocation sharing state
     89    gBrowser.updateBrowserSharing(browser, { geo: null });
     90    Assert.deepEqual(tab._sharingState, { geo: null, webRTC: null });
     91    ok(
     92      !tab.hasAttribute("sharing"),
     93      "Tab sharing attribute should not be set."
     94    );
     95  });
     96 });