enumerateDevices-with-selectAudioOutput.https.html (2246B)
1 <!doctype html> 2 <head> 3 <title>Test effect of selectAudioOutput() on audiooutput devices from enumerateDevices()</title> 4 <link rel="help" href="https://w3c.github.io/mediacapture-output/#dom-mediadevices-selectaudiooutput"> 5 </head> 6 <body> 7 <p class="instructions">If prompted, <strong>please allow</strong> access to 8 an audio output device.</p> 9 </body> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="/resources/testdriver.js"></script> 13 <script src="/resources/testdriver-vendor.js"></script> 14 <script> 15 'use strict'; 16 17 promise_test(async () => { 18 const devices = await navigator.mediaDevices.enumerateDevices(); 19 const outputDevices = devices.filter(info => info.kind == "audiooutput"); 20 assert_equals(outputDevices.length, 0, "number of audiooutput devices."); 21 }, "enumerateDevices() returns no audiooutput devices before permission grant"); 22 23 let selected; 24 25 promise_test(async t => { 26 await test_driver.bless('transient activation for selectAudioOutput()'); 27 selected = await navigator.mediaDevices.selectAudioOutput(); 28 assert_true(selected instanceof MediaDeviceInfo, 29 "resolves with a MediaDeviceInfo."); 30 assert_equals(selected.kind, "audiooutput", "selected.kind"); 31 assert_greater_than(selected.deviceId.length, 0, "selected.deviceId.length"); 32 assert_greater_than(selected.groupId.length, 0, "selected.groupId.length"); 33 assert_not_equals(selected.label, undefined, "selected.label"); 34 }, "selectAudioOutput()"); 35 36 promise_test(async () => { 37 // "Once a device is exposed after a call to selectAudioOutput, it MUST be 38 // listed by enumerateDevices() for the current browsing context." 39 const devices = await navigator.mediaDevices.enumerateDevices(); 40 const outputDevices = devices.filter(info => info.kind == "audiooutput"); 41 assert_equals(outputDevices.length, 1, "number of audiooutput devices."); 42 assert_not_equals(selected, undefined); 43 const [info] = outputDevices; 44 assert_equals(info.deviceId, selected.deviceId, "deviceId exposed"); 45 assert_equals(info.groupId, selected.groupId, "groupId exposed"); 46 assert_equals(info.label, selected.label, "label exposed"); 47 }, "enumerateDevices() after selectAudioOutput()"); 48 </script>