1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_singleSourceDest.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test whether we can create an AudioContext interface</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="webaudio.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 + 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 +addLoadEvent(function() { 1.18 + var context = new AudioContext(); 1.19 + var buffer = context.createBuffer(1, 2048, context.sampleRate); 1.20 + for (var i = 0; i < 2048; ++i) { 1.21 + buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); 1.22 + } 1.23 + 1.24 + var destination = context.destination; 1.25 + is(destination.context, context, "Destination node has proper context"); 1.26 + is(destination.context, context, "Destination node has proper context"); 1.27 + is(destination.numberOfInputs, 1, "Destination node has 1 inputs"); 1.28 + is(destination.numberOfOutputs, 0, "Destination node has 0 outputs"); 1.29 + is(destination.channelCount, 2, "Destination node has 2 input channels by default"); 1.30 + is(destination.channelCountMode, "explicit", "Correct channelCountMode for the destination node"); 1.31 + is(destination.channelInterpretation, "speakers", "Correct channelCountInterpretation for the destination node"); 1.32 + ok(destination instanceof EventTarget, "AudioNodes must be EventTargets"); 1.33 + 1.34 + var source = context.createBufferSource(); 1.35 + is(source.context, context, "Source node has proper context"); 1.36 + is(source.numberOfInputs, 0, "Source node has 0 inputs"); 1.37 + is(source.numberOfOutputs, 1, "Source node has 1 outputs"); 1.38 + is(source.loop, false, "Source node is not looping"); 1.39 + is(source.loopStart, 0, "Correct default value for loopStart"); 1.40 + is(source.loopEnd, 0, "Correct default value for loopEnd"); 1.41 + ok(!source.buffer, "Source node should not have a buffer when it's created"); 1.42 + is(source.channelCount, 2, "source node has 2 input channels by default"); 1.43 + is(source.channelCountMode, "max", "Correct channelCountMode for the source node"); 1.44 + is(source.channelInterpretation, "speakers", "Correct channelCountInterpretation for the source node"); 1.45 + 1.46 + expectException(function() { 1.47 + source.channelCount = 0; 1.48 + }, DOMException.NOT_SUPPORTED_ERR); 1.49 + 1.50 + source.buffer = buffer; 1.51 + ok(source.buffer, "Source node should have a buffer now"); 1.52 + 1.53 + source.connect(destination); 1.54 + 1.55 + is(source.numberOfInputs, 0, "Source node has 0 inputs"); 1.56 + is(source.numberOfOutputs, 1, "Source node has 0 outputs"); 1.57 + is(destination.numberOfInputs, 1, "Destination node has 0 inputs"); 1.58 + is(destination.numberOfOutputs, 0, "Destination node has 0 outputs"); 1.59 + 1.60 + source.start(0); 1.61 + SimpleTest.executeSoon(function() { 1.62 + source.stop(0); 1.63 + source.disconnect(); 1.64 + 1.65 + SpecialPowers.clearUserPref("media.webaudio.enabled"); 1.66 + SimpleTest.finish(); 1.67 + }); 1.68 +}); 1.69 + 1.70 +</script> 1.71 +</pre> 1.72 +</body> 1.73 +</html>