content/media/webaudio/test/test_singleSourceDest.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:dea06666f6b2
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test whether we can create an AudioContext interface</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="webaudio.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 </head>
9 <body>
10 <pre id="test">
11 <script class="testbody" type="text/javascript">
12
13 SimpleTest.waitForExplicitFinish();
14 addLoadEvent(function() {
15 var context = new AudioContext();
16 var buffer = context.createBuffer(1, 2048, context.sampleRate);
17 for (var i = 0; i < 2048; ++i) {
18 buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
19 }
20
21 var destination = context.destination;
22 is(destination.context, context, "Destination node has proper context");
23 is(destination.context, context, "Destination node has proper context");
24 is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
25 is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
26 is(destination.channelCount, 2, "Destination node has 2 input channels by default");
27 is(destination.channelCountMode, "explicit", "Correct channelCountMode for the destination node");
28 is(destination.channelInterpretation, "speakers", "Correct channelCountInterpretation for the destination node");
29 ok(destination instanceof EventTarget, "AudioNodes must be EventTargets");
30
31 var source = context.createBufferSource();
32 is(source.context, context, "Source node has proper context");
33 is(source.numberOfInputs, 0, "Source node has 0 inputs");
34 is(source.numberOfOutputs, 1, "Source node has 1 outputs");
35 is(source.loop, false, "Source node is not looping");
36 is(source.loopStart, 0, "Correct default value for loopStart");
37 is(source.loopEnd, 0, "Correct default value for loopEnd");
38 ok(!source.buffer, "Source node should not have a buffer when it's created");
39 is(source.channelCount, 2, "source node has 2 input channels by default");
40 is(source.channelCountMode, "max", "Correct channelCountMode for the source node");
41 is(source.channelInterpretation, "speakers", "Correct channelCountInterpretation for the source node");
42
43 expectException(function() {
44 source.channelCount = 0;
45 }, DOMException.NOT_SUPPORTED_ERR);
46
47 source.buffer = buffer;
48 ok(source.buffer, "Source node should have a buffer now");
49
50 source.connect(destination);
51
52 is(source.numberOfInputs, 0, "Source node has 0 inputs");
53 is(source.numberOfOutputs, 1, "Source node has 0 outputs");
54 is(destination.numberOfInputs, 1, "Destination node has 0 inputs");
55 is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
56
57 source.start(0);
58 SimpleTest.executeSoon(function() {
59 source.stop(0);
60 source.disconnect();
61
62 SpecialPowers.clearUserPref("media.webaudio.enabled");
63 SimpleTest.finish();
64 });
65 });
66
67 </script>
68 </pre>
69 </body>
70 </html>

mercurial