content/media/webaudio/test/test_oscillatorNode.html

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test the OscillatorNode interface</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="webaudio.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14 addLoadEvent(function() {
michael@0 15
michael@0 16 var context = new AudioContext();
michael@0 17 var osc = context.createOscillator();
michael@0 18
michael@0 19 is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
michael@0 20 is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
michael@0 21 is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
michael@0 22 is(osc.type, "sine", "Correct default type");
michael@0 23 expectException(function() {
michael@0 24 osc.type = "custom";
michael@0 25 }, DOMException.INVALID_STATE_ERR);
michael@0 26 expectException(function() {
michael@0 27 osc.type = osc.CUSTOM;
michael@0 28 }, DOMException.INVALID_STATE_ERR);
michael@0 29 is(osc.type, "sine", "Cannot set the type to custom");
michael@0 30 is(osc.frequency.value, 440, "Correct default frequency value");
michael@0 31 is(osc.detune.value, 0, "Correct default detine value");
michael@0 32
michael@0 33 // Make sure that we can set all of the valid type values
michael@0 34 var types = [
michael@0 35 "sine",
michael@0 36 "square",
michael@0 37 "sawtooth",
michael@0 38 "triangle",
michael@0 39 ];
michael@0 40 for (var i = 0; i < types.length; ++i) {
michael@0 41 osc.type = osc[types[i].toUpperCase()];
michael@0 42 is(osc.type, types[i], "Correct alternname type enum value");
michael@0 43 osc.type = types[i];
michael@0 44 }
michael@0 45
michael@0 46 // Verify setPeriodicWave()
michael@0 47 var real = new Float32Array([1.0, 0.5, 0.25, 0.125]);
michael@0 48 var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]);
michael@0 49 osc.setPeriodicWave(context.createPeriodicWave(real, imag));
michael@0 50 is(osc.type, "custom", "Failed to set custom waveform");
michael@0 51
michael@0 52 expectNoException(function() {
michael@0 53 osc.start();
michael@0 54 });
michael@0 55 expectNoException(function() {
michael@0 56 osc.stop();
michael@0 57 });
michael@0 58
michael@0 59 SimpleTest.finish();
michael@0 60 });
michael@0 61
michael@0 62 </script>
michael@0 63 </pre>
michael@0 64 </body>
michael@0 65 </html>

mercurial