test_setSinkId.html (2745B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="mediaStreamPlayback.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 9 <script> 10 createHTML({ 11 title: "SetSinkId in HTMLMediaElement", 12 bug: "934425", 13 }); 14 15 const memoryReportPath = 'explicit/media/media-manager-aggregates'; 16 17 /** 18 * Run a test to verify set sink id in audio element. 19 */ 20 runTest(async () => { 21 await pushPrefs(["media.setsinkid.enabled", true]); 22 23 if (!SpecialPowers.getCharPref("media.audio_loopback_dev", "")) { 24 ok(false, "No loopback device set by framework. Try --use-test-media-devices"); 25 return; 26 } 27 28 // Expose an audio output device. 29 SpecialPowers.wrap(document).notifyUserGestureActivation(); 30 await navigator.mediaDevices.selectAudioOutput(); 31 32 const allDevices = await navigator.mediaDevices.enumerateDevices(); 33 const audioDevices = allDevices.filter(({kind}) => kind == 'audiooutput'); 34 is(audioDevices.length, 1, "Number of output devices found"); 35 36 const audio = createMediaElement("audio", "audio"); 37 document.body.appendChild(audio); 38 39 is(audio.sinkId, "", "Initial value is empty string"); 40 41 const p = audio.setSinkId(audioDevices[0].deviceId); 42 is(audio.sinkId, "", "Value is unchanged upon function return"); 43 is(await p, undefined, "promise resolves with undefined"); 44 is(audio.sinkId, audioDevices[0].deviceId, `Sink device is set, id: ${audio.sinkId}`); 45 46 await audio.setSinkId(audioDevices[0].deviceId); 47 ok(true, `Sink device is set for 2nd time for the same id: ${audio.sinkId}`); 48 49 try { 50 await audio.setSinkId("dummy sink id"); 51 ok(false, "Never enter here, this must fail"); 52 } catch (error) { 53 ok(true, `Set sink id expected to fail: ${error}`); 54 is(error.name, "NotFoundError", "Verify correct error"); 55 } 56 57 const {usage: usage1} = 58 await collectMemoryUsage(memoryReportPath); // Provided by head.js 59 60 ok(usage1 > 0, "MediaManager memory usage should be non-zero to store \ 61 device ids after enumerateDevices"); 62 63 const p2 = audio.setSinkId(""); 64 is(audio.sinkId, audioDevices[0].deviceId, 65 'sinkId after setSinkId("") return'); 66 is(await p2, undefined, 67 "promise resolution value when sinkId parameter is empty"); 68 is(audio.sinkId, "", 'sinkId after setSinkId("") resolution'); 69 70 await audio.setSinkId(audioDevices[0].deviceId); 71 72 const {usage: usage2, reportCount} = 73 await collectMemoryUsage(memoryReportPath); 74 is(reportCount, 1, 75 'Expect only one MediaManager to report in content processes.'); 76 is(usage2, usage1, "MediaManager memory usage should return to previous \ 77 value after promise resolution"); 78 }); 79 80 </script> 81 </pre> 82 </body> 83 </html>