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/ScriptProcessor/scriptprocessornode.html

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (Closed)
Patch Set: Created 3 years, 7 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 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../resources/testharness.js"></script> 4 <title>
5 <script src="../../resources/testharnessreport.js"></script> 5 scriptprocessornode.html
6 <script src="../resources/audit-util.js"></script> 6 </title>
7 <script src="../resources/audit.js"></script> 7 <script src="../../resources/testharness.js"></script>
8 </head> 8 <script src="../../resources/testharnessreport.js"></script>
9 <script src="../resources/audit-util.js"></script>
10 <script src="../resources/audit.js"></script>
11 </head>
12 <body>
13 <script id="layout-test-code">
14 let audit = Audit.createTaskRunner();
9 15
10 <body> 16 let sampleRate = 44100.0;
11 <script> 17 let outputChannels = 6;
12 let audit = Audit.createTaskRunner(); 18 let playbackTime = 0.0;
13 19
14 let sampleRate = 44100.0; 20 // For the current implementation of ScriptProcessorNode, when it works
15 let outputChannels = 6; 21 // with OfflineAudioContext (which runs much faster than real-time) the
16 let playbackTime = 0.0; 22 // event.inputBuffer might be overwrite again before onaudioprocess ever
23 // get chance to be called. We carefully arrange the renderLengthInFrames
24 // and bufferSize to have exactly the same value to avoid this issue.
25 let renderLengthInFrames = 512;
26 let bufferSize = 512;
17 27
18 // For the current implementation of ScriptProcessorNode, when it works with 28 let context;
19 // OfflineAudioContext (which runs much faster than real-time) the
20 // event.inputBuffer might be overwrite again before onaudioprocess ever get
21 // chance to be called. We carefully arrange the renderLengthInFrames and
22 // bufferSize to have exactly the same value to avoid this issue.
23 let renderLengthInFrames = 512;
24 let bufferSize = 512;
25 29
26 let context; 30 function createBuffer(context, length) {
31 let audioBuffer = context.createBuffer(2, length, sampleRate);
32 let n = audioBuffer.length;
33 let dataL = audioBuffer.getChannelData(0);
34 let dataR = audioBuffer.getChannelData(1);
27 35
28 function createBuffer(context, length) { 36 for (let i = 0; i < n; ++i) {
29 let audioBuffer = context.createBuffer(2, length, sampleRate); 37 dataL[i] = -1;
30 let n = audioBuffer.length; 38 dataR[i] = 1;
31 let dataL = audioBuffer.getChannelData(0); 39 }
32 let dataR = audioBuffer.getChannelData(1);
33 40
34 for (let i = 0; i < n; ++i) { 41 return audioBuffer;
35 dataL[i] = -1; 42 }
36 dataR[i] = 1;
37 }
38 43
39 return audioBuffer; 44 function processAudioData(event, should) {
40 } 45 playbackTime = event.playbackTime;
46 let expectedTime =
47 context.currentTime + (bufferSize / context.sampleRate);
48 let allowedTimeGap = 0.0000001;
41 49
42 function processAudioData(event, should) { 50 // There may be a little time gap which is from different thread
43 playbackTime = event.playbackTime; 51 // operation between currentTime when main thread fires onaudioprocess()
44 let expectedTime = context.currentTime + (bufferSize / context.sampleRate); 52 // and currentTime when read in JS since currentTime is continuously
45 let allowedTimeGap = 0.0000001; 53 // increasing on audio thread.
46 54
47 // There may be a little time gap which is from different thread operation 55 should(playbackTime, 'playbackTime').beCloseTo(expectedTime, {
48 // between currentTime when main thread fires onaudioprocess() and currentTime 56 threshold: allowedTimeGap
49 // when read in JS since currentTime is continuously increasing on audio 57 });
50 // thread.
51 58
52 should(playbackTime, 'playbackTime').beCloseTo(expectedTime, { 59 buffer = event.outputBuffer;
53 threshold: allowedTimeGap 60 should(buffer.numberOfChannels, 'Number of output channels')
54 }); 61 .beEqualTo(outputChannels);
62 should(buffer.length, 'Length of buffer').beEqualTo(bufferSize);
55 63
56 buffer = event.outputBuffer; 64 buffer = event.inputBuffer;
57 should(buffer.numberOfChannels, 'Number of output channels') 65 let bufferDataL = buffer.getChannelData(0);
58 .beEqualTo(outputChannels); 66 let bufferDataR = buffer.getChannelData(1);
59 should(buffer.length, 'Length of buffer').beEqualTo(bufferSize);
60 67
61 buffer = event.inputBuffer; 68 should(bufferDataL, 'Left channel').beConstantValueOf(-1);
62 let bufferDataL = buffer.getChannelData(0); 69 should(bufferDataR, 'Right channel').beConstantValueOf(1);
63 let bufferDataR = buffer.getChannelData(1); 70 }
64 71
65 should(bufferDataL, 'Left channel').beConstantValueOf(-1); 72 function doBufferSizeTest(size, should) {
66 should(bufferDataR, 'Right channel').beConstantValueOf(1); 73 should(() => {
67 } 74 context.createScriptProcessor(size, 1, 1);
75 }, 'context.createScriptProcessor(' + size + ', 1, 1)').notThrow();
76 }
68 77
69 function doBufferSizeTest(size, should) { 78 audit.define(
70 should(() => { 79 {label: 'test', description: 'Basic ScriptProcessorNode properties'},
71 context.createScriptProcessor(size, 1, 1); 80 (task, should) => {
72 }, 'context.createScriptProcessor(' + size + ', 1, 1)').notThrow(); 81 // Create offline audio context.
73 } 82 context =
83 new OfflineAudioContext(2, renderLengthInFrames, sampleRate);
74 84
75 audit.define( 85 should(() => {
76 {label: 'test', description: 'Basic ScriptProcessorNode properties'}, 86 context.createScriptProcessor(512, 0, 0);
77 (task, should) => { 87 }, 'createScriptProcessor(512, 0, 0)').throw();
78 // Create offline audio context.
79 context = new OfflineAudioContext(2, renderLengthInFrames, sampleRate);
80 88
81 should(() => { 89 should(() => {
82 context.createScriptProcessor(512, 0, 0); 90 context.createScriptProcessor(512, 1, 0);
83 }, 'createScriptProcessor(512, 0, 0)').throw(); 91 }, 'context.createScriptProcessor(512, 1, 0)').notThrow();
84 92
85 should(() => { 93 should(() => {
86 context.createScriptProcessor(512, 1, 0); 94 context.createScriptProcessor(512, 2, 0);
87 }, 'context.createScriptProcessor(512, 1, 0)').notThrow(); 95 }, 'context.createScriptProcessor(512, 2, 0)').notThrow();
88 96
89 should(() => { 97 should(() => {
90 context.createScriptProcessor(512, 2, 0); 98 context.createScriptProcessor(512, 0, 1);
91 }, 'context.createScriptProcessor(512, 2, 0)').notThrow(); 99 }, 'context.createScriptProcessor(512, 0, 1)').notThrow();
92 100
93 should(() => { 101 should(() => {
94 context.createScriptProcessor(512, 0, 1); 102 context.createScriptProcessor(512, 0, 2);
95 }, 'context.createScriptProcessor(512, 0, 1)').notThrow(); 103 }, 'context.createScriptProcessor(512, 0, 2)').notThrow();
104 should(() => {
105 context.createScriptProcessor(511, 1, 1);
106 }, 'context.createScriptProcessor(511, 1, 1)').throw();
96 107
97 should(() => { 108 doBufferSizeTest(256, should);
98 context.createScriptProcessor(512, 0, 2); 109 doBufferSizeTest(512, should);
99 }, 'context.createScriptProcessor(512, 0, 2)').notThrow(); 110 doBufferSizeTest(1024, should);
100 should(() => { 111 doBufferSizeTest(2048, should);
101 context.createScriptProcessor(511, 1, 1); 112 doBufferSizeTest(4096, should);
102 }, 'context.createScriptProcessor(511, 1, 1)').throw(); 113 doBufferSizeTest(8192, should);
114 doBufferSizeTest(16384, should);
103 115
104 doBufferSizeTest(256, should); 116 let sourceBuffer = createBuffer(context, renderLengthInFrames);
105 doBufferSizeTest(512, should);
106 doBufferSizeTest(1024, should);
107 doBufferSizeTest(2048, should);
108 doBufferSizeTest(4096, should);
109 doBufferSizeTest(8192, should);
110 doBufferSizeTest(16384, should);
111 117
112 let sourceBuffer = createBuffer(context, renderLengthInFrames); 118 let bufferSource = context.createBufferSource();
119 bufferSource.buffer = sourceBuffer;
113 120
114 let bufferSource = context.createBufferSource(); 121 let jsnode =
115 bufferSource.buffer = sourceBuffer; 122 context.createScriptProcessor(bufferSize, 2, outputChannels);
116 123
117 let jsnode = context.createScriptProcessor(bufferSize, 2, outputChannels); 124 bufferSource.connect(jsnode);
125 jsnode.connect(context.destination);
126 jsnode.onaudioprocess = event => {
127 processAudioData(event, should);
128 };
118 129
119 bufferSource.connect(jsnode); 130 bufferSource.start(0);
120 jsnode.connect(context.destination);
121 jsnode.onaudioprocess = event => {
122 processAudioData(event, should);
123 };
124 131
125 bufferSource.start(0); 132 context.startRendering().then(() => task.done());
133 ;
134 });
126 135
127 context.startRendering().then(() => task.done()); 136 audit.run();
128 ; 137 </script>
129 }); 138 </body>
130
131 audit.run();
132 </script>
133
134 </body>
135 </html> 139 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698