content/media/webaudio/test/test_oscillatorNode.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_oscillatorNode.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test the OscillatorNode 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 +
    1.19 +  var context = new AudioContext();
    1.20 +  var osc = context.createOscillator();
    1.21 +
    1.22 +  is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
    1.23 +  is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
    1.24 +  is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
    1.25 +  is(osc.type, "sine", "Correct default type");
    1.26 +  expectException(function() {
    1.27 +    osc.type = "custom";
    1.28 +  }, DOMException.INVALID_STATE_ERR);
    1.29 +  expectException(function() {
    1.30 +    osc.type = osc.CUSTOM;
    1.31 +  }, DOMException.INVALID_STATE_ERR);
    1.32 +  is(osc.type, "sine", "Cannot set the type to custom");
    1.33 +  is(osc.frequency.value, 440, "Correct default frequency value");
    1.34 +  is(osc.detune.value, 0, "Correct default detine value");
    1.35 +
    1.36 +  // Make sure that we can set all of the valid type values
    1.37 +  var types = [
    1.38 +    "sine",
    1.39 +    "square",
    1.40 +    "sawtooth",
    1.41 +    "triangle",
    1.42 +  ];
    1.43 +  for (var i = 0; i < types.length; ++i) {
    1.44 +    osc.type = osc[types[i].toUpperCase()];
    1.45 +    is(osc.type, types[i], "Correct alternname type enum value");
    1.46 +    osc.type = types[i];
    1.47 +  }
    1.48 +
    1.49 +  // Verify setPeriodicWave()
    1.50 +  var real = new Float32Array([1.0, 0.5, 0.25, 0.125]);
    1.51 +  var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]);
    1.52 +  osc.setPeriodicWave(context.createPeriodicWave(real, imag));
    1.53 +  is(osc.type, "custom", "Failed to set custom waveform");
    1.54 +
    1.55 +  expectNoException(function() {
    1.56 +    osc.start();
    1.57 +  });
    1.58 +  expectNoException(function() {
    1.59 +    osc.stop();
    1.60 +  });
    1.61 +
    1.62 +  SimpleTest.finish();
    1.63 +});
    1.64 +
    1.65 +</script>
    1.66 +</pre>
    1.67 +</body>
    1.68 +</html>

mercurial