File: setSinkId-with-selectAudioOutput.https.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (85 lines) | stat: -rw-r--r-- 3,419 bytes parent folder | download | duplicates (15)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!doctype html>
<head>
<title>Test setSinkId() before and after selectAudioOutput()</title>
<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>
"use strict";

let deviceId;
promise_test(async t => {
  await test_driver.bless('transient activation for selectAudioOutput()');
  ({deviceId} = await navigator.mediaDevices.selectAudioOutput());

  const audio = new Audio();
  const p1 = audio.setSinkId(deviceId);
  assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
  let r = await p1;
  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() after selectAudioOutput()");

const src = "/media/movie_5.webm";

promise_test(async t => {
  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
  const video = document.createElement('video');
  try {
    document.body.appendChild(video);
    video.src = src;
    await new Promise(r => video.onloadeddata = r);
    await video.setSinkId(deviceId);
    assert_equals(video.sinkId, deviceId, "sinkId after setSinkId()");
  } finally {
    video.remove();
  }
}, "setSinkId() on video after loadeddata");

promise_test(async t => {
  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
  const video = document.createElement('video');
  try {
    video.src = src;
    video.autoplay = true;
    video.loop = true;
    await new Promise(r => video.onplay = r);
    await video.setSinkId(deviceId);
    assert_equals(video.sinkId, deviceId, "sinkId after setSinkId()");
  } finally {
    video.pause();
  }
}, "setSinkId() on video after play");

// Use the same sinkId in another same-origin top-level browsing context.
// "the identifier MUST be the same in documents of the same origin in
// top-level browsing contexts."
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
promise_test(async t => {
  assert_not_equals(deviceId, undefined, "selectAudioOutput() resolved");
  const proxy = window.open('/common/blank.html');
  t.add_cleanup(() => proxy.close());
  await new Promise(r => proxy.onload = r);
  const pAudio = new proxy.Audio();
  await promise_rejects_dom(t, "NotFoundError", proxy.DOMException,
                            pAudio.setSinkId(deviceId),
                            "before selectAudioOutput()");
  await test_driver.bless('transient activation for selectAudioOutput()',
                          null, proxy);
  const { deviceId: pDeviceId } =
        await proxy.navigator.mediaDevices.selectAudioOutput({deviceId});
  assert_equals(pDeviceId, deviceId,
                "deviceIds should be same in each browsing context");
  await pAudio.setSinkId(deviceId);
  assert_equals(pAudio.sinkId, deviceId, "sinkId after setSinkId()");
}, "setSinkId() with deviceID from another window");
</script>