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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js

Issue 2594183003: Convert note-grain-on tests to testharness (Closed)
Patch Set: Remove |success| which isn't needed anymore. Created 3 years, 11 months 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 var sampleRate = 44100.0; 1 var sampleRate = 44100.0;
hongchan 2017/01/20 17:46:10 var => let (all instances in this file)
Raymond Toy 2017/01/20 19:37:10 I was avoiding that to make the diff smaller, but
2 2
3 // HRTF extra frames. This is a magic constant currently in 3 // HRTF extra frames. This is a magic constant currently in
4 // AudioBufferSourceNode::process that always extends the 4 // AudioBufferSourceNode::process that always extends the
5 // duration by this number of samples. See bug 77224 5 // duration by this number of samples. See bug 77224
6 // (https://bugs.webkit.org/show_bug.cgi?id=77224). 6 // (https://bugs.webkit.org/show_bug.cgi?id=77224).
7 var extraFramesHRTF = 512; 7 var extraFramesHRTF = 512;
8 8
9 // How many grains to play. 9 // How many grains to play.
10 var numberOfTests = 100; 10 var numberOfTests = 100;
11 11
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 playGrain(context, source, timeOffset, grainOffset, duration); 99 playGrain(context, source, timeOffset, grainOffset, duration);
100 startTimes[k] = timeOffset; 100 startTimes[k] = timeOffset;
101 offsets[k] = grainOffset; 101 offsets[k] = grainOffset;
102 } 102 }
103 103
104 return { startTimes : startTimes, grainOffsetTimes : offsets }; 104 return { startTimes : startTimes, grainOffsetTimes : offsets };
105 } 105 }
106 106
107 // Verify that the start and end frames for each grain match our 107 // Verify that the start and end frames for each grain match our
108 // expected start and end frames. 108 // expected start and end frames.
109 function verifyStartAndEndFrames(startEndFrames) { 109 function verifyStartAndEndFrames(startEndFrames, should) {
110 var startFrames = startEndFrames.start; 110 var startFrames = startEndFrames.start;
111 var endFrames = startEndFrames.end; 111 var endFrames = startEndFrames.end;
112 112
113 var success = true;
114
115 // Count of how many grains started at the incorrect time. 113 // Count of how many grains started at the incorrect time.
116 var errorCountStart = 0; 114 var errorCountStart = 0;
117 115
118 // Count of how many grains ended at the incorrect time. 116 // Count of how many grains ended at the incorrect time.
119 var errorCountEnd = 0; 117 var errorCountEnd = 0;
120 118
121 if (startFrames.length != endFrames.length) { 119 should(startFrames.length == endFrames.length,
122 testFailed("Could not find the beginning or end of a grain."); 120 "Found all grain starts and ends").beTrue();
123 success = false;
124 }
125 121
126 if (startFrames.length == numberOfTests && endFrames.length == numberOfTests ) { 122 should(startFrames.length, "Number of start frames").beEqualTo(numberOfTests );
hongchan 2017/01/20 17:46:10 Wrap at 80.
Raymond Toy 2017/01/20 19:37:10 Done.
127 testPassed("Found all " + numberOfTests + " grains."); 123 should(endFrames.length, "Number of end frames").beEqualTo(numberOfTests);
128 } else {
129 testFailed("Did not find all " + numberOfTests + " grains.");
130 }
131 124
132 // Examine the start and stop times to see if they match our 125 // Examine the start and stop times to see if they match our
133 // expectations. 126 // expectations.
134 for (var k = 0; k < startFrames.length; ++k) { 127 for (var k = 0; k < startFrames.length; ++k) {
135 var expectedStart = timeToSampleFrame(k * timeStep, sampleRate); 128 var expectedStart = timeToSampleFrame(k * timeStep, sampleRate);
136 // The end point is the duration, plus the extra frames 129 // The end point is the duration, plus the extra frames
137 // for HRTF. 130 // for HRTF.
138 var expectedEnd = extraFramesHRTF + expectedStart + grainLengthInSampleF rames(k * grainOffsetStep, duration, sampleRate); 131 var expectedEnd = extraFramesHRTF + expectedStart + grainLengthInSampleF rames(k * grainOffsetStep, duration, sampleRate);
hongchan 2017/01/20 17:46:09 Let's wrap at 80.
Raymond Toy 2017/01/20 19:37:10 Done.
139 132
140 if (startFrames[k] != expectedStart) { 133 if (startFrames[k] != expectedStart)
141 testFailed("Pulse " + k + " started at " + startFrames[k] + " but ex pected at " + expectedStart); 134 ++errorCountStart;
142 ++errorCountStart; 135 if (endFrames[k] != expectedEnd)
143 success = false; 136 ++errorCountEnd;
144 }
145 137
146 if (endFrames[k] != expectedEnd) { 138 should([startFrames[k], endFrames[k]], "Pulse " + k + " boundary")
147 testFailed("Pulse " + k + " ended at " + endFrames[k] + " but expect ed at " + expectedEnd); 139 .beEqualToArray([expectedStart, expectedEnd]);
148 ++errorCountEnd;
149 success = false;
150 }
151 } 140 }
152 141
153 // Check that all the grains started or ended at the correct time. 142 // Check that all the grains started or ended at the correct time.
154 if (!errorCountStart) { 143 if (!errorCountStart) {
155 if (startFrames.length == numberOfTests) { 144 should(startFrames.length,
156 testPassed("All " + numberOfTests + " grains started at the correct time."); 145 "Number of grains that started at the correct time")
157 } else { 146 .beEqualTo(numberOfTests);
158 testFailed("All grains started at the correct time, but only " + sta rtFrames.length + " grains found.");
159 success = false;
160 }
161 } else { 147 } else {
162 testFailed(errorCountStart + " out of " + numberOfTests + " grains start ed at the wrong time."); 148 should(errorCountStart,
163 success = false; 149 "Number of grains out of " + numberOfTests + "that started at the w rong time")
hongchan 2017/01/20 17:46:10 This line needs to be wrapped.
Raymond Toy 2017/01/20 19:37:10 Done.
150 .beEqualTo(0);
164 } 151 }
165 152
166 if (!errorCountEnd) { 153 if (!errorCountEnd) {
167 if (endFrames.length == numberOfTests) { 154 should(endFrames.length,
168 testPassed("All " + numberOfTests + " grains ended at the correct ti me."); 155 "Number of grains that ended at the correct time")
169 } else { 156 .beEqualTo(numberOfTests);
170 testFailed("All grains ended at the correct time, but only " + endFr ames.length + " grains found.");
171 success = false;
172 }
173 } else { 157 } else {
174 testFailed(errorCountEnd + " out of " + numberOfTests + " grains ended a t the wrong time."); 158 should(errorCountEnd,
175 success = false; 159 "Number of grains out of " + numberOfTests + " that ended at the wr ong time")
hongchan 2017/01/20 17:46:10 Ditto.
Raymond Toy 2017/01/20 19:37:10 Done.
160 .beEqualTo(0);
176 } 161 }
177
178 return success;
179 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698