Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audiobuffersource-one-sample-loop.html
blobf15d77e0b6a774a962f6858ef3f4cc930e211ae3
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test AudioBufferSourceNode With Looping a Single-Sample Buffer</title>
5 <script src="resources/compatibility.js"></script>
6 <script src="resources/audio-testing.js"></script>
7 <script src="../resources/js-test.js"></script>
8 </head>
10 <body>
11 <script>
12 description("Test AudioBufferSourceNode With Looping a Single-Sample Buffer");
14 var context;
15 var source;
16 var buffer;
17 var renderedData;
19 var sampleRate = 44100;
20 var testDurationSamples = 1000;
22 function checkResult (event) {
23 var success = true;
25 renderedData = event.renderedBuffer.getChannelData(0);
26 // Check that the rendered data is all ones, like the buffer source.
27 for (k = 0; k < renderedData.length; ++k) {
28 if (renderedData[k] != 1) {
29 success = false;
30 testFailed("Expected all ones, but sample " + k + " is " + renderedData[k]);
31 break;
34 if (success)
35 testPassed("All samples equal to 1");
36 finishJSTest();
39 function runTest() {
40 window.jsTestIsAsync = true;
42 // Create the offline context for the test.
43 context = new OfflineAudioContext(1, testDurationSamples, sampleRate);
44 context.oncomplete = checkResult;
46 // Create the single sample buffer
47 buffer = createConstantBuffer(context, 1, 1);
49 // Create the source and connect it to the destination
50 source = context.createBufferSource();
51 source.buffer = buffer;
52 source.loop = true;
53 source.connect(context.destination);
54 source.start();
56 // Render it!
57 context.startRendering();
60 runTest();
61 succesfullyParsed = true;
62 </script>
63 </body>
64 </html>