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

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: Clean up 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;
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;
(...skipping 88 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; 113 var success = true;
114 114
115 // Count of how many grains started at the incorrect time. 115 // Count of how many grains started at the incorrect time.
116 var errorCountStart = 0; 116 var errorCountStart = 0;
117 117
118 // Count of how many grains ended at the incorrect time. 118 // Count of how many grains ended at the incorrect time.
119 var errorCountEnd = 0; 119 var errorCountEnd = 0;
120 120
121 if (startFrames.length != endFrames.length) { 121 success = should(startFrames.length == endFrames.length,
122 testFailed("Could not find the beginning or end of a grain."); 122 "Found all grain starts and ends").beTrue()
123 success = false; 123 && success;
hongchan 2017/01/18 18:19:04 Please see the comment at the end.
124 }
125 124
126 if (startFrames.length == numberOfTests && endFrames.length == numberOfTests ) { 125 success = should(startFrames.length, "Number of start frames").beEqualTo(num berOfTests)
127 testPassed("Found all " + numberOfTests + " grains."); 126 && success;
128 } else { 127 success = should(endFrames.length, "Number of end frames").beEqualTo(numberO fTests)
129 testFailed("Did not find all " + numberOfTests + " grains."); 128 && success;
hongchan 2017/01/18 18:19:04 Ditto.
130 }
131 129
132 // Examine the start and stop times to see if they match our 130 // Examine the start and stop times to see if they match our
133 // expectations. 131 // expectations.
134 for (var k = 0; k < startFrames.length; ++k) { 132 for (var k = 0; k < startFrames.length; ++k) {
135 var expectedStart = timeToSampleFrame(k * timeStep, sampleRate); 133 var expectedStart = timeToSampleFrame(k * timeStep, sampleRate);
136 // The end point is the duration, plus the extra frames 134 // The end point is the duration, plus the extra frames
137 // for HRTF. 135 // for HRTF.
138 var expectedEnd = extraFramesHRTF + expectedStart + grainLengthInSampleF rames(k * grainOffsetStep, duration, sampleRate); 136 var expectedEnd = extraFramesHRTF + expectedStart + grainLengthInSampleF rames(k * grainOffsetStep, duration, sampleRate);
139 137
140 if (startFrames[k] != expectedStart) { 138 if (startFrames[k] != expectedStart)
141 testFailed("Pulse " + k + " started at " + startFrames[k] + " but ex pected at " + expectedStart); 139 ++errorCountStart;
142 ++errorCountStart; 140 if (endFrames[k] != expectedEnd)
143 success = false; 141 ++errorCountEnd;
144 }
145 142
146 if (endFrames[k] != expectedEnd) { 143 success = should([startFrames[k], endFrames[k]], "Pulse " + k + " bounda ry")
147 testFailed("Pulse " + k + " ended at " + endFrames[k] + " but expect ed at " + expectedEnd); 144 .beEqualToArray([expectedStart, expectedEnd])
148 ++errorCountEnd; 145 && success;
149 success = false;
150 }
151 } 146 }
152 147
153 // Check that all the grains started or ended at the correct time. 148 // Check that all the grains started or ended at the correct time.
154 if (!errorCountStart) { 149 if (!errorCountStart) {
155 if (startFrames.length == numberOfTests) { 150 success = should(startFrames.length,
156 testPassed("All " + numberOfTests + " grains started at the correct time."); 151 "Number of grains that started at the correct time")
157 } else { 152 .beEqualTo(numberOfTests)
158 testFailed("All grains started at the correct time, but only " + sta rtFrames.length + " grains found."); 153 && success;
159 success = false;
160 }
161 } else { 154 } else {
162 testFailed(errorCountStart + " out of " + numberOfTests + " grains start ed at the wrong time."); 155 success = should(errorCountStart,
163 success = false; 156 "Number of grains out of " + numberOfTests + "that started at the w rong time")
157 .beEqualTo(0)
158 && success;
164 } 159 }
165 160
161
hongchan 2017/01/18 18:19:04 Remove this empty line.
166 if (!errorCountEnd) { 162 if (!errorCountEnd) {
167 if (endFrames.length == numberOfTests) { 163 success = should(endFrames.length,
168 testPassed("All " + numberOfTests + " grains ended at the correct ti me."); 164 "Number of grains that ended at the correct time")
169 } else { 165 .beEqualTo(numberOfTests) && success;
170 testFailed("All grains ended at the correct time, but only " + endFr ames.length + " grains found.");
171 success = false;
172 }
173 } else { 166 } else {
174 testFailed(errorCountEnd + " out of " + numberOfTests + " grains ended a t the wrong time."); 167 success = should(errorCountEnd,
175 success = false; 168 "Number of grains out of " + numberOfTests + " that ended at the wr ong time")
169 .beEqualTo(0)
170 && success;
176 } 171 }
177 172
178 return success; 173 return success;
hongchan 2017/01/18 18:19:04 Just do all the |should| assertions, then get the
Raymond Toy 2017/01/18 19:33:30 I don't think we even need to return success anymo
179 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698