blob: e1300cc57d3a21c93eb3a3fe4bdd9f6ba19f256d [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
Create an oscillator of each type and verify that the type is set correctly.
-->
<html>
<head>
<script type="text/javascript" src="resources/audio-testing.js"></script>
<script type="text/javascript" src="../resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Basic test of setting Oscillator node types.");
var sampleRate = 44100;
var renderLengthSeconds = 0.25;
var oscTypes = [{type: "sine", name: "SINE"},
{type: "square", name: "SQUARE"},
{type: "sawtooth", name: "SAWTOOTH"},
{type: "triangle", name: "TRIANGLE"},
{type: "custom", name: "CUSTOM"}];
function runTest()
{
window.jsTestIsAsync = true;
// Create offline audio context.
var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
var 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 (var k = 0; k < oscTypes.length - 1; ++k) {
osc.type = oscTypes[k].type;
if (osc.type == oscTypes[k].type)
testPassed("Oscillator correctly set to " + oscTypes[k].name + " type.");
else
testFailed("Oscillator set to " + oscTypes[k].name + " type, but returns " + oscTypes[osc.type].name + " type.");
}
// Now set a custom oscillator
var coeffA = new Float32Array([0, 1, 0.5]);
var coeffB = new Float32Array([0, 0, 0]);
var wave = context.createPeriodicWave(coeffA, coeffB);
osc.setPeriodicWave(wave);
if (osc.type == "custom")
testPassed("Oscillator correctly set to CUSTOM type using setPeriodicWave.");
else
testFailed("Oscillator set to CUSTOM type, but returns " + oscTypes[osc.type].name + " type.");
// Try setting some invalid types
try {
osc.type = "sine";
osc.type = "custom";
testFailed("Directly setting oscillator type to custom did not throw exception.");
} catch (e) {
testPassed("Directly setting oscillator type to custom correctly throws exception.");
}
// Check that we don't throw an exception for illegal .type values as per WebIDL.
shouldNotThrowException(function() { osc.type = "xyz12349jfksd"; }, "Setting .type to illegal string value");
shouldNotThrowException(function() { osc.type = new Float32Array(1); }, "Setting .type to illegal type");
finishJSTest();
}
runTest();
successfullyParsed = true;
</script>
</body>
</html>