1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_OfflineAudioContext.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test OfflineAudioContext</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 ctx = new OfflineAudioContext(2, 100, 22050); 1.19 + ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets"); 1.20 + 1.21 + var buf = ctx.createBuffer(2, 100, ctx.sampleRate); 1.22 + for (var i = 0; i < 2; ++i) { 1.23 + for (var j = 0; j < 100; ++j) { 1.24 + buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate); 1.25 + } 1.26 + } 1.27 + 1.28 + expectException(function() { 1.29 + ctx.createMediaStreamDestination(); 1.30 + }, DOMException.NOT_SUPPORTED_ERR); 1.31 + 1.32 + expectException(function() { 1.33 + new OfflineAudioContext(2, 100, 0); 1.34 + }, DOMException.NOT_SUPPORTED_ERR); 1.35 + expectException(function() { 1.36 + new OfflineAudioContext(2, 100, -1); 1.37 + }, DOMException.NOT_SUPPORTED_ERR); 1.38 + expectException(function() { 1.39 + new OfflineAudioContext(0, 100, 44100); 1.40 + }, DOMException.NOT_SUPPORTED_ERR); 1.41 + new OfflineAudioContext(32, 100, 44100); 1.42 + expectException(function() { 1.43 + new OfflineAudioContext(33, 100, 44100); 1.44 + }, DOMException.NOT_SUPPORTED_ERR); 1.45 + expectException(function() { 1.46 + new OfflineAudioContext(2, 0, 44100); 1.47 + }, DOMException.NOT_SUPPORTED_ERR); 1.48 + 1.49 + var src = ctx.createBufferSource(); 1.50 + src.buffer = buf; 1.51 + src.start(0); 1.52 + src.connect(ctx.destination); 1.53 + ctx.startRendering(); 1.54 + ctx.addEventListener("complete", function(e) { 1.55 + ok(e instanceof OfflineAudioCompletionEvent, "Correct event received"); 1.56 + is(e.renderedBuffer.numberOfChannels, 2, "Correct expected number of buffers"); 1.57 + compareBuffers(e.renderedBuffer, buf); 1.58 + 1.59 + expectException(function() { 1.60 + ctx.startRendering(); 1.61 + }, DOMException.INVALID_STATE_ERR); 1.62 + 1.63 + SimpleTest.finish(); 1.64 + }, false); 1.65 +}); 1.66 + 1.67 +</script> 1.68 +</pre> 1.69 +</body> 1.70 +</html>