<!DOCTYPE html>

<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/audio-testing.js"></script>
<script src="resources/audiobuffersource-testing.js"></script>
</head>

<body>

<div id="description"></div>
<div id="console"></div>

<script>
description("Tests that AnalyserNode validates minDecibels, maxDecibels and smoothingTimeConstant values.");

var analyser;

function runTest() {
    window.jsTestIsAsync = true;

    var sampleRate = 44100.0;
    var numberOfFrames = 32;
    var context = new OfflineAudioContext(1, numberOfFrames, sampleRate);
    analyser = context.createAnalyser();
    analyser.connect(context.destination);

    // 'minDecibels' shouldn't be greater than 'maxDecibels' which defaults to -30dB.
    shouldThrowErrorName("analyser.minDecibels = -20", "IndexSizeError");
    shouldThrowErrorName("analyser.minDecibels = NaN", "TypeError");
    shouldThrowErrorName("analyser.minDecibels = Infinity", "TypeError");
    shouldThrowErrorName("analyser.minDecibels = -Infinity", "TypeError");

    // 'maxDecibels' shouldn't be less than 'minDecibels' which defaults to -100dB.
    shouldThrowErrorName("analyser.maxDecibels = -120", "IndexSizeError");
    shouldThrowErrorName("analyser.maxDecibels = NaN", "TypeError");
    shouldThrowErrorName("analyser.maxDecibels = Infinity", "TypeError");
    shouldThrowErrorName("analyser.maxDecibels = -Infinity", "TypeError");

    // 'smoothingTimeConstant' range is between 0 and 1.
    shouldThrowErrorName("analyser.smoothingTimeConstant = 2", "IndexSizeError");
    shouldThrowErrorName("analyser.smoothingTimeConstant = -1", "IndexSizeError");
    shouldThrowErrorName("analyser.smoothingTimeConstant = NaN", "TypeError");
    shouldThrowErrorName("analyser.smoothingTimeConstant = Infinity", "TypeError");
    shouldThrowErrorName("analyser.smoothingTimeConstant = -Infinity", "TypeError");

    context.oncomplete = finishJSTest;
    context.startRendering();
}

runTest();

</script>
</body>
</html>
