| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | 2 |
| 3 <html> | 3 <html> |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../resources/compatibility.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 | 12 |
| 13 <div id="description"></div> | 13 <script> |
| 14 <div id="console"></div> | 14 // This test verifies that the AudioBasicInspectorNode based nodes work correctl
y |
| 15 | 15 |
| 16 <script> | 16 var audit = Audit.createTaskRunner(); |
| 17 description("This test verifies that the AudioBasicInspectorNode based nodes wor
k correctly."); | |
| 18 | 17 |
| 19 var sampleRate = 44100.0; | 18 var sampleRate = 44100.0; |
| 20 // We carefully arrange the renderLengthInFrames to be a multiple of the AudioNo
de rendering quantum (AudioNode::ProcessingSizeInFrames) | 19 // We carefully arrange the renderLengthInFrames to be a multiple of the |
| 21 // so that AudioSourceNode will not feed tailing zeroes into the context and fai
l this test. | 20 // AudioNode rendering quantum (AudioNode::ProcessingSizeInFrames) so that |
| 21 // AudioSourceNode will not feed tailing zeroes into the context and fail this |
| 22 // test. |
| 22 var renderLengthInFrames = 256; | 23 var renderLengthInFrames = 256; |
| 23 var fftSize = 64; | 24 var fftSize = 64; |
| 24 | 25 |
| 25 var audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255. | 26 var audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255. |
| 26 var audioDataZero = 128; // Audio data 0 in Uint8 format will be 128. | 27 var audioDataZero = 128; // Audio data 0 in Uint8 format will be 128. |
| 27 | 28 |
| 28 var context; | 29 var context; |
| 29 var constantBuffer; | 30 var constantBuffer; |
| 30 var bufferSource; | 31 var bufferSource; |
| 31 var analyser; | 32 var analyser; |
| 32 | 33 |
| 33 function constructCommonGraph() { | 34 function constructCommonGraph() { |
| 34 // Create offline audio context. | 35 // Create offline audio context. |
| 35 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate); | 36 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate); |
| 36 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1); | 37 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1); |
| 37 | 38 |
| 38 bufferSource = context.createBufferSource(); | 39 bufferSource = context.createBufferSource(); |
| 39 bufferSource.buffer = constantBuffer; | 40 bufferSource.buffer = constantBuffer; |
| 40 | 41 |
| 41 analyser = context.createAnalyser(); | 42 analyser = context.createAnalyser(); |
| 42 analyser.fftSize = fftSize; | 43 analyser.fftSize = fftSize; |
| 43 | 44 |
| 44 bufferSource.connect(analyser); | 45 bufferSource.connect(analyser); |
| 45 } | 46 } |
| 46 | 47 |
| 47 function test1Finished() { | 48 function test1Finished(should) { |
| 48 var timeDomainData = new Uint8Array(fftSize); | 49 var timeDomainData = new Uint8Array(fftSize); |
| 49 analyser.getByteTimeDomainData(timeDomainData); | 50 analyser.getByteTimeDomainData(timeDomainData); |
| 50 | 51 |
| 51 if (timeDomainData[0] >= audioDataOne) | 52 should(timeDomainData[0] >= audioDataOne, |
| 52 testPassed("RealtimeAnalyserNode got pulled when connected from upstream
node but not to downstream node."); | 53 "RealtimeAnalyserNode got pulled when connected from upstream node but not
to downstream node" |
| 53 else | 54 ) |
| 54 testFailed("RealtimeAnalyserNode failed to get pulled when connected fro
m upstream node but not to downstream node."); | 55 .beTrue(); |
| 55 | |
| 56 test2(); | |
| 57 } | 56 } |
| 58 | 57 |
| 59 // To verify the realtimeAnalyser can pull data when there is an upstream node c
onnected to it | 58 // To verify the realtimeAnalyser can pull data when there is an upstream node |
| 60 // but it's not connected to a downstream node. | 59 // connected to it but it's not connected to a downstream node. |
| 61 function test1() { | 60 audit.define("test1", function (task, should) { |
| 62 constructCommonGraph(); | 61 constructCommonGraph(); |
| 63 | 62 |
| 64 bufferSource.start(0); | 63 bufferSource.start(0); |
| 65 | 64 |
| 66 context.oncomplete = test1Finished; | 65 context.startRendering() |
| 67 context.startRendering(); | 66 .then(test1Finished(should)) |
| 67 .then(task.done.bind(task)); |
| 68 }); |
| 69 |
| 70 function test2Finished(should) { |
| 71 var timeDomainData = new Uint8Array(fftSize); |
| 72 analyser.getByteTimeDomainData(timeDomainData); |
| 73 |
| 74 should(timeDomainData[0] >= audioDataOne, |
| 75 "RealtimeAnalyserNode got pulled when connected from upstream node and to
destination node" |
| 76 ) |
| 77 .beTrue(); |
| 68 } | 78 } |
| 69 | 79 |
| 70 function test2Finished() { | 80 // To verify the realtimeAnalyser can process normally when there is an upstream |
| 71 var timeDomainData = new Uint8Array(fftSize); | 81 // node connected to it and it's also connected to a downstream node which |
| 72 analyser.getByteTimeDomainData(timeDomainData); | 82 // ultimately connect to audio destination. |
| 83 audit.define("test2", function (task, should) { |
| 84 constructCommonGraph(); |
| 73 | 85 |
| 74 if (timeDomainData[0] >= audioDataOne) | 86 analyser.connect(context.destination); |
| 75 testPassed("RealtimeAnalyserNode got pulled when connected from upstream
node and to destination node."); | |
| 76 else | |
| 77 testFailed("RealtimeAnalyserNode failed to be pulled when connected by u
pstream node and to destination node."); | |
| 78 | 87 |
| 79 test3(); | 88 bufferSource.start(0); |
| 89 |
| 90 context.startRendering() |
| 91 .then(test2Finished(should)) |
| 92 .then(task.done.bind(task)); |
| 93 }); |
| 94 |
| 95 function test3Finished(should) { |
| 96 var timeDomainData = new Uint8Array(fftSize); |
| 97 analyser.getByteTimeDomainData(timeDomainData); |
| 98 |
| 99 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0. |
| 100 should(timeDomainData[0] == audioDataZero, |
| 101 "RealtimeAnalyserNode didn't get pulled when it should not") |
| 102 .beTrue();; |
| 80 } | 103 } |
| 81 | 104 |
| 82 // To verify the realtimeAnalyser can process normally when there is an upstream
node connected to it | 105 // To verify the realtimeAnalyser will stop pulling if it is connected to a |
| 83 // and it's also connected to a downstream node which ultimately connect to audi
o destination. | 106 // downstream node which is not ultimatly connected to any audio destination. |
| 84 function test2() { | 107 audit.define("test3", function (task, should) { |
| 85 constructCommonGraph(); | 108 constructCommonGraph(); |
| 86 | 109 |
| 87 analyser.connect(context.destination); | 110 var gain = context.createGain(); |
| 111 analyser.connect(gain); |
| 88 | 112 |
| 89 bufferSource.start(0); | 113 bufferSource.start(0); |
| 90 | 114 |
| 91 context.oncomplete = test2Finished; | 115 context.startRendering() |
| 92 context.startRendering(); | 116 .then(test3Finished(should)) |
| 93 } | 117 .then(task.done.bind(task)); |
| 118 }); |
| 94 | 119 |
| 95 function test3Finished() { | 120 audit.run(); |
| 96 var timeDomainData = new Uint8Array(fftSize); | |
| 97 analyser.getByteTimeDomainData(timeDomainData); | |
| 98 | |
| 99 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0. | |
| 100 if (timeDomainData[0] == audioDataZero) | |
| 101 testPassed("RealtimeAnalyserNode didn't get pulled when it should not.")
; | |
| 102 else | |
| 103 testFailed("RealtimeAnalyserNode been pulled when it should not."); | |
| 104 | |
| 105 finishJSTest(); | |
| 106 } | |
| 107 | |
| 108 // To verify the realtimeAnalyser will stop pulling if it is connected to a down
stream node | |
| 109 // which is not ultimatly connected to any audio destination. | |
| 110 function test3() { | |
| 111 constructCommonGraph(); | |
| 112 | |
| 113 var gain = context.createGain(); | |
| 114 analyser.connect(gain); | |
| 115 | |
| 116 bufferSource.start(0); | |
| 117 | |
| 118 context.oncomplete = test3Finished; | |
| 119 context.startRendering(); | |
| 120 } | |
| 121 | |
| 122 function runTest() { | |
| 123 if (window.testRunner) { | |
| 124 testRunner.dumpAsText(); | |
| 125 testRunner.waitUntilDone(); | |
| 126 } | |
| 127 | |
| 128 window.jsTestIsAsync = true; | |
| 129 | |
| 130 test1(); | |
| 131 } | |
| 132 | |
| 133 runTest(); | |
| 134 | 121 |
| 135 </script> | 122 </script> |
| 136 | 123 |
| 137 </body> | 124 </body> |
| 138 </html> | 125 </html> |
| OLD | NEW |