<!DOCTYPE html>

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

<body>

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

<script>
description("Basic tests for AudioChannelMerger.");

function runTest() {
    window.jsTestIsAsync = true;

    var context = new AudioContext();

    try {
        var mergernode = context.createChannelMerger(0);
        testFailed("IndexSizeError should be thrown for numberOfInputs <= 0.");
    } catch(e) {
        if (e.code === DOMException.INDEX_SIZE_ERR)
            testPassed("IndexSizeError was thrown for numberOfInputs <= 0.");
        else
            testFailed("IndexSizeError should be thrown for numberOfInputs <= 0.");
    }

    try {
        var mergernode = context.createChannelMerger(33);
        testFailed("IndexSizeError should be thrown for numberOfInputs > 32.");
    } catch(e) {
        if (e.code === DOMException.INDEX_SIZE_ERR)
            testPassed("IndexSizeError was thrown for numberOfInputs > 32.");
        else
            testFailed("IndexSizeError should be thrown for numberOfInputs > 32.");
    }

    try {
        var mergernode = context.createChannelMerger(32);
        testPassed("AudioChannelMerger created successfully with numberOfInputs = 32.");
    } catch(e) {
        testFailed("Failed to create AudioChannelMerger with numberOfInputs = 32.");
    }

    try {
        var mergernode = context.createChannelMerger();
        testPassed("AudioChannelMerger created successfully with empty parameter.");
        if (mergernode.toString().indexOf("ChannelMergerNode") > -1)
            testPassed("ChannelMergerNode Object is available.");
        else
            testFailed("ChannelMergerNode Object is not available.");
    } catch(e) {
        testFailed("Failed to create AudioChannelMerger with empty parameter.");
    }

    finishJSTest();
}

runTest();

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