Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html |
| index fe0ca7008956e9b7659374bdada6c233eaa88fb0..5cceecf3b201aec959cc03b7a16c281df60051dd 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html |
| +++ b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html |
| @@ -1,9 +1,10 @@ |
| -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| +<!doctype> |
| <html> |
| <head> |
| - <script src="../../resources/js-test.js"></script> |
| + <script src="../../resources/testharness.js"></script> |
| + <script src="../../resources/testharnessreport.js"></script> |
| <script src="../resources/audit-util.js"></script> |
| - <script src="../resources/audio-testing.js"></script> |
| + <script src="../resources/audit.js"></script> |
| <script src="../resources/note-grain-on-testing.js"></script> |
| </head> |
| @@ -12,7 +13,7 @@ |
| <div id="console"></div> |
| <script> |
| - description("Test noteGrainOn offset rendering."); |
| + let audit = Audit.createTaskRunner(); |
| // To test noteGrainOn, a single ramp signal is created. |
| // Various sections of the ramp are rendered by noteGrainOn() at |
| @@ -20,25 +21,27 @@ |
| // consists of the correct section of the ramp at the correct |
| // time. |
| - var linearRampBuffer; |
| + let linearRampBuffer; |
| // Array of the grain offset used for each ramp played. |
| - var grainOffsetTime = []; |
| + let grainOffsetTime = []; |
| // Verify the received signal is a ramp from the correct section |
| // of our ramp signal. |
| function verifyGrain(renderedData, startFrame, endFrame, grainIndex) { |
| - var grainOffsetFrame = timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate); |
| - var grainFrameLength = endFrame - startFrame; |
| - var ramp = linearRampBuffer.getChannelData(0); |
| - var isCorrect = true; |
| - |
| - var expected; |
| - var actual; |
| - var frame; |
| - |
| - for (var k = 0; k < grainFrameLength; ++k) { |
| - if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) { |
| + let grainOffsetFrame = timeToSampleFrame(grainOffsetTime[ |
| + grainIndex], sampleRate); |
| + let grainFrameLength = endFrame - startFrame; |
| + let ramp = linearRampBuffer.getChannelData(0); |
| + let isCorrect = true; |
| + |
| + let expected; |
| + let actual; |
| + let frame; |
| + |
| + for (let k = 0; k < grainFrameLength; ++k) { |
| + if (renderedData[startFrame + k] != ramp[grainOffsetFrame + |
| + k]) { |
| expected = ramp[grainOffsetFrame + k]; |
| actual = renderedData[startFrame + k]; |
| frame = startFrame + k; |
| @@ -46,90 +49,71 @@ |
| break; |
| } |
| } |
| - return { verified: isCorrect, |
| - expected : expected , |
| - actual : actual, |
| - frame : frame }; |
| + return { |
| + verified: isCorrect, |
| + expected: expected, |
| + actual: actual, |
| + frame: frame |
| + }; |
| } |
| - |
| - function checkResult(event) { |
| - var buffer = event.renderedBuffer; |
| - renderedData = buffer.getChannelData(0); |
| - var nSamples = renderedData.length; |
| - var success = true; |
| + function checkResult(buffer, should) { |
| + renderedData = buffer.getChannelData(0); |
|
hongchan
2017/01/20 17:46:09
This is bad. We need |let| here. I know it happene
Raymond Toy
2017/01/20 19:37:10
renderedData is defined in note-grain-on-testing.j
|
| + let nSamples = renderedData.length; |
| // Number of grains that we found that have incorrect data. |
| - var invalidGrainDataCount = 0; |
| - |
| - var startEndFrames = findStartAndEndSamples(renderedData); |
| + let invalidGrainDataCount = 0; |
| + |
| + let startEndFrames = findStartAndEndSamples(renderedData); |
| // Verify the start and stop times. Not strictly needed for |
| // this test, but it's useful to know that if the ramp data |
| // appears to be incorrect. |
| - success = success && verifyStartAndEndFrames(startEndFrames); |
| + verifyStartAndEndFrames(startEndFrames, should); |
| // Loop through each of the rendered grains and check that |
| // each grain contains our expected ramp. |
| - for (var k = 0; k < startEndFrames.start.length; ++k) { |
| + for (let k = 0; k < startEndFrames.start.length; ++k) { |
| // Verify that the rendered data matches the expected |
| // section of our ramp signal. |
| - var result = verifyGrain(renderedData, startEndFrames.start[k], startEndFrames.end[k], k); |
| - |
| - if (!result.verified) { |
| - testFailed("Grain " + k + " incorrect. Expected " + result.expected + " but received " + result.actual + " at sample frame " + result.frame); |
| - ++invalidGrainDataCount; |
| - success = false; |
| - } |
| - } |
| - |
| - if (!invalidGrainDataCount) { |
| - testPassed("All " + numberOfTests + " grains contained the correct data."); |
| - } else { |
| - testFailed(invalidGrainDataCount + " grains out of " + numberOfTests + " did not contain the expected data."); |
| - success = false; |
| + let result = verifyGrain(renderedData, startEndFrames.start[ |
| + k], startEndFrames.end[k], k); |
| + should(result.verified, "Pulse " + k + " contained the expected data") |
|
hongchan
2017/01/20 17:46:09
Should be wrapped.
Raymond Toy
2017/01/20 19:37:10
Done.
|
| + .beTrue(); |
| } |
| - |
| - if (success) { |
| - testPassed("noteGrainOn offset rendering tests passed."); |
| - } else { |
| - testFailed("noteGrainOn offset rendering tests failed."); |
| - } |
| - |
| - finishJSTest(); |
| + should(invalidGrainDataCount, |
| + "Number of grains that did not contain the expected data" |
| + ) |
| + .beEqualTo(0); |
| } |
| - function runTest() { |
| - if (window.testRunner) { |
| - testRunner.dumpAsText(); |
| - testRunner.waitUntilDone(); |
| - } |
| - |
| - window.jsTestIsAsync = true; |
| - |
| + audit.define("note-grain-on-play", function(task, should) { |
| + task.describe("Test noteGrainOn offset rendering"); |
| // Create offline audio context. |
| - context = new OfflineAudioContext(2, sampleRate * renderTime, sampleRate); |
| + context = new OfflineAudioContext(2, sampleRate * |
| + renderTime, sampleRate); |
| // Create a linear ramp for testing noteGrainOn. |
| linearRampBuffer = createSignalBuffer(context, |
| - function(k) { |
| - // Want the ramp to start |
| - // with 1, not 0. |
| - return k + 1; |
| - }); |
| + function(k) { |
| + // Want the ramp to start |
| + // with 1, not 0. |
| + return k + 1; |
| + }); |
| - var grainInfo = playAllGrains(context, linearRampBuffer, numberOfTests); |
| + let grainInfo = playAllGrains(context, linearRampBuffer, |
| + numberOfTests); |
| grainOffsetTime = grainInfo.grainOffsetTimes; |
| - context.oncomplete = checkResult; |
| - context.startRendering(); |
| - } |
| + context.startRendering() |
| + .then(function(audioBuffer) { |
| + checkResult(audioBuffer, should); |
|
hongchan
2017/01/20 17:46:09
This does not return a promise and it's synchronou
Raymond Toy
2017/01/20 19:37:10
Done.
|
| + }) |
| + .then(task.done.bind(task)); |
| + }); |
| - runTest(); |
| - successfullyParsed = true; |
| - |
| + audit.run(); |
| </script> |
| - |
| </body> |
| </html> |