tor-browser

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

browser_devices_get_user_media_anim.js (3779B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 var gTests = [
      5  {
      6    desc: "device sharing animation on background tabs",
      7    run: async function checkAudioVideo() {
      8      async function getStreamAndCheckBackgroundAnim(aAudio, aVideo, aSharing) {
      9        // Get a stream
     10        let observerPromise = expectObserverCalled("getUserMedia:request");
     11        let popupPromise = promisePopupNotificationShown("webRTC-shareDevices");
     12        await promiseRequestDevice(aAudio, aVideo);
     13        await popupPromise;
     14        await observerPromise;
     15 
     16        let observerPromise1 = expectObserverCalled(
     17          "getUserMedia:response:allow"
     18        );
     19        let observerPromise2 = expectObserverCalled("recording-device-events");
     20        await promiseMessage("ok", () => {
     21          PopupNotifications.panel.firstElementChild.button.click();
     22        });
     23        await observerPromise1;
     24        await observerPromise2;
     25        let expected = {};
     26        if (aVideo) {
     27          expected.video = true;
     28        }
     29        if (aAudio) {
     30          expected.audio = true;
     31        }
     32        Assert.deepEqual(
     33          await getMediaCaptureState(),
     34          expected,
     35          "expected " + Object.keys(expected).join(" and ") + " to be shared"
     36        );
     37 
     38        // Check the attribute on the tab, and check there's no visible
     39        // sharing icon on the tab
     40        let tab = gBrowser.selectedTab;
     41        is(
     42          tab.getAttribute("sharing"),
     43          aSharing,
     44          "the tab has the attribute to show the " + aSharing + " icon"
     45        );
     46        let icon = tab.sharingIcon;
     47        is(
     48          window.getComputedStyle(icon).display,
     49          "none",
     50          "the animated sharing icon of the tab is hidden"
     51        );
     52 
     53        // After selecting a new tab, check the attribute is still there,
     54        // and the icon is now visible.
     55        await BrowserTestUtils.switchTab(
     56          gBrowser,
     57          BrowserTestUtils.addTab(gBrowser)
     58        );
     59        is(
     60          gBrowser.selectedTab.getAttribute("sharing"),
     61          null,
     62          "the new tab doesn't have the 'sharing' attribute"
     63        );
     64        is(
     65          tab.getAttribute("sharing"),
     66          aSharing,
     67          "the tab still has the 'sharing' attribute"
     68        );
     69        isnot(
     70          window.getComputedStyle(icon).display,
     71          "none",
     72          "the animated sharing icon of the tab is now visible"
     73        );
     74 
     75        // Ensure the icon disappears when selecting the tab.
     76        BrowserTestUtils.removeTab(gBrowser.selectedTab);
     77        ok(tab.selected, "the tab with ongoing sharing is selected again");
     78        is(
     79          window.getComputedStyle(icon).display,
     80          "none",
     81          "the animated sharing icon is gone after selecting the tab again"
     82        );
     83 
     84        // And finally verify the attribute is removed when closing the stream.
     85        await closeStream();
     86 
     87        // TODO(Bug 1304997): Fix the race in closeStream() and remove this
     88        // TestUtils.waitForCondition().
     89        await TestUtils.waitForCondition(() => !tab.getAttribute("sharing"));
     90        is(
     91          tab.getAttribute("sharing"),
     92          null,
     93          "the tab no longer has the 'sharing' attribute after closing the stream"
     94        );
     95      }
     96 
     97      await getStreamAndCheckBackgroundAnim(true, true, "camera");
     98      await getStreamAndCheckBackgroundAnim(false, true, "camera");
     99      await getStreamAndCheckBackgroundAnim(true, false, "microphone");
    100 
    101      let browser = gBrowser.selectedBrowser;
    102      PermissionTestUtils.remove(browser.currentURI, "camera");
    103      PermissionTestUtils.remove(browser.currentURI, "microphone");
    104    },
    105  },
    106 ];
    107 
    108 add_task(async function test() {
    109  await runTests(gTests);
    110 });