diff --git a/dom/media/webaudio/test/mochitest.ini b/dom/media/webaudio/test/mochitest.ini index 4cbf6d78a6de..254e380dc136 100644 --- a/dom/media/webaudio/test/mochitest.ini +++ b/dom/media/webaudio/test/mochitest.ini @@ -196,6 +196,9 @@ tags=capturestream [test_mediaStreamAudioSourceNodePassThrough.html] [test_mediaStreamAudioSourceNodeResampling.html] tags=capturestream +[test_mediaStreamTrackAudioSourceNode.html] +[test_mediaStreamTrackAudioSourceNodeVideo.html] +[test_mediaStreamTrackAudioSourceNodeCrossOrigin.html] [test_mixingRules.html] skip-if = toolkit == 'android' # bug 1091965 [test_nodeToParamConnection.html] diff --git a/dom/media/webaudio/test/test_mediaStreamAudioSourceNodeNoGC.html b/dom/media/webaudio/test/test_mediaStreamAudioSourceNodeNoGC.html index 4a8fc1cfdd26..e7004c8ee558 100644 --- a/dom/media/webaudio/test/test_mediaStreamAudioSourceNodeNoGC.html +++ b/dom/media/webaudio/test/test_mediaStreamAudioSourceNodeNoGC.html @@ -14,8 +14,8 @@ SimpleTest.requestFlakyTimeout("gUM and WebAudio data is async to main thread. " "We need a timeout to see that something does " + "NOT happen to data."); -var context = new AudioContext(); -var analyser = context.createAnalyser(); +let context = new AudioContext(); +let analyser = context.createAnalyser(); function wait(millis, resolveWithThis) { return new Promise(resolve => setTimeout(() => resolve(resolveWithThis), millis)); @@ -26,15 +26,15 @@ function binIndexForFrequency(frequency) { } function waitForAudio(analysisFunction, cancelPromise) { - var data = new Uint8Array(analyser.frequencyBinCount); - var cancelled = false; - var cancelledMsg = ""; + let data = new Uint8Array(analyser.frequencyBinCount); + let cancelled = false; + let cancelledMsg = ""; cancelPromise.then(msg => { cancelled = true; cancelledMsg = msg; }); return new Promise((resolve, reject) => { - var loop = () => { + let loop = () => { analyser.getByteFrequencyData(data); if (cancelled) { reject(new Error("waitForAudio cancelled: " + cancelledMsg)); @@ -50,20 +50,8 @@ function waitForAudio(analysisFunction, cancelPromise) { }); } -SpecialPowers.pushPrefEnv({ - set: [ - // This test expects the fake audio device, specifically for the tones - // it outputs. Explicitly disable the audio loopback device and enable - // fake streams. - ['media.audio_loopback_dev', ''], - ['media.navigator.streams.fake', true] - ] -}).then(async () => { +async function test(sourceNode) { try { - let stream = await navigator.mediaDevices.getUserMedia({audio: true}); - stream.onended = () => ended = true; - let source = context.createMediaStreamSource(stream); - source.connect(analyser); await analyser.connect(context.destination); ok(true, "Waiting for audio to pass through the analyser") @@ -83,12 +71,45 @@ SpecialPowers.pushPrefEnv({ () => Promise.resolve()); ok(true, "Audio is still flowing"); - SimpleTest.finish(); } catch(e) { ok(false, "Error executing test: " + e + (e.stack ? "\n" + e.stack : "")); SimpleTest.finish(); } -}); +} + +(async function() { + try { + await SpecialPowers.pushPrefEnv({ + set: [ + // This test expects the fake audio device, specifically for the tones + // it outputs. Explicitly disable the audio loopback device and enable + // fake streams. + ['media.audio_loopback_dev', ''], + ['media.navigator.streams.fake', true], + ['media.navigator.permission.disabled', true] + ] + }); + + // Test stream source GC + let stream = await navigator.mediaDevices.getUserMedia({audio: true}); + let source = context.createMediaStreamSource(stream); + stream = null; + source.connect(analyser); + await test(source); + + // Test track source GC + stream = await navigator.mediaDevices.getUserMedia({audio: true}); + source = context.createMediaStreamTrackSource(stream.getAudioTracks()[0]); + stream = null; + source.connect(analyser); + await test(source); + } catch(e) { + ok(false, `Error executing test: ${e}${e.stack ? "\n" + e.stack : ""}`); + } finally { + context.close(); + SimpleTest.finish(); + } +})(); diff --git a/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNode.html b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNode.html new file mode 100644 index 000000000000..7523b52fd631 --- /dev/null +++ b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNode.html @@ -0,0 +1,54 @@ + + + + + Test MediaStreamTrackAudioSourceNode processing is correct + + + + + +
+
+
+ + diff --git a/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeCrossOrigin.html b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeCrossOrigin.html new file mode 100644 index 000000000000..26e0c6849e63 --- /dev/null +++ b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeCrossOrigin.html @@ -0,0 +1,53 @@ + + + + +Test MediaStreamTrackAudioSourceNode doesn't get data from cross-origin media resources + + + + +
+
+
+ diff --git a/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeVideo.html b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeVideo.html new file mode 100644 index 000000000000..9e4ff2332b3b --- /dev/null +++ b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeVideo.html @@ -0,0 +1,27 @@ + + + + + Test MediaStreamTrackAudioSourceNode throw video track + + + + + + +
+
+
+ +