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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-connect-audioratesignal.html

Issue 2651253004: Convert non-Audit AudioParam tests to testharness (Closed)
Patch Set: Remove unneeded expected results. Created 3 years, 10 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/AudioParam/audioparam-connect-audioratesignal-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> 1 <!DOCTYPE html>
2 2
3 <!-- 3 <!--
4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioP aram. 4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioP aram.
hongchan 2017/01/30 17:40:10 Since you're reformatting the whole file, why don'
Raymond Toy 2017/01/30 17:57:35 Because clang-format was only run on the JS code.
5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSou rceNode 5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSou rceNode
6 playing an AudioBuffer containing a specific curve can be connected to an AudioG ainNode's 6 playing an AudioBuffer containing a specific curve can be connected to an AudioG ainNode's
7 .gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audi o source 7 .gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audi o source
8 having its gain changed. We load this one with an AudioBuffer containing a cons tant value of 1. 8 having its gain changed. We load this one with an AudioBuffer containing a cons tant value of 1.
9 Thus it's easy to check that the resultant signal should be equal to the gain-sc aling curve. 9 Thus it's easy to check that the resultant signal should be equal to the gain-sc aling curve.
10 --> 10 -->
11 11
12 <html> 12 <html>
13 <head> 13 <head>
14 <script src="../../resources/js-test.js"></script> 14 <script src="../../resources/testharness.js"></script>
15 <script src="../../resources/testharnessreport.js"></script>
15 <script src="../resources/audit-util.js"></script> 16 <script src="../resources/audit-util.js"></script>
16 <script src="../resources/audio-testing.js"></script> 17 <script src="../resources/audit.js"></script>
17 18
18 </head> 19 </head>
19 <body> 20 <body>
20 21
21 <script> 22 <script>
23 let audit = Audit.createTaskRunner();
22 24
23 var sampleRate = 44100.0; 25 let sampleRate = 44100.0;
24 var lengthInSeconds = 1; 26 let lengthInSeconds = 1;
25 27
26 var context = 0; 28 let context = 0;
27 var constantOneBuffer = 0; 29 let constantOneBuffer = 0;
28 var linearRampBuffer = 0; 30 let linearRampBuffer = 0;
29 31
30 function checkResult(event) { 32 function checkResult(renderedBuffer, should) {
31 var renderedBuffer = event.renderedBuffer; 33 let renderedData = renderedBuffer.getChannelData(0);
32 var renderedData = renderedBuffer.getChannelData(0); 34 let expectedData = linearRampBuffer.getChannelData(0);
33 var expectedData = linearRampBuffer.getChannelData(0); 35 let n = renderedBuffer.length;
34 var n = renderedBuffer.length;
35 36
36 if (n == linearRampBuffer.length) { 37 should(n, 'Rendered signal length').beEqualTo(linearRampBuffer.length);
37 testPassed("Rendered signal is of correct length."); 38
38 } else { 39 // Check that the rendered result exactly matches the buffer used to control
39 testFailed("Rendered signal is not of correct length."); 40 // gain. This is because we're changing the gain of a signal having constant
41 // value 1.
42 let success = true;
43 for (let i = 0; i < n; ++i) {
44 if (renderedData[i] != expectedData[i]) {
45 success = false;
46 break;
40 } 47 }
48 }
41 49
42 // Check that the rendered result exactly matches the buffer used to control gain. 50 should(
43 // This is because we're changing the gain of a signal having constant value 1. 51 success,
44 var success = true; 52 'Rendered signal exactly matches the audio-rate gain changing signal')
45 for (var i = 0; i < n; ++i) { 53 .beTrue();
46 if (renderedData[i] != expectedData[i]) {
47 success = false;
48 break;
49 }
50 }
51
52 if (success) {
53 testPassed("Rendered signal exactly matches the audio-rate gain changing signal.");
54 } else {
55 testFailed("Rendered signal differs from the audio-rate gain changing si gnal.");
56 }
57
58 finishJSTest();
59 } 54 }
60 55
61 function runTest() { 56 audit.define('test', function(task, should) {
62 if (window.testRunner) { 57 let sampleFrameLength = sampleRate * lengthInSeconds;
63 testRunner.dumpAsText();
64 testRunner.waitUntilDone();
65 }
66 58
67 window.jsTestIsAsync = true; 59 // Create offline audio context.
60 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate);
68 61
69 var sampleFrameLength = sampleRate * lengthInSeconds; 62 // Create buffer used by the source which will have its gain controlled.
63 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
70 64
71 // Create offline audio context. 65 // Create buffer used to control gain.
72 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate); 66 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
73 67
74 // Create buffer used by the source which will have its gain controlled. 68 // Create the two sources.
75 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
76 69
77 // Create buffer used to control gain. 70 let constantSource = context.createBufferSource();
78 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength); 71 constantSource.buffer = constantOneBuffer;
79 72
80 // Create the two sources. 73 let gainChangingSource = context.createBufferSource();
74 gainChangingSource.buffer = linearRampBuffer;
81 75
82 var constantSource = context.createBufferSource(); 76 // Create a gain node controlling the gain of constantSource and make the
83 constantSource.buffer = constantOneBuffer; 77 // connections.
78 let gainNode = context.createGain();
84 79
85 var gainChangingSource = context.createBufferSource(); 80 // Intrinsic baseline gain of zero.
86 gainChangingSource.buffer = linearRampBuffer; 81 gainNode.gain.value = 0;
87 82
88 // Create a gain node controlling the gain of constantSource and make the co nnections. 83 constantSource.connect(gainNode);
89 var gainNode = context.createGain(); 84 gainNode.connect(context.destination);
90 85
91 // Intrinsic baseline gain of zero. 86 // Connect an audio-rate signal to control the .gain AudioParam.
92 gainNode.gain.value = 0; 87 // This is the heart of what is being tested.
88 gainChangingSource.connect(gainNode.gain);
93 89
94 constantSource.connect(gainNode); 90 // Start both sources at time 0.
95 gainNode.connect(context.destination); 91 constantSource.start(0);
92 gainChangingSource.start(0);
96 93
97 // Connect an audio-rate signal to control the .gain AudioParam. 94 context.startRendering().then(buffer => {
98 // This is the heart of what is being tested. 95 checkResult(buffer, should);
99 gainChangingSource.connect(gainNode.gain); 96 task.done();
97 });
98 });
100 99
101 // Start both sources at time 0. 100 audit.run();
102 constantSource.start(0);
103 gainChangingSource.start(0);
104
105 context.oncomplete = checkResult;
106 context.startRendering();
107 }
108
109 runTest();
110 successfullyParsed = true;
111 101
112 </script> 102 </script>
113 103
114 </body> 104 </body>
115 </html> 105 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-connect-audioratesignal-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698