tor-browser

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

setSinkId.https.html (2615B)


      1 <!doctype html>
      2 <head>
      3 <title>Test setSinkId behavior </title>
      4 <link rel="author" title="Dominique Hazael-Massieux" href="mailto:dom@w3.org"/>
      5 <link rel="help" href="https://www.w3.org/TR/audio-output/#dom-htmlmediaelement-setsinkid">
      6 </head>
      7 <script src=/resources/testharness.js></script>
      8 <script src=/resources/testharnessreport.js></script>
      9 <script src=/resources/testdriver.js></script>
     10 <script src=/resources/testdriver-vendor.js></script>
     11 <script src='../mediacapture-streams/permission-helper.js'></script>
     12 <script>
     13 "use strict";
     14 
     15 const audio = new Audio();
     16 
     17 promise_test(t => audio.setSinkId(""), "setSinkId on default audio output should always work");
     18 
     19 promise_test(t => promise_rejects_dom(t, "NotFoundError", audio.setSinkId("nonexistent_device_id")),
     20  "setSinkId fails with NotFoundError on made up deviceid");
     21 
     22 promise_test(async t => {
     23  // Attempt to expose some audiooutput devices.
     24  await setMediaPermission("granted", ["microphone"]);
     25  await navigator.mediaDevices.getUserMedia({ audio: true });
     26  const list = await navigator.mediaDevices.enumerateDevices();
     27  assert_greater_than(list.length, 0,
     28                      "media device list includes at least one device");
     29  const outputDevicesList = list.filter(({kind}) => kind == "audiooutput");
     30  for (const { deviceId, groupId } of outputDevicesList) {
     31    assert_greater_than(deviceId.length, 0, "deviceId.length");
     32 
     33    const p1 = audio.setSinkId(deviceId);
     34    assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
     35    let r;
     36    try {
     37      r = await p1;
     38    } catch (e) {
     39      // "If sinkId is not the empty string, and the application would not be
     40      // permitted to play audio through the device identified by sinkId if it
     41      // weren't the current user agent default device, reject p with a new
     42      // DOMException whose name is NotAllowedError and abort these
     43      // substeps."
     44      assert_equals(e.name, "NotAllowedError", "Non-permitted devices are failing with NotAllowed error");
     45      continue;
     46    }
     47    assert_equals(r, undefined, "setSinkId resolves with undefined");
     48    assert_equals(audio.sinkId, deviceId, "when it resolves, setSinkId updates sinkId to the requested deviceId");
     49    r = await audio.setSinkId(deviceId);
     50    assert_equals(r, undefined, "resetting sinkid on same current value should always work");
     51    r = await audio.setSinkId("");
     52    assert_equals(r, undefined, "resetting sinkid on default audio output should always work");
     53  }
     54 }, "setSinkId() with output device IDs exposed by getUserMedia() should either reject with NotAllowedError or resolve");
     55 
     56 </script>