gecko-dev/testing/web-platform/tests/audio-output/setSinkId.https.html
Boris Zbarsky 745b772897 Bug 1613394 [wpt PR 21600] - Replace some "promise_rejects(t, 'SomeDOMError', stuff)" calls with p…, a=testonly
Automatic update from web-platform-tests
Replace some "promise_rejects(t, 'SomeDOMError', stuff)" calls with promise_rejects_dom.

This diff was generated by running:

  find . -type f -print0 | xargs -0 perl -pi -e "BEGIN { \$/ = undef; } s/promise_rejects\(([ \n]*[a-zA-Z_]+[ \n]*,[ \n]*)([\"'][A-Za-z_]*[\"']) *(, *.)/promise_rejects_dom(\1\2\3/gs"

in bash (doesn't work in tcsh, due to the $ inside "").

--

wpt-commits: b7f2dd315a8d84ce786f6336510ee51423011009
wpt-pr: 21600
2020-02-14 19:09:14 +00:00

46 lines
2 KiB
HTML

<!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>
"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 => {
const list = await navigator.mediaDevices.enumerateDevices();
const outputDevicesList = list.filter(({kind}) => kind == "audiooutput");
assert_not_equals(outputDevicesList.length, 0,
"media device list includes at least one audio output device");
let acceptedDevices = 0;
for (const {deviceId} of outputDevicesList) {
const {deviceId} = outputDevicesList[0];
const p1 = audio.setSinkId(deviceId);
assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
try {
let r = await p1;
assert_equals(acceptedDevices, 0, "only the default sink device can be set");
acceptedDevices++;
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");
} catch (e) {
assert_equals(e.name, "NotAllowedError", "Non-default devices are failing with NotAllowed error");
}
}
}, "List device, setSinkId should be allowed on the default, the rest of the devices will get a NotAllowedError");
</script>