Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html

Issue 2595633002: Convert Analyser tests to use testharness (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../resources/js-test.js"></script> 4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../resources/compatibility.js"></script> 6 <script src="../resources/compatibility.js"></script>
6 <script src="../resources/audit-util.js"></script> 7 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audio-testing.js"></script> 8 <script src="../resources/audio-testing.js"></script>
8 <title>Test AnalyserNode getFloatTimeDomainData</title> 9 <title>Test AnalyserNode getFloatTimeDomainData</title>
9 </head> 10 </head>
10 11
11 <body> 12 <body>
12 <script> 13 <script>
13 description("Test AnalyserNode getFloatTimeDomainData");
14 window.jsTestIsAsync = true; 14 window.jsTestIsAsync = true;
hongchan 2016/12/20 23:04:31 ditto.
15 15
16 // Use a power of two to eliminate any round-off in the computation of the times for 16 // Use a power of two to eliminate any round-off in the computation of the times for
17 // context.suspend(). 17 // context.suspend().
18 var sampleRate = 32768; 18 var sampleRate = 32768;
19 19
20 // The largest FFT size for the analyser node is 32768. We want to render longer than this so 20 // The largest FFT size for the analyser node is 32768. We want to render longer than this so
21 // that we have at least one complete buffer of data of 32768 samples. 21 // that we have at least one complete buffer of data of 32768 samples.
22 var renderFrames = 2 * 32768; 22 var renderFrames = 2 * 32768;
23 var renderDuration = renderFrames / sampleRate; 23 var renderDuration = renderFrames / sampleRate;
24 24
25 var audit = Audit.createTaskRunner(); 25 var audit = Audit.createTaskRunner();
26 26
27 // Test that getFloatTimeDomainData handles short and long vectors correct ly. 27 // Test that getFloatTimeDomainData handles short and long vectors correct ly.
28 audit.defineTask("short and long vector", function (done) { 28 audit.defineTask("short and long vector", function (done) {
29 var fftSize = 32; 29 var fftSize = 32;
30 var graphInfo = createGraph(fftSize); 30 var graphInfo = createGraph(fftSize);
31 var context = graphInfo.context; 31 var context = graphInfo.context;
32 var analyser = graphInfo.analyser; 32 var analyser = graphInfo.analyser;
33 var signalBuffer = graphInfo.signalBuffer; 33 var signalBuffer = graphInfo.signalBuffer;
34 var signal = signalBuffer.getChannelData(0); 34 var signal = signalBuffer.getChannelData(0);
35 35
36 var success = true; 36 var success = true;
37 var sampleFrame = 128; 37 var sampleFrame = 128;
38 38
39 context.suspend(sampleFrame / sampleRate).then(function () { 39 context.suspend(sampleFrame / sampleRate).then(function () {
40 var shortData = new Float32Array(8); 40 var shortData = new Float32Array(8);
41 // Initialize the array to Infinity to represent uninitialize data. 41 // Initialize the array to Infinity to represent uninitialize data.
42 shortData.fill(Infinity); 42 shortData.fill(Infinity);
43 testPassed(shortData.length + "-element short array initialized to Inf inity.");
44 43
45 analyser.getFloatTimeDomainData(shortData); 44 analyser.getFloatTimeDomainData(shortData);
46 testPassed("getFloatTimeDomainData(<" + shortData.length + "-element v ector>).");
47 45
48 // The short array should be filled with the expected data, with no er rors thrown. 46 // The short array should be filled with the expected data, with no er rors thrown.
49 47
50 var expected = signal.subarray(sampleFrame - fftSize, sampleFrame); 48 var expected = signal.subarray(sampleFrame - fftSize, sampleFrame);
51 success = Should(shortData.length + "-element time domain data", short Data) 49 success = Should(shortData.length + "-element time domain data", short Data)
52 .beEqualToArray(expected.subarray(0, shortData.length)) && success; 50 .beEqualToArray(expected.subarray(0, shortData.length)) && success;
53 51
54 var longData = new Float32Array(2 * fftSize); 52 var longData = new Float32Array(2 * fftSize);
55 // Initialize the array to Infinity to represent uninitialize data. 53 // Initialize the array to Infinity to represent uninitialize data.
56 longData.fill(Infinity); 54 longData.fill(Infinity);
57 testPassed(longData.length + "-element long array initialized to Infin ity.");
58 55
59 analyser.getFloatTimeDomainData(longData); 56 analyser.getFloatTimeDomainData(longData);
60 testPassed("getFloatTimeDomainData(<" + longData.length + "-element ve ctor>).");
61 57
62 // The long array should filled with the expected data but the extra e lements should be 58 // The long array should filled with the expected data but the extra e lements should be
63 // untouched. 59 // untouched.
64 success = Should("longData.subarray(0, " + fftSize + ")", 60 success = Should("longData.subarray(0, " + fftSize + ")",
65 longData.subarray(0, fftSize), { 61 longData.subarray(0, fftSize), {
66 numberOfArrayLog: 32 62 numberOfArrayLog: 32
67 }) 63 })
68 .beEqualToArray(expected) && success; 64 .beEqualToArray(expected) && success;
69 65
70 success = Should("Unfilled elements longData.subarray(" + fftSize + ") ", 66 success = Should("Unfilled elements longData.subarray(" + fftSize + ") ",
71 longData.subarray(fftSize)) 67 longData.subarray(fftSize))
72 .beConstantValueOf(Infinity) && success; 68 .beConstantValueOf(Infinity) && success;
73 }).then(context.resume.bind(context)); 69 }).then(context.resume.bind(context));
74 70
75 context.startRendering().then(function (buffer) { 71 context.startRendering().then(function (buffer) {
76 if (success) 72 Should("Long and short time domain arrays handled", success)
77 testPassed("Long and short time domain arrays handled correctly.\n") ; 73 .summarize("correctly.", "incorrectly.");
78 else
79 testFailed("Long and short time domain arrays handled incorrectly.\n ");
80 }).then(done); 74 }).then(done);
81 }); 75 });
82 76
83 var success = true; 77 var success = true;
84 78
85 // Generate tests for all valid FFT sizes for an AnalyserNode. 79 // Generate tests for all valid FFT sizes for an AnalyserNode.
86 for (var k = 5; k < 16; ++k) { 80 for (var k = 5; k < 16; ++k) {
87 var fftSize = Math.pow(2, k); 81 var fftSize = Math.pow(2, k);
88 (function (n) { 82 (function (n) {
89 // We grab a sample at (roughly) half the rendering duration. 83 // We grab a sample at (roughly) half the rendering duration.
90 audit.defineTask("fftSize " + n, function (done) { 84 audit.defineTask("fftSize " + n, function (done) {
91 runTest(n, renderDuration / 2).then(done); 85 runTest(n, renderDuration / 2).then(done);
92 }); 86 });
93 })(fftSize); 87 })(fftSize);
94 } 88 }
95 89
96 audit.defineTask("summarize size tests", function (done) { 90 audit.defineTask("summarize size tests", function (done) {
97 if (success) 91 Should("Time domain data", success)
98 testPassed("Time domain data contained the correct data for each size. \n"); 92 .summarize("contained the correct data for each size.",
99 else 93 "did not contain the correct data for each size.");
100 testFailed("Time domain data did not contain the correct data for each size.\n");
101 94
102 done(); 95 done();
103 }); 96 });
104 97
105 // Special case for a large size, but the sampling point is early. The in itial part of the 98 // Special case for a large size, but the sampling point is early. The in itial part of the
106 // buffer should be filled with zeroes. 99 // buffer should be filled with zeroes.
107 100
108 audit.defineTask("initial zeroes", function (done) { 101 audit.defineTask("initial zeroes", function (done) {
109 // Somewhat arbitrary size for the analyser. It should be greater than one rendering 102 // Somewhat arbitrary size for the analyser. It should be greater than one rendering
110 // quantum. 103 // quantum.
(...skipping 21 matching lines...) Expand all
132 } 125 }
133 126
134 var signal = signalBuffer.getChannelData(0); 127 var signal = signalBuffer.getChannelData(0);
135 success = Should(prefix + "(" + (fftSize - sampleFrame) + ", " + fft Size + ")", 128 success = Should(prefix + "(" + (fftSize - sampleFrame) + ", " + fft Size + ")",
136 data.subarray(fftSize - sampleFrame, fftSize)) 129 data.subarray(fftSize - sampleFrame, fftSize))
137 .beEqualToArray(signal.subarray(0, sampleFrame)) && success; 130 .beEqualToArray(signal.subarray(0, sampleFrame)) && success;
138 }).then(context.resume.bind(context)); 131 }).then(context.resume.bind(context));
139 } 132 }
140 133
141 context.startRendering().then(function (b) { 134 context.startRendering().then(function (b) {
142 if (success) { 135 Should("Time domain data", success)
143 testPassed( 136 .summarize(
144 "Time domain data contained initial zeroes and correct data as exp ected.\n"); 137 "contained initial zeroes and correct data as expected",
145 } else { 138 "did not contain initial zeroes and correct data as expected.");
146 testFailed(
147 "Time domain data did not contain initial zeroes and correct data as expected.\n"
148 );
149 }
150
151 }).then(done); 139 }).then(done);
152 }); 140 });
153 141
154 audit.defineTask("finish", function (done) { 142 audit.defineTask("finish", function (done) {
155 finishJSTest();
156 done(); 143 done();
157 }); 144 });
158 145
159 audit.runTasks(); 146 audit.runTasks();
160 147
161 // Run test of an AnalyserNode with fftSize of |fftSize|, and with the dat a from the node 148 // Run test of an AnalyserNode with fftSize of |fftSize|, and with the dat a from the node
162 // being requested at time |sampletime|. The result from the analyser nod e is compared 149 // being requested at time |sampletime|. The result from the analyser nod e is compared
163 // against the expected data. The result of startRendering() is returned. 150 // against the expected data. The result of startRendering() is returned.
164 function runTest(fftSize, sampleTime) { 151 function runTest(fftSize, sampleTime) {
165 var graphInfo = createGraph(fftSize); 152 var graphInfo = createGraph(fftSize);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 199
213 return { 200 return {
214 context: context, 201 context: context,
215 analyser: analyser, 202 analyser: analyser,
216 signalBuffer: signalBuffer 203 signalBuffer: signalBuffer
217 }; 204 };
218 } 205 }
219 </script> 206 </script>
220 </body> 207 </body>
221 </html> 208 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698