| Index: third_party/WebKit/LayoutTests/webaudio/constructor/periodicwave.html
|
| diff --git a/third_party/WebKit/LayoutTests/webaudio/constructor/periodicwave.html b/third_party/WebKit/LayoutTests/webaudio/constructor/periodicwave.html
|
| index 7485edc87da0e3813e53859ee2e9e480a63f784f..90b389c7c1e17f6690516b5e6bc1782230f3c00d 100644
|
| --- a/third_party/WebKit/LayoutTests/webaudio/constructor/periodicwave.html
|
| +++ b/third_party/WebKit/LayoutTests/webaudio/constructor/periodicwave.html
|
| @@ -5,8 +5,8 @@
|
| <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="audionodeoptions.js"></script>
|
| + <script src="../resources/audit.js"></script>
|
| + <script src="new-audionodeoptions.js"></script>
|
| </head>
|
|
|
| <body>
|
| @@ -15,246 +15,159 @@
|
|
|
| var audit = Audit.createTaskRunner();
|
|
|
| - audit.defineTask("initialize", function (taskDone) {
|
| - Should("context = new OfflineAudioContext(...)", function () {
|
| - context = new OfflineAudioContext(1, 1, 48000);
|
| - }).notThrow();
|
| -
|
| - taskDone();
|
| + audit.define('initialize', (task, should) => {
|
| + context = initializeContext(should);
|
| + task.done();
|
| });
|
|
|
| - audit.defineTask("invalid constructor", function (taskDone) {
|
| - var node;
|
| - var success = true;
|
| -
|
| - success = Should("new PeriodicWave()", function () {
|
| - node = new PeriodicWave();
|
| - }).throw("TypeError");
|
| - success = Should("new PeriodicWave(1)", function () {
|
| - node = new PeriodicWave(1) && success;
|
| - }).throw("TypeError");
|
| - success = Should("new PeriodicWave(context, 42)", function () {
|
| - node = new PeriodicWave(context, 42) && success;
|
| - }).throw("TypeError");
|
| -
|
| - Should("Invalid constructors", success)
|
| - .summarize(
|
| - "correctly threw errors",
|
| - "did not throw errors in all cases");
|
| -
|
| - taskDone();
|
| + audit.define('invalid constructor', (task, should) => {
|
| + testInvalidConstructor(should, 'PeriodicWave', context);
|
| + task.done();
|
| });
|
|
|
| - audit.defineTask("default constructor", function (taskDone) {
|
| - var node;
|
| - var success = true;
|
| -
|
| - success = Should("node = new PeriodicWave(context)", function () {
|
| + audit.define('default constructor', (task, should) => {
|
| + should(() => {
|
| node = new PeriodicWave(context);
|
| - }).notThrow();
|
| + }, 'node = new PeriodicWave(context)').notThrow();
|
|
|
| - taskDone();
|
| + task.done();
|
| });
|
|
|
| - audit.defineTask("constructor with options", function (taskDone) {
|
| + audit.define('constructor with options', (task, should) => {
|
| var node1;
|
| - var success = true;
|
| -
|
| - var options = {
|
| - real: [1, 1]
|
| - };
|
| - success = Should("node = new PeriodicWave(context, " + JSON.stringify(options) + ")",
|
| - function () {
|
| - node1 = new PeriodicWave(context, options);
|
| - }).notThrow();
|
| - success = Should("node1 instanceof PeriodicWave", node1 instanceof PeriodicWave)
|
| - .beEqualTo(true) && success;
|
| + var options = {real: [1, 1]};
|
| + should(
|
| + () => {
|
| + node1 = new PeriodicWave(context, options);
|
| + },
|
| + 'node = new PeriodicWave(context, ' + JSON.stringify(options) + ')')
|
| + .notThrow();
|
| + should(node1 instanceof PeriodicWave, 'node1 instanceof PeriodicWave')
|
| + .beEqualTo(true);
|
|
|
| var node2;
|
| - options = {
|
| - imag: [1, 1]
|
| - };
|
| - success = Should("node2 = new PeriodicWave(context, " + JSON.stringify(options) + ")",
|
| - function () {
|
| - node2 = new PeriodicWave(context, options);
|
| - }).notThrow();
|
| - success = Should("node2 instanceof PeriodicWave", node2 instanceof PeriodicWave)
|
| - .beEqualTo(true) && success;
|
| -
|
| - var node3;
|
| - options = {
|
| - real: [1, 2],
|
| - imag: [1, 1]
|
| - };
|
| - success = Should("node3 = new PeriodicWave(context, " + JSON.stringify(options) + ")",
|
| - function () {
|
| - node3 = new PeriodicWave(context, options);
|
| - }).notThrow();
|
| - success = Should("node3 instanceof PeriodicWave", node3 instanceof PeriodicWave)
|
| - .beEqualTo(true) && success;
|
| -
|
| - Should("new PeriodicWave() with options", success)
|
| - .summarize(
|
| - "constructed with correct attributes",
|
| - "was not constructed correctly");
|
| -
|
| - taskDone();
|
| + options = {imag: [1, 1]};
|
| + should(
|
| + () => {
|
| + node2 = new PeriodicWave(context, options);
|
| + },
|
| + 'node2 = new PeriodicWave(context, ' + JSON.stringify(options) +
|
| + ')')
|
| + .notThrow();
|
| + should(node2 instanceof PeriodicWave, 'node2 instanceof PeriodicWave')
|
| + .beEqualTo(true);
|
| +
|
| + var node3;
|
| + options = {real: [1, 2], imag: [1, 1]};
|
| + should(
|
| + () => {
|
| + node3 = new PeriodicWave(context, options);
|
| + },
|
| + 'node3 = new PeriodicWave(context, ' + JSON.stringify(options) +
|
| + ')')
|
| + .notThrow();
|
| + should(node3 instanceof PeriodicWave, 'node3 instanceof PeriodicWave')
|
| + .beEqualTo(true);
|
| +
|
| + task.done();
|
| });
|
| -
|
| +
|
| // The following test that the correct waveforms are produced when various
|
| // possible PeriodicWave options are used. These are needed because it's
|
| // the only way to tell if the various options were correctly applied.
|
|
|
| // TODO(rtoy): These functionality tests should be moved out to a separate
|
| // file.
|
| - audit.defineTask("1: real periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - real: [0, 2]
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - var normalizationFactor = 0.5;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = Math.cos(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 2.7143e-5).then(taskDone);
|
| + audit.define('1: real periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {real: [0, 2]}, generateReference(Math.cos), 2.7143e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("2: real periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - real: [0, 2],
|
| - disableNormalization: false
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = Math.cos(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 2.7143e-5).then(taskDone);
|
| - }),
|
| -
|
| - audit.defineTask("3: real periodicwave test", function (taskDone) {
|
| -
|
| - waveTest({
|
| - real: [0, 2],
|
| - disableNormalization: true
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = 2 * Math.cos(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 5.4285e-5).then(taskDone);
|
| + audit.define('2: real periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {real: [0, 2], disableNormalization: false},
|
| + generateReference(Math.cos), 2.7143e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("1: imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - imag: [0, 2]
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = Math.sin(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 2.7232e-5).then(taskDone);
|
| + audit.define('3: real periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {real: [0, 2], disableNormalization: true},
|
| + generateReference(x => 2 * Math.cos(x)), 5.4285e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("2: imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - imag: [0, 2],
|
| - disableNormalization: false
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = Math.sin(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 2.7232e-5).then(taskDone);
|
| + audit.define('1: imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {imag: [0, 2]}, generateReference(Math.sin), 2.7232e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("3: imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - imag: [0, 2],
|
| - disableNormalization: true
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = 2 * Math.sin(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 5.4464e-5).then(taskDone);
|
| + audit.define('2: imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {imag: [0, 2], disableNormalization: false},
|
| + generateReference(Math.sin), 2.7232e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("1: real/imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - real: [0, 1],
|
| - imag: [0, 1],
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - var normalizationFactor = Math.SQRT1_2;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = normalizationFactor * (Math.sin(omega * k) + Math.cos(omega * k));
|
| - }
|
| - return expected;
|
| - },
|
| - 3.8371e-5).then(taskDone);
|
| + audit.define('3: imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {imag: [0, 2], disableNormalization: true},
|
| + generateReference(x => 2 * Math.sin(x)), 5.4464e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("2: real/imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - real: [0, 1],
|
| - imag: [0, 1],
|
| - disableNormalization: false
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - var normalizationFactor = Math.SQRT1_2;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = normalizationFactor * (Math.sin(omega * k) + Math.cos(omega * k));
|
| - }
|
| - return expected;
|
| - },
|
| - 2.7165e-5).then(taskDone);
|
| + audit.define('1: real/imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {
|
| + real: [0, 1],
|
| + imag: [0, 1],
|
| + },
|
| + generateReference(x => Math.SQRT1_2 * (Math.sin(x) + Math.cos(x))),
|
| + 3.8371e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask("3: real/imag periodicwave test", function (taskDone) {
|
| - waveTest({
|
| - real: [0, 1],
|
| - imag: [0, 1],
|
| - disableNormalization: true
|
| - }, function (length, freq, sampleRate) {
|
| - var expected = new Float32Array(length);
|
| - var omega = 2 * Math.PI * freq / sampleRate;
|
| - for (var k = 0; k < length; ++k) {
|
| - expected[k] = Math.sin(omega * k) + Math.cos(omega * k);
|
| - }
|
| - return expected;
|
| - },
|
| - 3.8416e-5).then(taskDone);
|
| + audit.define('2: real/imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {real: [0, 1], imag: [0, 1], disableNormalization: false},
|
| + generateReference(x => Math.SQRT1_2 * (Math.sin(x) + Math.cos(x))),
|
| + 2.7165e-5)
|
| + .then(() => task.done());
|
| });
|
|
|
| - function waveTest(waveOptions, expectedFunction, threshold) {
|
| - var node;
|
| - var success = true;
|
| + audit.define('3: real/imag periodicwave test', (task, should) => {
|
| + verifyPeriodicWaveOutput(
|
| + should, {real: [0, 1], imag: [0, 1], disableNormalization: true},
|
| + generateReference(x => Math.sin(x) + Math.cos(x)), 3.8416e-5)
|
| + .then(() => task.done());
|
| + });
|
|
|
| + // Returns a function that generates the expected reference array where
|
| + // the samples are generated by the function |gen|.
|
| + function generateReference(gen) {
|
| + return (length, freq, sampleRate) => {
|
| + var expected = new Float32Array(length);
|
| + var omega = 2 * Math.PI * freq / sampleRate;
|
| + for (var k = 0; k < length; ++k) {
|
| + expected[k] = gen(omega * k);
|
| + }
|
| + return expected;
|
| + };
|
| + }
|
| +
|
| + // Verify that an oscillator constructed from the given periodic wave
|
| + // produces the expected result.
|
| + function verifyPeriodicWaveOutput(
|
| + should, waveOptions, expectedFunction, threshold) {
|
| + var node;
|
| // Rather arbitrary sample rate and render length. Length doesn't have
|
| // to be very long.
|
| var sampleRate = 48000;
|
| var renderLength = 0.25;
|
| - var testContext = new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
|
| + var testContext =
|
| + new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
|
|
|
| var options = {
|
| periodicWave: new PeriodicWave(testContext, waveOptions)
|
| @@ -265,35 +178,36 @@
|
| node.connect(testContext.destination);
|
| node.start();
|
|
|
| - return testContext.startRendering().then(function (resultBuffer) {
|
| + return testContext.startRendering().then(function(resultBuffer) {
|
| var actual = resultBuffer.getChannelData(0);
|
| - var expected = expectedFunction(actual.length,
|
| - node.frequency.value,
|
| - testContext.sampleRate);
|
| + var expected = expectedFunction(
|
| + actual.length, node.frequency.value, testContext.sampleRate);
|
| // Actual must match expected to within the (experimentally)
|
| // determined threshold.
|
| - var message = "";
|
| + var message = '';
|
| if (waveOptions.disableNormalization != undefined)
|
| - message = "disableNormalization: " + waveOptions.disableNormalization;
|
| + message =
|
| + 'disableNormalization: ' + waveOptions.disableNormalization;
|
| if (waveOptions.real) {
|
| if (message.length > 0)
|
| - message += ", "
|
| - message += "real: [" + waveOptions.real + "]";
|
| + message += ', '
|
| + message += 'real: [' + waveOptions.real + ']';
|
| }
|
| if (waveOptions.imag) {
|
| if (message.length > 0)
|
| - message += ", "
|
| - message += "imag: [" + waveOptions.imag + "]";
|
| + message += ', '
|
| + message += 'imag: [' + waveOptions.imag + ']';
|
| }
|
| - Should("Oscillator with periodicWave {" + message + "}", actual)
|
| - .beCloseToArray(expected, threshold);
|
| + should(actual, 'Oscillator with periodicWave {' + message + '}')
|
| + .beCloseToArray(expected, {absoluteThreshold: threshold});
|
| });
|
| }
|
|
|
| - function sineWaveTest(waveFun, message) {
|
| - // Verify that the default PeriodicWave produces a sine wave. Use a
|
| - // 2-channel context to verify this. Channel 0 is the output from the
|
| - // PeriodicWave, and channel 1 is the reference oscillator output.
|
| + // Verify that the default PeriodicWave produces a sine wave. Use a
|
| + // 2-channel context to verify this.
|
| + function sineWaveTest(should, waveFun, message) {
|
| + // Channel 0 is the output from the PeriodicWave, and channel 1 is the
|
| + // reference oscillator output.
|
| let context = new OfflineAudioContext(2, 40000, 40000);
|
| let oscRef =
|
| new OscillatorNode(context, {type: 'sine', frequency: 440});
|
| @@ -316,29 +230,29 @@
|
| let actual = output.getChannelData(0);
|
| let ref = output.getChannelData(1);
|
|
|
| - Should(message, actual).beEqualToArray(ref);
|
| + should(actual, message).beEqualToArray(ref);
|
| });
|
| }
|
|
|
| - audit.defineTask('default wave', function(taskDone) {
|
| + audit.define('default wave', (task, should) => {
|
| // Verify that the default PeriodicWave produces a sine wave.
|
| sineWaveTest(
|
| - (context) => new PeriodicWave(context),
|
| + should, (context) => new PeriodicWave(context),
|
| 'new PeriodicWave(context) output')
|
| - .then(taskDone);
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.defineTask('default wave (with dict)', function(taskDone) {
|
| + audit.define('default wave (with dict)', (task, should) => {
|
| // Verify that the default PeriodicWave produces a sine wave when the
|
| // PeriodicWaveOptions dictionary is given, but real and imag members
|
| // are not set.
|
| sineWaveTest(
|
| - (context) => new PeriodicWave(context, {foo: 42}),
|
| + should, (context) => new PeriodicWave(context, {foo: 42}),
|
| 'new PeriodicWave(context, {foo: 42}) output')
|
| - .then(taskDone);
|
| + .then(() => task.done());
|
| });
|
|
|
| - audit.runTasks();
|
| + audit.run();
|
| </script>
|
| </body>
|
| </html>
|
|
|