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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.html

Issue 2594183003: Convert note-grain-on tests to testharness (Closed)
Patch Set: Address review comments and git cl format 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 1 <!doctype>
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/audit-util.js"></script> 6 <script src="../resources/audit-util.js"></script>
6 <script src="../resources/audio-testing.js"></script> 7 <script src="../resources/audit.js"></script>
7 <script src="../resources/note-grain-on-testing.js"></script> 8 <script src="../resources/note-grain-on-testing.js"></script>
8 </head> 9 </head>
9 10
10 <body> 11 <body>
11 <div id="description"></div> 12 <div id="description"></div>
12 <div id="console"></div> 13 <div id="console"></div>
13 14
14 <script> 15 <script>
15 description("Test noteGrainOn offset rendering."); 16 let audit = Audit.createTaskRunner();
16 17
17 // To test noteGrainOn, a single ramp signal is created. 18 // To test noteGrainOn, a single ramp signal is created.
18 // Various sections of the ramp are rendered by noteGrainOn() at 19 // Various sections of the ramp are rendered by noteGrainOn() at
19 // different times, and we verify that the actual output 20 // different times, and we verify that the actual output
20 // consists of the correct section of the ramp at the correct 21 // consists of the correct section of the ramp at the correct
21 // time. 22 // time.
22 23
23 var linearRampBuffer; 24 let linearRampBuffer;
24 25
25 // Array of the grain offset used for each ramp played. 26 // Array of the grain offset used for each ramp played.
26 var grainOffsetTime = []; 27 let grainOffsetTime = [];
27 28
28 // Verify the received signal is a ramp from the correct section 29 // Verify the received signal is a ramp from the correct section
29 // of our ramp signal. 30 // of our ramp signal.
30 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) { 31 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
31 var grainOffsetFrame = timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate); 32 let grainOffsetFrame = timeToSampleFrame(grainOffsetTime[
32 var grainFrameLength = endFrame - startFrame; 33 grainIndex], sampleRate);
33 var ramp = linearRampBuffer.getChannelData(0); 34 let grainFrameLength = endFrame - startFrame;
34 var isCorrect = true; 35 let ramp = linearRampBuffer.getChannelData(0);
36 let isCorrect = true;
35 37
36 var expected; 38 let expected;
37 var actual; 39 let actual;
38 var frame; 40 let frame;
39 41
40 for (var k = 0; k < grainFrameLength; ++k) { 42 for (let k = 0; k < grainFrameLength; ++k) {
41 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) { 43 if (renderedData[startFrame + k] != ramp[grainOffsetFrame +
44 k]) {
42 expected = ramp[grainOffsetFrame + k]; 45 expected = ramp[grainOffsetFrame + k];
43 actual = renderedData[startFrame + k]; 46 actual = renderedData[startFrame + k];
44 frame = startFrame + k; 47 frame = startFrame + k;
45 isCorrect = false; 48 isCorrect = false;
46 break; 49 break;
47 } 50 }
48 } 51 }
49 return { verified: isCorrect, 52 return {
50 expected : expected , 53 verified: isCorrect,
51 actual : actual, 54 expected: expected,
52 frame : frame }; 55 actual: actual,
56 frame: frame
57 };
53 } 58 }
54 59
55 function checkResult(event) { 60 function checkResult(buffer, should) {
56 var buffer = event.renderedBuffer;
57 renderedData = buffer.getChannelData(0); 61 renderedData = buffer.getChannelData(0);
58 var nSamples = renderedData.length; 62 let nSamples = renderedData.length;
59
60 var success = true;
61 63
62 // Number of grains that we found that have incorrect data. 64 // Number of grains that we found that have incorrect data.
63 var invalidGrainDataCount = 0; 65 let invalidGrainDataCount = 0;
64 66
65 var startEndFrames = findStartAndEndSamples(renderedData); 67 let startEndFrames = findStartAndEndSamples(renderedData);
66 68
67 // Verify the start and stop times. Not strictly needed for 69 // Verify the start and stop times. Not strictly needed for
68 // this test, but it's useful to know that if the ramp data 70 // this test, but it's useful to know that if the ramp data
69 // appears to be incorrect. 71 // appears to be incorrect.
70 success = success && verifyStartAndEndFrames(startEndFrames); 72 verifyStartAndEndFrames(startEndFrames, should);
71 73
72 // Loop through each of the rendered grains and check that 74 // Loop through each of the rendered grains and check that
73 // each grain contains our expected ramp. 75 // each grain contains our expected ramp.
74 for (var k = 0; k < startEndFrames.start.length; ++k) { 76 for (let k = 0; k < startEndFrames.start.length; ++k) {
75 // Verify that the rendered data matches the expected 77 // Verify that the rendered data matches the expected
76 // section of our ramp signal. 78 // section of our ramp signal.
77 var result = verifyGrain(renderedData, startEndFrames.start[k], st artEndFrames.end[k], k); 79 let result = verifyGrain(renderedData, startEndFrames.start[
78 80 k], startEndFrames.end[k], k);
79 if (!result.verified) { 81 should(result.verified, "Pulse " + k +
80 testFailed("Grain " + k + " incorrect. Expected " + result.ex pected + " but received " + result.actual + " at sample frame " + result.frame); 82 " contained the expected data")
81 ++invalidGrainDataCount; 83 .beTrue();
82 success = false;
83 }
84 } 84 }
85 85 should(invalidGrainDataCount,
86 if (!invalidGrainDataCount) { 86 "Number of grains that did not contain the expected data")
87 testPassed("All " + numberOfTests + " grains contained the correct data."); 87 .beEqualTo(0);
88 } else {
89 testFailed(invalidGrainDataCount + " grains out of " + numberOfTes ts + " did not contain the expected data.");
90 success = false;
91 }
92
93 if (success) {
94 testPassed("noteGrainOn offset rendering tests passed.");
95 } else {
96 testFailed("noteGrainOn offset rendering tests failed.");
97 }
98
99 finishJSTest();
100 } 88 }
101 89
102 function runTest() { 90 audit.define("note-grain-on-play", function(task, should) {
103 if (window.testRunner) { 91 task.describe("Test noteGrainOn offset rendering");
104 testRunner.dumpAsText();
105 testRunner.waitUntilDone();
106 }
107
108 window.jsTestIsAsync = true;
109
110 // Create offline audio context. 92 // Create offline audio context.
111 context = new OfflineAudioContext(2, sampleRate * renderTime, sampleRa te); 93 context = new OfflineAudioContext(2, sampleRate *
94 renderTime, sampleRate);
112 95
113 // Create a linear ramp for testing noteGrainOn. 96 // Create a linear ramp for testing noteGrainOn.
114 linearRampBuffer = createSignalBuffer(context, 97 linearRampBuffer = createSignalBuffer(context,
115 function(k) { 98 function(k) {
116 // Want the ramp to start 99 // Want the ramp to start
117 // with 1, not 0. 100 // with 1, not 0.
118 return k + 1; 101 return k + 1;
119 }); 102 });
120 103
121 var grainInfo = playAllGrains(context, linearRampBuffer, numberOfTests ); 104 let grainInfo = playAllGrains(context, linearRampBuffer,
105 numberOfTests);
122 106
123 grainOffsetTime = grainInfo.grainOffsetTimes; 107 grainOffsetTime = grainInfo.grainOffsetTimes;
124 108
125 context.oncomplete = checkResult; 109 context.startRendering()
126 context.startRendering(); 110 .then(function(audioBuffer) {
127 } 111 checkResult(audioBuffer, should);
112 task.done();
113 });
114 });
128 115
129 runTest(); 116 audit.run();
130 successfullyParsed = true;
131
132 </script> 117 </script>
133
134 </body> 118 </body>
135 </html> 119 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698