Attachment #709878: Part 7.5: Make Web Audio tests context-rate-independent (disabling some decodeAudioData tests) for bug #804387

View | Details | Raw Unified | Return to bug 804387
Collapse All | Expand All

(-)a/content/media/webaudio/test/test_AudioBuffer.html (-4 / +4 lines)
Line     Link Here 
 Lines 7-29    Link Here 
7
</head>
7
</head>
8
<body>
8
<body>
9
<pre id="test">
9
<pre id="test">
10
<script class="testbody" type="text/javascript">
10
<script class="testbody" type="text/javascript">
11
11
12
SimpleTest.waitForExplicitFinish();
12
SimpleTest.waitForExplicitFinish();
13
addLoadEvent(function() {
13
addLoadEvent(function() {
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
15
  var ac = new AudioContext();
15
  var context = new AudioContext();
16
  var buffer = ac.createBuffer(2, 2048, 44100);
16
  var buffer = context.createBuffer(2, 2048, context.sampleRate);
17
  SpecialPowers.gc(); // Make sure that our channels are accessible after GC
17
  SpecialPowers.gc(); // Make sure that our channels are accessible after GC
18
  ok(buffer, "Buffer was allocated successfully");
18
  ok(buffer, "Buffer was allocated successfully");
19
  is(buffer.sampleRate, 44100, "Correct sample rate");
19
  is(buffer.sampleRate, context.sampleRate, "Correct sample rate");
20
  is(buffer.length, 2048, "Correct length");
20
  is(buffer.length, 2048, "Correct length");
21
  ok(Math.abs(buffer.duration - 2048 / 44100) < 0.0001, "Correct duration");
21
  ok(Math.abs(buffer.duration - 2048 / context.sampleRate) < 0.0001, "Correct duration");
22
  is(buffer.numberOfChannels, 2, "Correct number of channels");
22
  is(buffer.numberOfChannels, 2, "Correct number of channels");
23
  for (var i = 0; i < buffer.numberOfChannels; ++i) {
23
  for (var i = 0; i < buffer.numberOfChannels; ++i) {
24
    var buf = buffer.getChannelData(i);
24
    var buf = buffer.getChannelData(i);
25
    ok(buf, "Buffer index " + i + " exists");
25
    ok(buf, "Buffer index " + i + " exists");
26
    ok(buf instanceof Float32Array, "Result is a typed array");
26
    ok(buf instanceof Float32Array, "Result is a typed array");
27
    is(buf.length, buffer.length, "Correct length");
27
    is(buf.length, buffer.length, "Correct length");
28
    var foundNonZero = false;
28
    var foundNonZero = false;
29
    for (var j = 0; j < buf.length; ++j) {
29
    for (var j = 0; j < buf.length; ++j) {
(-)a/content/media/webaudio/test/test_biquadFilterNode.html (-3 / +3 lines)
Line     Link Here 
 Lines 14-49   function near(a, b, msg) { Link Here 
14
  ok(Math.abs(a - b) < 1e-3, msg);
14
  ok(Math.abs(a - b) < 1e-3, msg);
15
}
15
}
16
16
17
SimpleTest.waitForExplicitFinish();
17
SimpleTest.waitForExplicitFinish();
18
addLoadEvent(function() {
18
addLoadEvent(function() {
19
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
19
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
20
20
21
  var context = new AudioContext();
21
  var context = new AudioContext();
22
  var buffer = context.createBuffer(1, 2048, 44100);
22
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
23
  for (var i = 0; i < 2048; ++i) {
23
  for (var i = 0; i < 2048; ++i) {
24
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
24
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
25
  }
25
  }
26
26
27
  var destination = context.destination;
27
  var destination = context.destination;
28
28
29
  var source = context.createBufferSource();
29
  var source = context.createBufferSource();
30
30
31
  var filter = context.createBiquadFilter();
31
  var filter = context.createBiquadFilter();
32
32
33
  source.buffer = buffer;
33
  source.buffer = buffer;
34
34
35
  source.connect(filter);
35
  source.connect(filter);
36
  filter.connect(destination);
36
  filter.connect(destination);
37
37
38
  // Verify default values
38
  // Verify default values
39
  is(filter.type, 0, "Correct default value for type");
39
  is(filter.type, 0, "Correct default value for type");
40
  near(filter.frequency.minValue, 10, "Correct min value for filter frequency");
40
  near(filter.frequency.minValue, 10, "Correct min value for filter frequency");
41
  near(filter.frequency.maxValue, 22050, "Correct max value for filter frequency");
41
  near(filter.frequency.maxValue, context.sampleRate/2, "Correct max value for filter frequency");
42
  near(filter.frequency.defaultValue, 350, "Correct default value for filter frequency");
42
  near(filter.frequency.defaultValue, 350, "Correct default value for filter frequency");
43
  near(filter.Q.minValue, 0.001, "Correct min value for filter Q");
43
  near(filter.Q.minValue, 0.001, "Correct min value for filter Q");
44
  near(filter.Q.maxValue, 1000, "Correct max value for filter Q");
44
  near(filter.Q.maxValue, 1000, "Correct max value for filter Q");
45
  near(filter.Q.defaultValue, 1, "Correct default value for filter Q");
45
  near(filter.Q.defaultValue, 1, "Correct default value for filter Q");
46
  near(filter.gain.minValue, -40, "Correct min value for filter gain");
46
  near(filter.gain.minValue, -40, "Correct min value for filter gain");
47
  near(filter.gain.maxValue, 40, "Correct max value for filter gain");
47
  near(filter.gain.maxValue, 40, "Correct max value for filter gain");
48
  near(filter.gain.defaultValue, 0, "Correct default value for filter gain");
48
  near(filter.gain.defaultValue, 0, "Correct default value for filter gain");
49
49
(-)a/content/media/webaudio/test/test_decodeAudioData.html (-2 / +7 lines)
Line     Link Here 
 Lines 249-263   expectTypeError(function() { Link Here 
249
});
249
});
250
expectTypeError(function() {
250
expectTypeError(function() {
251
  cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
251
  cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
252
});
252
});
253
expectTypeError(function() {
253
expectTypeError(function() {
254
  cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
254
  cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
255
});
255
});
256
256
257
// Now, let's get real!
257
if (cx.sampleRate == 44100) {
258
runNextTest();
258
  // Now, let's get real!
259
  runNextTest();
260
} else {
261
  todo(false, "Decoded data tests disabled; context sampleRate " + cx.sampleRate + " not supported");
262
  SimpleTest.finish();
263
}
259
264
260
</script>
265
</script>
261
</pre>
266
</pre>
262
</body>
267
</body>
263
</html>
268
</html>
(-)a/content/media/webaudio/test/test_delayNode.html (-2 / +2 lines)
Line     Link Here 
 Lines 10-28    Link Here 
10
<script src="webaudio.js" type="text/javascript"></script>
10
<script src="webaudio.js" type="text/javascript"></script>
11
<script class="testbody" type="text/javascript">
11
<script class="testbody" type="text/javascript">
12
12
13
SimpleTest.waitForExplicitFinish();
13
SimpleTest.waitForExplicitFinish();
14
addLoadEvent(function() {
14
addLoadEvent(function() {
15
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
15
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
16
16
17
  var context = new AudioContext();
17
  var context = new AudioContext();
18
  var buffer = context.createBuffer(1, 2048, 44100);
18
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
19
  for (var i = 0; i < 2048; ++i) {
19
  for (var i = 0; i < 2048; ++i) {
20
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
20
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
21
  }
21
  }
22
22
23
  var destination = context.destination;
23
  var destination = context.destination;
24
24
25
  var source = context.createBufferSource();
25
  var source = context.createBufferSource();
26
26
27
  var delay = context.createDelay();
27
  var delay = context.createDelay();
28
28
(-)a/content/media/webaudio/test/test_dynamicsCompressorNode.html (-2 / +2 lines)
Line     Link Here 
 Lines 13-31   function near(a, b, msg) { Link Here 
13
  ok(Math.abs(a - b) < 1e-4, msg);
13
  ok(Math.abs(a - b) < 1e-4, msg);
14
}
14
}
15
15
16
SimpleTest.waitForExplicitFinish();
16
SimpleTest.waitForExplicitFinish();
17
addLoadEvent(function() {
17
addLoadEvent(function() {
18
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
18
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
19
19
20
  var context = new AudioContext();
20
  var context = new AudioContext();
21
  var buffer = context.createBuffer(1, 2048, 44100);
21
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
22
  for (var i = 0; i < 2048; ++i) {
22
  for (var i = 0; i < 2048; ++i) {
23
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
23
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
24
  }
24
  }
25
25
26
  var destination = context.destination;
26
  var destination = context.destination;
27
27
28
  var source = context.createBufferSource();
28
  var source = context.createBufferSource();
29
29
30
  var compressor = context.createDynamicsCompressor();
30
  var compressor = context.createDynamicsCompressor();
31
31
(-)a/content/media/webaudio/test/test_gainNode.html (-2 / +2 lines)
Line     Link Here 
 Lines 9-27    Link Here 
9
<pre id="test">
9
<pre id="test">
10
<script class="testbody" type="text/javascript">
10
<script class="testbody" type="text/javascript">
11
11
12
SimpleTest.waitForExplicitFinish();
12
SimpleTest.waitForExplicitFinish();
13
addLoadEvent(function() {
13
addLoadEvent(function() {
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
15
15
16
  var context = new AudioContext();
16
  var context = new AudioContext();
17
  var buffer = context.createBuffer(1, 2048, 44100);
17
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
18
  for (var i = 0; i < 2048; ++i) {
18
  for (var i = 0; i < 2048; ++i) {
19
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
19
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
20
  }
20
  }
21
21
22
  var destination = context.destination;
22
  var destination = context.destination;
23
23
24
  var source = context.createBufferSource();
24
  var source = context.createBufferSource();
25
25
26
  var gain = context.createGain();
26
  var gain = context.createGain();
27
27
(-)a/content/media/webaudio/test/test_pannerNode.html (-2 / +2 lines)
Line     Link Here 
 Lines 13-31   function near(a, b, msg) { Link Here 
13
  ok(Math.abs(a - b) < 1e-4, msg);
13
  ok(Math.abs(a - b) < 1e-4, msg);
14
}
14
}
15
15
16
SimpleTest.waitForExplicitFinish();
16
SimpleTest.waitForExplicitFinish();
17
addLoadEvent(function() {
17
addLoadEvent(function() {
18
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
18
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
19
19
20
  var context = new AudioContext();
20
  var context = new AudioContext();
21
  var buffer = context.createBuffer(1, 2048, 44100);
21
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
22
  for (var i = 0; i < 2048; ++i) {
22
  for (var i = 0; i < 2048; ++i) {
23
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
23
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
24
  }
24
  }
25
25
26
  var destination = context.destination;
26
  var destination = context.destination;
27
27
28
  var source = context.createBufferSource();
28
  var source = context.createBufferSource();
29
29
30
  var panner = context.createPanner();
30
  var panner = context.createPanner();
31
31
(-)a/content/media/webaudio/test/test_singleSourceDest.html (-2 / +2 lines)
Line     Link Here 
 Lines 9-27    Link Here 
9
<pre id="test">
9
<pre id="test">
10
<script class="testbody" type="text/javascript">
10
<script class="testbody" type="text/javascript">
11
11
12
SimpleTest.waitForExplicitFinish();
12
SimpleTest.waitForExplicitFinish();
13
addLoadEvent(function() {
13
addLoadEvent(function() {
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
14
  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
15
15
16
  var context = new AudioContext();
16
  var context = new AudioContext();
17
  var buffer = context.createBuffer(1, 2048, 44100);
17
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
18
  for (var i = 0; i < 2048; ++i) {
18
  for (var i = 0; i < 2048; ++i) {
19
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / 44100);
19
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
20
  }
20
  }
21
21
22
  var destination = context.destination;
22
  var destination = context.destination;
23
  is(destination.context, context, "Destination node has proper context");
23
  is(destination.context, context, "Destination node has proper context");
24
  is(destination.context, context, "Destination node has proper context");
24
  is(destination.context, context, "Destination node has proper context");
25
  is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
25
  is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
26
  is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
26
  is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
27
27

Return to bug 804387