Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js

Issue 2672863007: Convert Panner distance model tests to testharness (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js
index 933cc146496c9f5dc6c158cda53256432232d052..0d9d07a7696b09991fb0b820965726966e7d1687 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/distance-model-testing.js
@@ -101,7 +101,7 @@ function createGraph(context, distanceModel, nodeCount) {
// distanceModel should be the distance model string like
// "linear", "inverse", or "exponential".
-function createTestAndRun(context, distanceModel) {
+function createTestAndRun(context, distanceModel, should) {
// To test the distance models, we create a number of panners at
// uniformly spaced intervals on the z-axis. Each of these are
// started at equally spaced time intervals. After rendering the
@@ -111,8 +111,8 @@ function createTestAndRun(context, distanceModel) {
createGraph(context, distanceModel, nodesToCreate);
- context.oncomplete = checkDistanceResult(distanceModel);
- context.startRendering();
+ return context.startRendering()
+ .then(buffer => checkDistanceResult(buffer, distanceModel, should));
}
// The gain caused by the EQUALPOWER panning model, if we stay on the
@@ -121,86 +121,65 @@ function equalPowerGain() {
return Math.SQRT1_2;
}
-function checkDistanceResult(model) {
- return function(event) {
- renderedBuffer = event.renderedBuffer;
- renderedData = renderedBuffer.getChannelData(0);
+function checkDistanceResult(renderedBuffer, model, should) {
+ renderedData = renderedBuffer.getChannelData(0);
- // The max allowed error between the actual gain and the expected
- // value. This is determined experimentally. Set to 0 to see what
- // the actual errors are.
- var maxAllowedError = 3.3e-6;
+ // The max allowed error between the actual gain and the expected
hongchan 2017/02/17 18:31:04 If the indentation is changed, we might just wrap
Raymond Toy 2017/02/17 19:10:11 Done.
+ // value. This is determined experimentally. Set to 0 to see what
+ // the actual errors are.
+ var maxAllowedError = 3.3e-6;
- var success = true;
-
- // Number of impulses we found in the rendered result.
- var impulseCount = 0;
-
- // Maximum relative error in the gain of the impulses.
- var maxError = 0;
-
- // Array of locations of the impulses that were not at the
- // expected location. (Contains the actual and expected frame
- // of the impulse.)
- var impulsePositionErrors = new Array();
-
- // Step through the rendered data to find all the non-zero points
- // so we can find where our distance-attenuated impulses are.
- // These are tested against the expected attenuations at that
- // distance.
- for (var k = 0; k < renderedData.length; ++k) {
- if (renderedData[k] != 0) {
- // Convert from string to index.
- var distanceFunction = distanceModelFunction[model];
- var expected = distanceFunction(panner[impulseCount], 0, 0, position[impulseCount]);
-
- // Adjust for the center-panning of the EQUALPOWER panning
- // model that we're using.
- expected *= equalPowerGain();
-
- var error = Math.abs(renderedData[k] - expected) / Math.abs(expected);
-
- maxError = Math.max(maxError, Math.abs(error));
-
- // Keep track of any impulses that aren't where we expect them
- // to be.
- var expectedOffset = timeToSampleFrame(time[impulseCount], sampleRate);
- if (k != expectedOffset) {
- impulsePositionErrors.push({ actual : k, expected : expectedOffset});
- }
- ++impulseCount;
+ var success = true;
+
+ // Number of impulses we found in the rendered result.
+ var impulseCount = 0;
+
+ // Maximum relative error in the gain of the impulses.
+ var maxError = 0;
+
+ // Array of locations of the impulses that were not at the
+ // expected location. (Contains the actual and expected frame
+ // of the impulse.)
+ var impulsePositionErrors = new Array();
+
+ // Step through the rendered data to find all the non-zero points
+ // so we can find where our distance-attenuated impulses are.
+ // These are tested against the expected attenuations at that
+ // distance.
+ for (var k = 0; k < renderedData.length; ++k) {
+ if (renderedData[k] != 0) {
+ // Convert from string to index.
+ var distanceFunction = distanceModelFunction[model];
+ var expected = distanceFunction(panner[impulseCount], 0, 0, position[impulseCount]);
+
+ // Adjust for the center-panning of the EQUALPOWER panning
+ // model that we're using.
+ expected *= equalPowerGain();
+
+ var error = Math.abs(renderedData[k] - expected) / Math.abs(expected);
+
+ maxError = Math.max(maxError, Math.abs(error));
+
+ // Keep track of any impulses that aren't where we expect them
+ // to be.
+ var expectedOffset = timeToSampleFrame(time[impulseCount], sampleRate);
+ if (k != expectedOffset) {
+ impulsePositionErrors.push({ actual : k, expected : expectedOffset});
}
+ ++impulseCount;
}
+ }
- if (impulseCount == nodesToCreate) {
- testPassed("Number of impulses found matches number of panner nodes.");
- } else {
- testFailed("Number of impulses is incorrect. Found " + impulseCount + " but expected " + nodesToCreate + ".");
- success = false;
- }
-
- if (maxError <= maxAllowedError) {
- testPassed("Distance gains are correct.");
- } else {
- testFailed("Distance gains are incorrect. Max rel error = " + maxError + " (maxAllowedError = " + maxAllowedError + ")");
- success = false;
- }
-
- // Display any timing errors that we found.
- if (impulsePositionErrors.length > 0) {
- success = false;
- testFailed(impulsePositionErrors.length + " timing errors found");
- for (var k = 0; k < impulsePositionErrors.length; ++k) {
- testFailed("Sample at frame " + impulsePositionErrors[k].actual + " but expected " + impulsePositionErrors[k].expected);
- }
- }
+ should(impulseCount, "Number of impulses")
+ .beEqualTo(nodesToCreate);
- if (success) {
- testPassed("Distance test passed for distance model " + model);
- } else {
- testFailed("Distance test failed for distance model " + model);
- }
+ should(maxError, "Max error in distance gains")
+ .beLessThanOrEqualTo(maxAllowedError);
- finishJSTest();
+ // Display any timing errors that we found.
+ if (impulsePositionErrors.length > 0) {
+ let actual = impulsePositionErrors.map(x => x.actual);
+ let expected = impulsePositionErrors.map(x => x.expected);
+ should(actual).beEqualTo(expected);
hongchan 2017/02/17 18:31:04 Are you okay with no description for both argument
Raymond Toy 2017/02/17 19:10:12 No. And I think this is wrong because actual and e
}
}

Powered by Google App Engine
This is Rietveld 408576698