diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html')
-rw-r--r-- | dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html b/dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html new file mode 100644 index 0000000000..ceb4d82b50 --- /dev/null +++ b/dom/media/webrtc/tests/mochitests/test_setSinkId_preMutedElement.html @@ -0,0 +1,98 @@ +<!DOCTYPE HTML> +<html> +<head> + <script src="mediaStreamPlayback.js"></script> +</head> +<body> +<pre id="test"> +<script type="application/javascript"> +createHTML({ + title: "Test changing sink and muting before the MediaStream is set", + bug: "1651049", + visible: true +}); + +let getOutputDeviceId = async () => { + let devices = await navigator.mediaDevices.enumerateDevices(); + let audios = devices.filter(d => d.kind == "audiooutput"); + ok(audios.length, "One or more output devices found."); + return audios[0].deviceId; +} + +let verifyAudioTone = async (ac, stream, freq) => { + const toneAnalyser = new AudioStreamAnalyser(ac, stream); + return toneAnalyser.waitForAnalysisSuccess(array => { + const lowerFreq = freq / 2; + const upperFreq = freq + 1000; + const lowerMag = array[toneAnalyser.binIndexForFrequency(lowerFreq)]; + const freqMag = array[toneAnalyser.binIndexForFrequency(freq)]; + const upperMag = array[toneAnalyser.binIndexForFrequency(upperFreq)]; + info("Audio tone expected. " + + lowerFreq + ": " + lowerMag + ", " + + freq + ": " + freqMag + ", " + + upperFreq + ": " + upperMag); + return lowerMag < 50 && freqMag > 200 && upperMag < 50; + }); +} + +let verifyNoAudioTone = async (ac, stream, freq) => { + const toneAnalyser = new AudioStreamAnalyser(ac, stream); + // repeat check 100 times to make sure that it is muted. + let retryCnt = 0; + return toneAnalyser.waitForAnalysisSuccess(array => { + const lowerFreq = freq / 2; + const upperFreq = freq + 1000; + const lowerMag = array[toneAnalyser.binIndexForFrequency(lowerFreq)]; + const freqMag = array[toneAnalyser.binIndexForFrequency(freq)]; + const upperMag = array[toneAnalyser.binIndexForFrequency(upperFreq)]; + info("No audio tone expected. " + + lowerFreq + ": " + lowerMag + ", " + + freq + ": " + freqMag + ", " + + upperFreq + ": " + upperMag); + return lowerMag == 0 && freqMag == 0 && upperMag == 0 && ++retryCnt == 100; + }); +} + +runTest(async () => { + let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", ""); + if (!audioDevice) { + todo(false, "No loopback device set by framework. Try --use-test-media-devices"); + return; + } + + await pushPrefs(["media.setsinkid.enabled", true]); + + // Implicitly expose the loopback device sink by opening the source in the + // same group. + const verifyStream = await getUserMedia({audio: true}); + + let sinkId = await getOutputDeviceId(); + isnot(sinkId, "", "SinkId is not null"); + + let audioElement = createMediaElement('audio', 'audioElement'); + audioElement.muted = true; + await audioElement.setSinkId(sinkId); + isnot(audioElement.sinkId, "", "sinkId property of the element is not null"); + + // The test stream is a sine tone of 1000 Hz + let ac = new AudioContext(); + const frequency = 2000; + let stream = createOscillatorStream(ac, frequency); + await verifyAudioTone(ac, stream, frequency); + + audioElement.srcObject = stream; + audioElement.play(); + + // Verify the silent output using the loopback device. + await verifyNoAudioTone(ac, verifyStream, frequency); + info("output is muted"); + + // Clean up + audioElement.pause(); + audioElement.srcObject = null; + verifyStream.getTracks()[0].stop(); +}); +</script> +</pre> +</body> +</html> |