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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-suspend-resume-graph-manipulation.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 <title>
5 offlineaudiocontext-suspend-resume-graph-manipulation.html
6 </title>
4 <script src="../../resources/testharness.js"></script> 7 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 8 <script src="../../resources/testharnessreport.js"></script>
6 <script src="../resources/audit-util.js"></script> 9 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audit.js"></script> 10 <script src="../resources/audit.js"></script>
8 </head> 11 </head>
12 <body>
13 <script id="layout-test-code">
14 let audit = Audit.createTaskRunner();
9 15
10 <body> 16 let context;
11 <script> 17 let renderQuantum = 128;
12 var audit = Audit.createTaskRunner(); 18 let renderDuration = 3;
13
14 var context;
15 var renderQuantum = 128;
16 var renderDuration = 3;
17 19
18 // The sample rate is multiple of the rendering quantum, so suspension 20 // The sample rate is multiple of the rendering quantum, so suspension
19 // times fall in to the render quantum boundary. 21 // times fall in to the render quantum boundary.
20 var sampleRate = renderQuantum * 100; 22 let sampleRate = renderQuantum * 100;
21 23
22 // Suspend at 1 second and activate the source node. The audio output 24 // Suspend at 1 second and activate the source node. The audio output
23 // should be 1.0 from |suspendTime1| to the next suspension. 25 // should be 1.0 from |suspendTime1| to the next suspension.
24 var suspendTime1 = 1; 26 let suspendTime1 = 1;
25 27
26 // Suspend at 2 seconds and disconnect the node. The audio output should 28 // Suspend at 2 seconds and disconnect the node. The audio output should
27 // be 0.0 from |suspendTime2| to the end. 29 // be 0.0 from |suspendTime2| to the end.
28 var suspendTime2 = 2; 30 let suspendTime2 = 2;
29 31
30 audit.define({ 32 audit.define(
31 label: 'test', 33 {
32 description: 'Synchronous graph manipulation with suspend() and resume() ' 34 label: 'test',
33 }, (task, should) => { 35 description:
34 context = new OfflineAudioContext(1, sampleRate * renderDuration, 36 'Synchronous graph manipulation with suspend() and resume()'
35 sampleRate); 37 },
38 (task, should) => {
39 context = new OfflineAudioContext(
40 1, sampleRate * renderDuration, sampleRate);
36 41
37 // Create a constant buffer of 1.0. 42 // Create a constant buffer of 1.0.
38 var constantBuffer = createConstantBuffer(context, 1, 1.0); 43 let constantBuffer = createConstantBuffer(context, 1, 1.0);
39 var constantSource = context.createBufferSource(); 44 let constantSource = context.createBufferSource();
40 constantSource.buffer = constantBuffer; 45 constantSource.buffer = constantBuffer;
41 constantSource.loop = true; 46 constantSource.loop = true;
42 47
43 // The audio output from the beginning (0.0 second) to the first suspend 48 // The audio output from the beginning (0.0 second) to the first
44 // time should be 0.0 because there is no connection to the destination. 49 // suspend time should be 0.0 because there is no connection to the
50 // destination.
45 51
46 context.suspend(suspendTime1).then(function () { 52 context.suspend(suspendTime1).then(function() {
47 if (context.currentTime === suspendTime1) { 53 if (context.currentTime === suspendTime1) {
48 should(context.currentTime * sampleRate, 54 should(
49 'Frame at which context is suspended') 55 context.currentTime * sampleRate,
50 .beEqualTo(suspendTime1 * sampleRate) 56 'Frame at which context is suspended')
51 } 57 .beEqualTo(suspendTime1 * sampleRate)
52 should(() => { 58 }
53 constantSource.connect(context.destination); 59 should(
54 constantSource.start() 60 () => {
55 }, 61 constantSource.connect(context.destination);
56 'Connecting a constant buffer to destination and starting at ' + 62 constantSource.start()
57 suspendTime1 * sampleRate + ' frame') 63 },
58 .notThrow();; 64 'Connecting a constant buffer to destination and starting at ' +
59 context.resume(); 65 suspendTime1 * sampleRate + ' frame')
60 }); 66 .notThrow();
67 ;
68 context.resume();
69 });
61 70
62 context.suspend(suspendTime2).then(function () { 71 context.suspend(suspendTime2).then(function() {
63 if (context.currentTime === suspendTime2) { 72 if (context.currentTime === suspendTime2) {
64 should(context.currentTime * sampleRate, 73 should(context.currentTime * sampleRate, 'Context is suspended')
65 'Context is suspended') 74 .beEqualTo(suspendTime2 * sampleRate);
66 .beEqualTo(suspendTime2 * sampleRate); 75 }
67 } 76 should(
68 should(() => constantSource.disconnect(), 77 () => constantSource.disconnect(),
69 'Disconnecting a constant buffer at ' + suspendTime2 * 78 'Disconnecting a constant buffer at ' +
70 sampleRate + ' frame') 79 suspendTime2 * sampleRate + ' frame')
71 .notThrow(); 80 .notThrow();
72 81
73 context.resume(); 82 context.resume();
74 }); 83 });
75 84
76 context.startRendering().then(function (buffer) { 85 context.startRendering()
77 verifyResult(should, buffer); 86 .then(function(buffer) {
78 }).then(() => task.done()); 87 verifyResult(should, buffer);
79 }); 88 })
89 .then(() => task.done());
90 });
80 91
81 function verifyResult(should, buffer) { 92 function verifyResult(should, buffer) {
82 var data = buffer.getChannelData(0); 93 let data = buffer.getChannelData(0);
83 94
84 var suspendIndex1 = suspendTime1 * sampleRate; 95 let suspendIndex1 = suspendTime1 * sampleRate;
85 var suspendIndex2 = suspendTime2 * sampleRate; 96 let suspendIndex2 = suspendTime2 * sampleRate;
86 var endIndex = renderDuration * sampleRate; 97 let endIndex = renderDuration * sampleRate;
87 98
88 // Split the rendered buffer into 3 segments: 99 // Split the rendered buffer into 3 segments:
89 // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2, 100 // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2,
90 // endIndex). 101 // endIndex).
91 var subarray0 = data.subarray(0, suspendIndex1); 102 let subarray0 = data.subarray(0, suspendIndex1);
92 var subarray1 = data.subarray(suspendIndex1, suspendIndex2); 103 let subarray1 = data.subarray(suspendIndex1, suspendIndex2);
93 var subarray2 = data.subarray(suspendIndex2, endIndex); 104 let subarray2 = data.subarray(suspendIndex2, endIndex);
94 105
95 // Each segment should contain a constant value of 0, 1 and 0 106 // Each segment should contain a constant value of 0, 1 and 0
96 // respectively. 107 // respectively.
97 should(subarray0, 'Buffer frame [0, ' + suspendIndex1 + ')') 108 should(subarray0, 'Buffer frame [0, ' + suspendIndex1 + ')')
98 .beConstantValueOf(0); 109 .beConstantValueOf(0);
99 should(subarray1, 'Buffer frame [' + suspendIndex1 + ', ' + 110 should(
100 suspendIndex2 + ')') 111 subarray1,
101 .beConstantValueOf(1); 112 'Buffer frame [' + suspendIndex1 + ', ' + suspendIndex2 + ')')
102 should(subarray2, 'Buffer frame [' + suspendIndex2 + ', ' + endIndex + 113 .beConstantValueOf(1);
103 ')') 114 should(
104 .beConstantValueOf(0); 115 subarray2, 'Buffer frame [' + suspendIndex2 + ', ' + endIndex + ')')
116 .beConstantValueOf(0);
105 } 117 }
106 118
107 audit.run(); 119 audit.run();
108 </script> 120 </script>
109
110 </body> 121 </body>
111 </html> 122 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698