blob: 94d79e0698b1a7bd924d4d4b8c27a36417c12fc7 [file] [log] [blame]
<!DOCTYPE html>
<!--
Create an oscillator of each type and verify that the type is set correctly.
-->
<html>
<head>
<title>
oscillator-basic.html
</title>
<script src="../../imported/w3c/web-platform-tests/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 sampleRate = 44100;
let renderLengthSeconds = 0.25;
let oscTypes = ['sine', 'square', 'sawtooth', 'triangle', 'custom'];
let audit = Audit.createTaskRunner();
audit.define('basic osc tests', (task, should) => {
// Create offline audio context.
let context = new OfflineAudioContext(
2, sampleRate * renderLengthSeconds, sampleRate);
let osc = context.createOscillator();
// Set each possible oscillator type (except CUSTOM) and verify that the
// type is correct. Here we're setting the type using WebIDL enum
// values which are strings.
for (let k = 0; k < oscTypes.length - 1; ++k) {
osc.type = oscTypes[k];
should(osc.type, 'osc.type = \'' + oscTypes[k] + '\'')
.beEqualTo(oscTypes[k]);
}
// Verify that setting a custom type directly does not set the custom
// type. This test has to be done before using setPeriodicWave.
should(function() {
osc.type = 'custom';
}, 'osc.type = \'custom\'').throw(DOMException, 'InvalidStateError');
// Now set a custom oscillator
let coeffA = new Float32Array([0, 1, 0.5]);
let coeffB = new Float32Array([0, 0, 0]);
let wave = context.createPeriodicWave(coeffA, coeffB);
should(function() {
osc.setPeriodicWave(wave);
}, 'osc.setPeriodicWave(wave)').notThrow();
should(osc.type, 'After setting periodicWave, osc.type')
.beEqualTo('custom');
// Check that numerical values are no longer supported
let oldType = osc.type;
osc.type = 0;
should(osc.type, 'osc.type = 0').notBeEqualTo(0);
should(osc.type, 'osc.type').beEqualTo(oldType);
task.done();
});
audit.define('start/stop exceptions', (task, should) => {
// We're not going to render anything, so make it simple
let context = new OfflineAudioContext(1, 1, sampleRate);
let node = new OscillatorNode(context);
testStartStop(should, node);
task.done();
});
audit.run();
</script>
</body>
</html>