From 8a163574a045971918b6af589889d60030969614 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Thu, 29 Feb 2024 19:36:21 +0000 Subject: [PATCH] Bug 1882685 use async/await to manage asynchronicity in some PannerNode tests r=padenot Differential Revision: https://phabricator.services.mozilla.com/D203083 --- .../test/test_pannerNodeAtZeroDistance.html | 38 ++++++------------ .../test/test_pannerNode_maxDistance.html | 40 +++++++------------ 2 files changed, 28 insertions(+), 50 deletions(-) diff --git a/dom/media/webaudio/test/test_pannerNodeAtZeroDistance.html b/dom/media/webaudio/test/test_pannerNodeAtZeroDistance.html index a0c20f01fe36..9772dbf18850 100644 --- a/dom/media/webaudio/test/test_pannerNodeAtZeroDistance.html +++ b/dom/media/webaudio/test/test_pannerNodeAtZeroDistance.html @@ -17,15 +17,7 @@ var types = [ "HRTF" ] -var finished = 2 * types.length; - -function finish() { - if (!--finished) { - SimpleTest.finish(); - } -} - -function testMono(type) { +async function testMono(type) { var ac = new OfflineAudioContext(1, BUF_SIZE, 44100); // A sine to be used to fill the buffers @@ -76,13 +68,11 @@ function testMono(type) { monoBuffer.getChannelData(0)[i] = gain * monoBuffer.getChannelData(0)[i]; } - ac.startRendering().then(function(buffer) { - compareBuffers(buffer, monoBuffer); - finish(); - }); + const buffer = await ac.startRendering(); + compareBuffers(buffer, monoBuffer); } -function testStereo(type) { +async function testStereo(type) { var ac = new OfflineAudioContext(2, BUF_SIZE, 44100); // A sine to be used to fill the buffers @@ -126,23 +116,21 @@ function testStereo(type) { panner3.connect(ac.destination); - ac.startRendering().then(function(buffer) { - compareBuffers(buffer, stereoBuffer); - finish(); - }); + const buffer = await ac.startRendering(); + compareBuffers(buffer, stereoBuffer); } -function test(type) { - testMono(type); - testStereo(type); +async function test(type) { + await testMono(type) + await testStereo(type); } -addLoadEvent(function() { - types.forEach(test); +add_task(async function() { + for (const panningModel of types) { + await test(panningModel); + } }); -SimpleTest.waitForExplicitFinish(); - diff --git a/dom/media/webaudio/test/test_pannerNode_maxDistance.html b/dom/media/webaudio/test/test_pannerNode_maxDistance.html index b5286e56e1a9..33de1fefdc51 100644 --- a/dom/media/webaudio/test/test_pannerNode_maxDistance.html +++ b/dom/media/webaudio/test/test_pannerNode_maxDistance.html @@ -14,15 +14,7 @@ var types = [ "HRTF" ] -var finished = types.length; - -function finish() { - if (!--finished) { - SimpleTest.finish(); - } -} - -function test(type) { +async function test(type) { var ac = new OfflineAudioContext(1, 128, 44100); var osc = ac.createOscillator(); var panner = ac.createPanner(); @@ -37,27 +29,25 @@ function test(type) { osc.start(); - ac.startRendering().then(function(buffer) { - var silence = true; - var array = buffer.getChannelData(0); - for (var i = 0; i < buffer.length; i++) { - if (array[i] != 0) { - ok(false, "Found noise in the buffer."); - silence = false; - } + const buffer = await ac.startRendering() + + var silence = true; + var array = buffer.getChannelData(0); + for (var i = 0; i < buffer.length; i++) { + if (array[i] != 0) { + ok(false, "Found noise in the buffer."); + silence = false; } - ok(silence, "The buffer is silent."); - finish(); - }); + } + ok(silence, "The buffer is silent."); } - -addLoadEvent(function() { - types.forEach(test); +add_task(async function() { + for (const panningModel of types) { + await test(panningModel); + } }); -SimpleTest.waitForExplicitFinish(); -