tor-browser

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

setSinkId-with-selectAudioOutput.https.html (3419B)


      1 <!doctype html>
      2 <head>
      3 <title>Test setSinkId() before and after selectAudioOutput()</title>
      4 <link rel="help" href="https://www.w3.org/TR/audio-output/#dom-htmlmediaelement-setsinkid">
      5 </head>
      6 <script src=/resources/testharness.js></script>
      7 <script src=/resources/testharnessreport.js></script>
      8 <script src="/resources/testdriver.js"></script>
      9 <script src="/resources/testdriver-vendor.js"></script>
     10 <script>
     11 "use strict";
     12 
     13 let deviceId;
     14 promise_test(async t => {
     15  await test_driver.bless('transient activation for selectAudioOutput()');
     16  ({deviceId} = await navigator.mediaDevices.selectAudioOutput());
     17 
     18  const audio = new Audio();
     19  const p1 = audio.setSinkId(deviceId);
     20  assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
     21  let r = await p1;
     22  assert_equals(r, undefined, "setSinkId resolves with undefined");
     23  assert_equals(audio.sinkId, deviceId, "when it resolves, setSinkId updates sinkId to the requested deviceId");
     24 
     25  r = await audio.setSinkId(deviceId);
     26  assert_equals(r, undefined, "resetting sinkid on same current value should always work");
     27 
     28  r = await audio.setSinkId("");
     29  assert_equals(r, undefined, "resetting sinkid on default audio output should always work");
     30 }, "setSinkId() after selectAudioOutput()");
     31 
     32 const src = "/media/movie_5.webm";
     33 
     34 promise_test(async t => {
     35  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
     36  const video = document.createElement('video');
     37  try {
     38    document.body.appendChild(video);
     39    video.src = src;
     40    await new Promise(r => video.onloadeddata = r);
     41    await video.setSinkId(deviceId);
     42    assert_equals(video.sinkId, deviceId, "sinkId after setSinkId()");
     43  } finally {
     44    video.remove();
     45  }
     46 }, "setSinkId() on video after loadeddata");
     47 
     48 promise_test(async t => {
     49  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
     50  const video = document.createElement('video');
     51  try {
     52    video.src = src;
     53    video.autoplay = true;
     54    video.loop = true;
     55    await new Promise(r => video.onplay = r);
     56    await video.setSinkId(deviceId);
     57    assert_equals(video.sinkId, deviceId, "sinkId after setSinkId()");
     58  } finally {
     59    video.pause();
     60  }
     61 }, "setSinkId() on video after play");
     62 
     63 // Use the same sinkId in another same-origin top-level browsing context.
     64 // "the identifier MUST be the same in documents of the same origin in
     65 // top-level browsing contexts."
     66 // https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
     67 promise_test(async t => {
     68  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
     69  const proxy = window.open('/common/blank.html');
     70  t.add_cleanup(() => proxy.close());
     71  await new Promise(r => proxy.onload = r);
     72  const pAudio = new proxy.Audio();
     73  await promise_rejects_dom(t, "NotFoundError", proxy.DOMException,
     74                            pAudio.setSinkId(deviceId),
     75                            "before selectAudioOutput()");
     76  await test_driver.bless('transient activation for selectAudioOutput()',
     77                          null, proxy);
     78  const { deviceId: pDeviceId } =
     79        await proxy.navigator.mediaDevices.selectAudioOutput({deviceId});
     80  assert_equals(pDeviceId, deviceId,
     81                "deviceIds should be same in each browsing context");
     82  await pAudio.setSinkId(deviceId);
     83  assert_equals(pAudio.sinkId, deviceId, "sinkId after setSinkId()");
     84 }, "setSinkId() with deviceID from another window");
     85 </script>