Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| index 49b376b6889bfd1543568c3c26284d954a3ad119..be8852a322310a6a8900bd8a191e3424d8ea4527 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| +++ b/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| @@ -35,6 +35,7 @@ |
| OscillatorTestingUtils = (function () { |
| +var audit = Audit.createTaskRunner(); |
|
hongchan
2017/02/07 18:18:53
Not sure what's fixed here.
Raymond Toy
2017/02/07 18:57:58
Forgot to remove it.
Raymond Toy
2017/02/07 18:57:58
Oops. Forgot to remove this.
|
| var sampleRate = 44100.0; |
| var nyquist = 0.5 * sampleRate; |
| var lengthInSeconds = 4; |
| @@ -109,21 +110,24 @@ function calculateSNR(sPower, nPower) |
| return 10 * Math.log10(sPower / nPower); |
| } |
| -function loadReferenceAndRunTest(oscType) { |
| - var bufferLoader = new BufferLoader( |
| +function loadReferenceAndRunTest(context, oscType, task, should) { |
| + var bufferLoader = new BufferLoader( |
| context, |
| [ "../Oscillator/oscillator-" + oscType + "-expected.wav" ], |
| function (bufferList) { |
| reference = bufferList[0].getChannelData(0); |
| generateExponentialOscillatorSweep(context, oscType); |
| - context.oncomplete = checkResult; |
| + context.oncomplete = () => { |
| + checkResult(event, should); |
| + task.done(); |
| + }; |
| context.startRendering(); |
| }); |
| bufferLoader.load(); |
| } |
| -function checkResult (event) { |
| +function checkResult (event, should) { |
| renderedData = event.renderedBuffer.getChannelData(0); |
| // Compute signal to noise ratio between the result and the reference. Also keep track |
| // of the max difference (and position). |
| @@ -148,30 +152,15 @@ function checkResult (event) { |
| } |
| var snr = calculateSNR(signalPower, noisePower); |
| - if (snr >= thresholdSNR) { |
| - testPassed("Exceeded SNR threshold of " + thresholdSNR + " dB"); |
| - } else { |
| - testFailed("Expected SNR of " + thresholdSNR + " dB, but actual SNR is " + snr + " dB"); |
| - } |
| - |
| - if (maxError <= thresholdDiff) { |
| - testPassed("Maximum difference below threshold of " |
| - + (thresholdDiff * waveScaleFactor) + " ulp (16-bits)"); |
| - } else { |
| - testFailed("Maximum difference of " + (maxError * waveScaleFactor) + " at " |
| - + errorPosition + " exceeded threshold of " + (thresholdDiff * waveScaleFactor) |
| - + " ulp (16-bits)"); |
| - } |
| - |
| - if (diffCount <= thresholdDiffCount) { |
| - testPassed("Number of differences between actual and expected result is less than " + thresholdDiffCount |
| - + " out of " + renderedData.length); |
| - } else { |
| - testFailed(diffCount + " differences found but expected no more than " + thresholdDiffCount |
| - + " out of " + renderedData.length); |
| - } |
| - |
| - finishJSTest(); |
| + should(snr, "SNR") |
| + .beGreaterThanOrEqualTo(thresholdSNR); |
| + should(maxError * waveScaleFactor, "Maximum difference in ulp (16-bits)") |
| + .beLessThanOrEqualTo(thresholdDiff * waveScaleFactor); |
| + |
| + should(diffCount, |
| + "Number of differences between actual and expected result out of " |
| + + renderedData.length + " frames") |
| + .beLessThanOrEqualTo(thresholdDiffCount); |
| } |
| function setThresholds(thresholds) { |
| @@ -180,10 +169,8 @@ function setThresholds(thresholds) { |
| thresholdDiffCount = thresholds.diffCount; |
| } |
| -function runTest(oscType) { |
| - window.jsTestIsAsync = true; |
| - context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRate); |
| - loadReferenceAndRunTest(oscType); |
| +function runTest(context, oscType, description, task, should) { |
| + loadReferenceAndRunTest(context, oscType, task, should); |
| } |
| function createNewReference(oscType) { |
| @@ -207,7 +194,6 @@ return { |
| thresholdDiffCount: thresholdDiffCount, |
| waveScaleFactor: waveScaleFactor, |
| setThresholds: setThresholds, |
| - loadReferenceAndRunTest: loadReferenceAndRunTest, |
| runTest: runTest, |
| createNewReference: createNewReference, |
| }; |