File: setSinkId.https.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (56 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!doctype html>
<head>
<title>Test setSinkId behavior </title>
<link rel="author" title="Dominique Hazael-Massieux" href="mailto:dom@w3.org"/>
<link rel="help" href="https://www.w3.org/TR/audio-output/#dom-htmlmediaelement-setsinkid">
</head>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src='../mediacapture-streams/permission-helper.js'></script>
<script>
"use strict";

const audio = new Audio();

promise_test(t => audio.setSinkId(""), "setSinkId on default audio output should always work");

promise_test(t => promise_rejects_dom(t, "NotFoundError", audio.setSinkId("nonexistent_device_id")),
  "setSinkId fails with NotFoundError on made up deviceid");

promise_test(async t => {
  // Attempt to expose some audiooutput devices.
  await setMediaPermission("granted", ["microphone"]);
  await navigator.mediaDevices.getUserMedia({ audio: true });
  const list = await navigator.mediaDevices.enumerateDevices();
  assert_greater_than(list.length, 0,
                      "media device list includes at least one device");
  const outputDevicesList = list.filter(({kind}) => kind == "audiooutput");
  for (const { deviceId, groupId } of outputDevicesList) {
    assert_greater_than(deviceId.length, 0, "deviceId.length");

    const p1 = audio.setSinkId(deviceId);
    assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
    let r;
    try {
      r = await p1;
    } catch (e) {
      // "If sinkId is not the empty string, and the application would not be
      // permitted to play audio through the device identified by sinkId if it
      // weren't the current user agent default device, reject p with a new
      // DOMException whose name is NotAllowedError and abort these
      // substeps."
      assert_equals(e.name, "NotAllowedError", "Non-permitted devices are failing with NotAllowed error");
      continue;
    }
    assert_equals(r, undefined, "setSinkId resolves with undefined");
    assert_equals(audio.sinkId, deviceId, "when it resolves, setSinkId updates sinkId to the requested deviceId");
    r = await audio.setSinkId(deviceId);
    assert_equals(r, undefined, "resetting sinkid on same current value should always work");
    r = await audio.setSinkId("");
    assert_equals(r, undefined, "resetting sinkid on default audio output should always work");
  }
}, "setSinkId() with output device IDs exposed by getUserMedia() should either reject with NotAllowedError or resolve");

</script>