<!DOCTYPE html>

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

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

<script>
description('Basic tests for AudioNode API.');

var context = null;
var node = null;
var calledResumeWithUserGesture = false;

function runTest() {
    window.jsTestIsAsync = true;

    context = new AudioContext();

    if (window.internals)
        internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');

    shouldBe('context.state', '"suspended"');

    node = context.createBufferSource();
    evalAndLog('node.connect(context.destination)');

    shouldBe('context.state', '"suspended"');

    debug('Calling context.resume() without a user gesture');
    context.resume().then(noUserGestureResumeSucceeded, noUserGestureResumeFailed);

    debug('Wait for 100ms');
    window.setTimeout(function() {
        runWithKeyDown(function() {
            debug('Calling node.start() with a user gesture');
            node.start();
        });
    }, 100);
}

function noUserGestureResumeFailed() {
    testFailed('context.resume() (without a user gesture) promise rejected');
    finishJSTest();
}

function noUserGestureResumeSucceeded() {
    testPassed('context.resume() (without a user gesture) promise resolved');
    shouldBe('context.state', '"running"');
    finishJSTest();
}

runTest();

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