Index: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-clamp-time-to-current-time.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-clamp-time-to-current-time.html b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-clamp-time-to-current-time.html |
index 287a1b8de1c294aa1a7eb56649ba61d11a55e9c2..f8aa9994e3e92a4947b7fcba8a8a31f2892f3d53 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-clamp-time-to-current-time.html |
+++ b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-clamp-time-to-current-time.html |
@@ -1,153 +1,165 @@ |
-<!doctype html> |
+<!DOCTYPE html> |
<html> |
<head> |
- <title>Test Clamping of AudioParam Time</title> |
+ <title> |
+ Test Clamping of AudioParam Time |
+ </title> |
<script src="../../resources/testharness.js"></script> |
<script src="../../resources/testharnessreport.js"></script> |
<script src="../resources/audit-util.js"></script> |
<script src="../resources/audit.js"></script> |
</head> |
- |
<body> |
- <script> |
+ <script id="layout-test-code"> |
// Fairly arbitrary sample rate and render frames. |
- var sampleRate = 24000; |
- var renderFrames = 1024; |
+ let sampleRate = 24000; |
+ let renderFrames = 1024; |
- var audit = Audit.createTaskRunner(); |
+ let audit = Audit.createTaskRunner(); |
- audit.define("setValue", (task, should) => { |
- var suspendFrame = 128; |
+ audit.define('setValue', (task, should) => { |
+ let suspendFrame = 128; |
createGraph({ |
- suspendFrame: suspendFrame, |
- method: "setValueAtTime", |
- initialGain: 0, |
- arg0: 1, |
- }) |
- .then(function (resultBuffer) { |
- // Just verify that the cosine wave actually started at |
- // suspendFrame. |
- var result = resultBuffer.getChannelData(0); |
- |
- should(result.slice(0, suspendFrame), |
- "setValue: Output[0-" + (suspendFrame - 1) + "]") |
- .beConstantValueOf(0); |
- should(result.slice(suspendFrame), |
- "setValue: Output[" + suspendFrame + "-" + (renderFrames - 1) + |
- "]") |
- .beConstantValueOf(1); |
- }) |
- .then(() => task.done()); |
+ suspendFrame: suspendFrame, |
+ method: 'setValueAtTime', |
+ initialGain: 0, |
+ arg0: 1, |
+ }) |
+ .then(function(resultBuffer) { |
+ // Just verify that the cosine wave actually started at |
+ // suspendFrame. |
+ let result = resultBuffer.getChannelData(0); |
+ |
+ should( |
+ result.slice(0, suspendFrame), |
+ 'setValue: Output[0-' + (suspendFrame - 1) + ']') |
+ .beConstantValueOf(0); |
+ should( |
+ result.slice(suspendFrame), |
+ 'setValue: Output[' + suspendFrame + '-' + |
+ (renderFrames - 1) + ']') |
+ .beConstantValueOf(1); |
+ }) |
+ .then(() => task.done()); |
}); |
- audit.define("linear", (task, should) => { |
- var suspendFrame = 128; |
+ audit.define('linear', (task, should) => { |
+ let suspendFrame = 128; |
createGraph({ |
- suspendFrame: suspendFrame, |
- method: "linearRampToValueAtTime", |
- initialGain: 1, |
- arg0: 0.5 |
- }) |
- .then(function (resultBuffer) { |
- // Just verify that the cosine wave actually started at |
- // suspendFrame. |
- var result = resultBuffer.getChannelData(0); |
- |
- should(result.slice(0, suspendFrame), |
- "linear: Output[0-" + (suspendFrame - 1) + "]") |
- .beConstantValueOf(1); |
- should(result.slice(suspendFrame), |
- "linear: Output[" + suspendFrame + "-" + (renderFrames - 1) + "]") |
- .beConstantValueOf(0.5); |
- |
- }) |
- .then(() => task.done()); |
+ suspendFrame: suspendFrame, |
+ method: 'linearRampToValueAtTime', |
+ initialGain: 1, |
+ arg0: 0.5 |
+ }) |
+ .then(function(resultBuffer) { |
+ // Just verify that the cosine wave actually started at |
+ // suspendFrame. |
+ let result = resultBuffer.getChannelData(0); |
+ |
+ should( |
+ result.slice(0, suspendFrame), |
+ 'linear: Output[0-' + (suspendFrame - 1) + ']') |
+ .beConstantValueOf(1); |
+ should( |
+ result.slice(suspendFrame), |
+ 'linear: Output[' + suspendFrame + '-' + (renderFrames - 1) + |
+ ']') |
+ .beConstantValueOf(0.5); |
+ |
+ }) |
+ .then(() => task.done()); |
}); |
- audit.define("exponential", (task, should) => { |
- var suspendFrame = 128; |
+ audit.define('exponential', (task, should) => { |
+ let suspendFrame = 128; |
createGraph({ |
- suspendFrame: suspendFrame, |
- method: "exponentialRampToValueAtTime", |
- initialGain: 1, |
- arg0: 0.5 |
- }) |
- .then(function (resultBuffer) { |
- // Just verify that the cosine wave actually started at |
- // suspendFrame. |
- var result = resultBuffer.getChannelData(0); |
- |
- should(result.slice(0, suspendFrame), |
- "exponential: Output[0-" + (suspendFrame - 1) + "]") |
- .beConstantValueOf(1); |
- should(result.slice(suspendFrame), |
- "exponential: Output[" + suspendFrame + "-" + (renderFrames - 1) + |
- "]") |
- .beConstantValueOf(0.5); |
- }) |
- .then(() => task.done()); |
+ suspendFrame: suspendFrame, |
+ method: 'exponentialRampToValueAtTime', |
+ initialGain: 1, |
+ arg0: 0.5 |
+ }) |
+ .then(function(resultBuffer) { |
+ // Just verify that the cosine wave actually started at |
+ // suspendFrame. |
+ let result = resultBuffer.getChannelData(0); |
+ |
+ should( |
+ result.slice(0, suspendFrame), |
+ 'exponential: Output[0-' + (suspendFrame - 1) + ']') |
+ .beConstantValueOf(1); |
+ should( |
+ result.slice(suspendFrame), |
+ 'exponential: Output[' + suspendFrame + '-' + |
+ (renderFrames - 1) + ']') |
+ .beConstantValueOf(0.5); |
+ }) |
+ .then(() => task.done()); |
}); |
- audit.define("setTarget", (task, should) => { |
- var suspendFrame = 128; |
+ audit.define('setTarget', (task, should) => { |
+ let suspendFrame = 128; |
createGraph({ |
- suspendFrame: suspendFrame, |
- method: "setTargetAtTime", |
- initialGain: 1, |
- arg0: 0.5, |
- moreArgs: 0.1 |
- }) |
- .then(function (resultBuffer) { |
- // Just verify that the cosine wave actually started at |
- // suspendFrame. |
- var result = resultBuffer.getChannelData(0); |
- |
- should(result.slice(0, suspendFrame), |
- "setTarget: Output[0-" + (suspendFrame - 1) + "]") |
- .beConstantValueOf(1); |
- // For the samples past the suspend time, we only care that first |
- // value is 1 and that the rest are not zero. |
- should(result[suspendFrame], |
- "setTarget: Output[" + suspendFrame + "]") |
- .beEqualTo(1); |
- |
- var positive = result.slice(suspendFrame + 1).every(x => x > |
- 0); |
- should(positive, "Output[" + (suspendFrame + 1) + "-" + |
- (renderFrames - 1) + "] contains only positive values") |
- .beEqualTo(true); |
- }) |
- .then(() => task.done()); |
+ suspendFrame: suspendFrame, |
+ method: 'setTargetAtTime', |
+ initialGain: 1, |
+ arg0: 0.5, |
+ moreArgs: 0.1 |
+ }) |
+ .then(function(resultBuffer) { |
+ // Just verify that the cosine wave actually started at |
+ // suspendFrame. |
+ let result = resultBuffer.getChannelData(0); |
+ |
+ should( |
+ result.slice(0, suspendFrame), |
+ 'setTarget: Output[0-' + (suspendFrame - 1) + ']') |
+ .beConstantValueOf(1); |
+ // For the samples past the suspend time, we only care that first |
+ // value is 1 and that the rest are not zero. |
+ should( |
+ result[suspendFrame], |
+ 'setTarget: Output[' + suspendFrame + ']') |
+ .beEqualTo(1); |
+ |
+ let positive = result.slice(suspendFrame + 1).every(x => x > 0); |
+ should( |
+ positive, |
+ 'Output[' + (suspendFrame + 1) + '-' + (renderFrames - 1) + |
+ '] contains only positive values') |
+ .beEqualTo(true); |
+ }) |
+ .then(() => task.done()); |
}); |
- audit.define("setValueCurve", (task, should) => { |
- var suspendFrame = 128; |
+ audit.define('setValueCurve', (task, should) => { |
+ let suspendFrame = 128; |
createGraph({ |
- suspendFrame: suspendFrame, |
- method: "setValueCurveAtTime", |
- initialGain: 1, |
- arg0: Float32Array.from([2, 3]), |
- moreArgs: 0.1 |
- }) |
- .then(function (resultBuffer) { |
- // Just verify that the cosine wave actually started at |
- // suspendFrame. |
- var result = resultBuffer.getChannelData(0); |
- |
- should(result.slice(0, suspendFrame), |
- "setValueCurve: Output[0-" + (suspendFrame - 1) + "]") |
- .beConstantValueOf(1); |
- |
- // The selected curve contains values greater than or equal to 2. |
- // Just verify that all values are greater than or equal to 2. |
- var biggerThan2 = result.slice(suspendFrame).every(x => x >= |
- 2); |
- should(biggerThan2, |
- "setValueCurve: Output[" + suspendFrame + "-" + |
- (renderFrames - 1) + "]") |
- .beEqualTo(true); |
- }) |
- .then(() => task.done()); |
+ suspendFrame: suspendFrame, |
+ method: 'setValueCurveAtTime', |
+ initialGain: 1, |
+ arg0: Float32Array.from([2, 3]), |
+ moreArgs: 0.1 |
+ }) |
+ .then(function(resultBuffer) { |
+ // Just verify that the cosine wave actually started at |
+ // suspendFrame. |
+ let result = resultBuffer.getChannelData(0); |
+ |
+ should( |
+ result.slice(0, suspendFrame), |
+ 'setValueCurve: Output[0-' + (suspendFrame - 1) + ']') |
+ .beConstantValueOf(1); |
+ |
+ // The selected curve contains values greater than or equal to 2. |
+ // Just verify that all values are greater than or equal to 2. |
+ let biggerThan2 = result.slice(suspendFrame).every(x => x >= 2); |
+ should( |
+ biggerThan2, |
+ 'setValueCurve: Output[' + suspendFrame + '-' + |
+ (renderFrames - 1) + ']') |
+ .beEqualTo(true); |
+ }) |
+ .then(() => task.done()); |
}); |
@@ -159,23 +171,18 @@ |
// method: the name of automation method to be tested |
// initialGain: the initial gain at time 0 for the gain node |
// arg0: the first argument to be supplied to the automation method. |
- // moreArgs: An array of any additional arguments for the automation method. |
+ // moreArgs: An array of any additional arguments for the automation |
+ // method. |
function createGraph(options) { |
- var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
+ let context = new OfflineAudioContext(1, renderFrames, sampleRate); |
- var cosineWave = new PeriodicWave(context, { |
- real: [0, 1] |
- }); |
+ let cosineWave = new PeriodicWave(context, {real: [0, 1]}); |
- var src = new OscillatorNode(context, { |
- periodicWave: cosineWave, |
- frequency: 0 |
- }); |
+ let src = new OscillatorNode( |
+ context, {periodicWave: cosineWave, frequency: 0}); |
// The gain node whose automations we're testing. |
- var gain = new GainNode(context, { |
- gain: 0 |
- }); |
+ let gain = new GainNode(context, {gain: 0}); |
src.connect(gain).connect(context.destination); |
@@ -184,15 +191,16 @@ |
// Suspend rendering so that we can call the automation method at the |
// right time. |startTime| is the time for the automation method. It |
// must be some time before the suspend time. |
- var suspendFrame = options.suspendFrame; |
- var startTime = (suspendFrame / 2) / context.sampleRate; |
+ let suspendFrame = options.suspendFrame; |
+ let startTime = (suspendFrame / 2) / context.sampleRate; |
context.suspend(suspendFrame / context.sampleRate) |
- .then(function () { |
- // Call the appropriate automation method with the desired |
- // automation value, time, and any other arguments needed. |
- gain.gain[options.method](...[options.arg0, startTime, options.moreArgs]); |
- }) |
- .then(context.resume.bind(context)); |
+ .then(function() { |
+ // Call the appropriate automation method with the desired |
+ // automation value, time, and any other arguments needed. |
+ gain.gain[options.method]( |
+ ...[options.arg0, startTime, options.moreArgs]); |
+ }) |
+ .then(context.resume.bind(context)); |
// Start the source and begin rendering, returning the promise from |
// rendering. |