Commit ac7c8e1b authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Move WPT chrome constant source node tests to final place

Move the ConstantSourceNode tests from the chrome directory to the
the-constantsourcenode-interface directory.

The test failures on Firefox are bugs in Firefox and issues have been
filed.  Safari and Edge fail these because they don't currently
support ConstantSourceNode.

Remove these tests from LayoutTests/webaudio since the WPT tests are
identical except for the script locations (as confirmed by diffing).

Bug: 745778
Change-Id: I2c082834a78437e2d6773ef890dfaf063b3ac49e
Reviewed-on: https://chromium-review.googlesource.com/759023Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516071}
parent 71c8f842
......@@ -6,9 +6,9 @@
</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>
<script src="../resources/start-stop-exceptions.js"></script>
<script src="../../resources/audit-util.js"></script>
<script src="../../resources/audit.js"></script>
<script src="../../resources/start-stop-exceptions.js"></script>
</head>
<body>
<script id="layout-test-code">
......
......@@ -6,9 +6,9 @@
</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>
<script src="../resources/audioparam-testing.js"></script>
<script src="../../resources/audit-util.js"></script>
<script src="../../resources/audit.js"></script>
<script src="../../resources/audioparam-testing.js"></script>
</head>
<body>
<script id="layout-test-code">
......
<!DOCTYPE html>
<html>
<head>
<title>
Basic ConstantSourceNode Tests
</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>
<script src="../resources/start-stop-exceptions.js"></script>
</head>
<body>
<script id="layout-test-code">
let context = new AudioContext();
let audit = Audit.createTaskRunner();
audit.define('createConstantSource()', (task, should) => {
let node;
let prefix = 'Factory method: ';
should(() => {
node = context.createConstantSource();
}, prefix + 'node = context.createConstantSource()').notThrow();
should(
node instanceof ConstantSourceNode,
prefix + 'node instance of ConstantSourceNode')
.beEqualTo(true);
verifyNodeDefaults(should, node, prefix);
task.done();
});
audit.define('new ConstantSourceNode()', (task, should) => {
let node;
let prefix = 'Constructor: ';
should(() => {
node = new ConstantSourceNode(context);
}, prefix + 'node = new ConstantSourceNode()').notThrow();
should(
node instanceof ConstantSourceNode,
prefix + 'node instance of ConstantSourceNode')
.beEqualTo(true);
verifyNodeDefaults(should, node, prefix);
task.done();
});
audit.define('start/stop exceptions', (task, should) => {
let node = new ConstantSourceNode(context);
testStartStop(should, node);
task.done();
});
function verifyNodeDefaults(should, node, prefix) {
should(node.numberOfInputs, prefix + 'node.numberOfInputs')
.beEqualTo(0);
should(node.numberOfOutputs, prefix + 'node.numberOfOutputs')
.beEqualTo(1);
should(node.channelCount, prefix + 'node.channelCount').beEqualTo(2);
should(node.channelCountMode, prefix + 'node.channelCountMode')
.beEqualTo('max');
should(
node.channelInterpretation, prefix + 'node.channelInterpretation')
.beEqualTo('speakers');
should(node.offset.value, prefix + 'node.offset.value').beEqualTo(1);
should(node.offset.defaultValue, prefix + 'node.offset.defaultValue')
.beEqualTo(1);
should(node.offset.minValue, prefix + 'node.offset.minValue')
.beEqualTo(Math.fround(-3.4028235e38));
should(node.offset.maxValue, prefix + 'node.offset.maxValue')
.beEqualTo(Math.fround(3.4028235e38));
}
audit.run();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>
Test ConstantSourceNode onended
</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script id="layout-test-code">
let sampleRate = 44100.0;
// Number of frames that the source will run; fairly arbitrary
let numberOfFrames = 32;
// Number of frames to render; arbitrary, but should be larger than
// numberOfFrames;
let renderFrames = 16 * numberOfFrames;
let context = new OfflineAudioContext(1, renderFrames, sampleRate);
let src = new ConstantSourceNode(context);
src.connect(context.destination);
let tester = async_test('ConstantSourceNode onended event fired');
src.onended = function() {
tester.step(function() {
assert_true(true, 'ConstantSourceNode.onended fired');
});
tester.done();
};
src.start();
src.stop(numberOfFrames / context.sampleRate);
context.startRendering();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>
Test ConstantSourceNode Output
</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>
<script src="../resources/audioparam-testing.js"></script>
</head>
<body>
<script id="layout-test-code">
let sampleRate = 48000;
let renderDuration = 0.125;
let renderFrames = sampleRate * renderDuration;
let audit = Audit.createTaskRunner();
audit.define('constant source', (task, should) => {
// Verify a constant source outputs the correct (fixed) constant.
let context = new OfflineAudioContext(1, renderFrames, sampleRate);
let node = new ConstantSourceNode(context, {offset: 0.5});
node.connect(context.destination);
node.start();
context.startRendering()
.then(function(buffer) {
let actual = buffer.getChannelData(0);
let expected = new Float32Array(actual.length);
expected.fill(node.offset.value);
should(actual, 'Basic: ConstantSourceNode({offset: 0.5})')
.beEqualToArray(expected);
})
.then(() => task.done());
});
audit.define('start/stop', (task, should) => {
// Verify a constant source starts and stops at the correct time and has
// the correct (fixed) value.
let context = new OfflineAudioContext(1, renderFrames, sampleRate);
let node = new ConstantSourceNode(context, {offset: 1});
node.connect(context.destination);
let startFrame = 10;
let stopFrame = 300;
node.start(startFrame / context.sampleRate);
node.stop(stopFrame / context.sampleRate);
context.startRendering()
.then(function(buffer) {
let actual = buffer.getChannelData(0);
let expected = new Float32Array(actual.length);
// The expected output is all 1s from start to stop time.
expected.fill(0);
for (let k = startFrame; k < stopFrame; ++k) {
expected[k] = node.offset.value;
}
let prefix = 'start/stop: ';
should(actual.slice(
0, startFrame,
prefix + 'ConstantSourceNode frames [0, ' +
startFrame + ')'))
.beConstantValueOf(0);
should(actual.slice(
startFrame, stopFrame,
prefix + 'ConstantSourceNode frames [' + startFrame +
', ' + stopFrame + ')'))
.beConstantValueOf(1);
should(
actual.slice(stopFrame),
prefix + 'ConstantSourceNode frames [' + stopFrame + ', ' +
renderFrames + ')')
.beConstantValueOf(0);
})
.then(() => task.done());
});
audit.define('basic automation', (task, should) => {
// Verify that automation works as expected.
let context = new OfflineAudioContext(1, renderFrames, sampleRate);
let source = context.createConstantSource();
source.connect(context.destination);
let rampEndTime = renderDuration / 2;
source.offset.setValueAtTime(0.5, 0);
source.offset.linearRampToValueAtTime(1, rampEndTime);
source.start();
context.startRendering()
.then(function(buffer) {
let actual = buffer.getChannelData(0);
let expected = createLinearRampArray(
0, rampEndTime, 0.5, 1, context.sampleRate);
let rampEndFrame = Math.ceil(rampEndTime * context.sampleRate);
let prefix = 'Automation: ';
should(actual.slice(
0, rampEndFrame,
prefix + 'ConstantSourceNode.linearRamp(1, 0.5)'))
.beCloseToArray(expected, {
// Experimentally determined threshold..
relativeThreshold: 7.1610e-7
});
should(
actual.slice(rampEndFrame),
prefix + 'ConstantSourceNode after ramp')
.beConstantValueOf(1);
})
.then(() => task.done());
});
audit.define('connected audioparam', (task, should) => {
// Verify the constant source output with connected AudioParam produces
// the correct output.
let context = new OfflineAudioContext(2, renderFrames, sampleRate)
context.destination.channelInterpretation = 'discrete';
let source = new ConstantSourceNode(context, {offset: 1});
let osc = context.createOscillator();
let merger = context.createChannelMerger(2);
merger.connect(context.destination);
source.connect(merger, 0, 0);
osc.connect(merger, 0, 1);
osc.connect(source.offset);
osc.start();
let sourceStartFrame = 10;
source.start(sourceStartFrame / context.sampleRate);
context.startRendering()
.then(function(buffer) {
// Channel 0 and 1 should be identical, except channel 0 (the
// source) is silent at the beginning.
let actual = buffer.getChannelData(0);
let expected = buffer.getChannelData(1);
// The expected output should be oscillator + 1 because offset
// is 1.
expected = expected.map(x => 1 + x);
let prefix = 'Connected param: ';
// The initial part of the output should be silent because the
// source node hasn't started yet.
should(
actual.slice(0, sourceStartFrame),
prefix + 'ConstantSourceNode frames [0, ' + sourceStartFrame +
')')
.beConstantValueOf(0);
// The rest of the output should be the same as the oscillator (in
// channel 1)
should(
actual.slice(sourceStartFrame),
prefix + 'ConstantSourceNode frames [' + sourceStartFrame +
', ' + renderFrames + ')')
.beCloseToArray(expected.slice(sourceStartFrame), 0);
})
.then(() => task.done());
});
audit.run();
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment