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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/ChannelSplitter/audiochannelsplitter.html

Issue 2676683002: Convert ChannelSplitter test to testharness (Closed)
Patch Set: Address review comments. 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/ChannelSplitter/audiochannelsplitter-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 AudioChannelSplitter works correctly. 4 Tests that AudioChannelSplitter works correctly.
5 --> 5 -->
6 6
7 <html> 7 <html>
8 <head> 8 <head>
9 <script src="../../resources/js-test.js"></script> 9 <script src="../../resources/testharness.js"></script>
10 <script src="../../resources/testharnessreport.js"></script>
10 <script src="../resources/audit-util.js"></script> 11 <script src="../resources/audit-util.js"></script>
11 <script src="../resources/audio-testing.js"></script> 12 <script src="../resources/audit.js"></script>
12 </head> 13 </head>
13 14
14 <body> 15 <body>
15 16
16 <div id="description"></div>
17 <div id="console"></div>
18
19 <script> 17 <script>
20 description("Tests AudioChannelSplitter."); 18 var audit = Audit.createTaskRunner();
21 19
22 var sampleRate = 44100.0; 20 var sampleRate = 44100.0;
23 var lengthInSampleFrames = 512; 21 var lengthInSampleFrames = 512;
24 22
25 var context = 0; 23 var context = 0;
26 var sourceBuffer; 24 var sourceBuffer;
27 var sourceNode; 25 var sourceNode;
28 var channelSplitter; 26 var channelSplitter;
29 var channelMerger; 27 var channelMerger;
30 28
31 function createStereoBufferWithDCOffset(length, sampleRate, offset) { 29 function createStereoBufferWithDCOffset(length, sampleRate, offset) {
32 var buffer = context.createBuffer(2, length, sampleRate); 30 var buffer = context.createBuffer(2, length, sampleRate);
33 var n = buffer.length; 31 var n = buffer.length;
34 var channelL = buffer.getChannelData(0); 32 var channelL = buffer.getChannelData(0);
35 var channelR = buffer.getChannelData(1); 33 var channelR = buffer.getChannelData(1);
36 34
37 for (var i = 0; i < n; ++i) { 35 for (var i = 0; i < n; ++i) {
38 channelL[i] = offset; 36 channelL[i] = offset;
39 channelR[i] = -1.0 * offset; 37 channelR[i] = -1.0 * offset;
40 } 38 }
41 39
42 return buffer; 40 return buffer;
43 } 41 }
44 42
45 // checkResult() checks that the rendered buffer is stereo and that the left cha nnel is all -1 and right channel all +1. 43 // checkResult() checks that the rendered buffer is stereo and that the left cha nnel is all -1 and right channel all +1.
46 // In other words, we've reversed the order of the two channels. 44 // In other words, we've reversed the order of the two channels.
47 function checkResult(event) { 45 function checkResult(buffer, should) {
48 var buffer = event.renderedBuffer;
49 46
50 var success = true; 47 var success = true;
51 48
52 if (buffer.numberOfChannels == 2) { 49 if (buffer.numberOfChannels == 2) {
53 var bufferDataL = buffer.getChannelData(0); 50 var bufferDataL = buffer.getChannelData(0);
54 var bufferDataR = buffer.getChannelData(1); 51 var bufferDataR = buffer.getChannelData(1);
55 52
56 // Go through every sample and make sure it's all -1 for the left-channe l, and all +1 for the right-channel. 53 success = should(bufferDataL, "Left channel")
57 for (var i = 0; i < buffer.length; ++i) { 54 .beConstantValueOf(-1) && success;
58 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) { 55 success = should(bufferDataR, "Right channel")
59 success = false; 56 .beConstantValueOf(1) && success;
60 break;
61 }
62 }
63 } else { 57 } else {
64 success = false; 58 success = false;
65 } 59 }
66 60
67 if (success) { 61 should(success, "Left and right channels were exchanged")
68 testPassed("Correctly exchanged left and right channels."); 62 .message("correctly", "incorrectly");
69 } else {
70 testFailed("Error on exchanging left and right channels.");
71 }
72
73 finishJSTest();
74 } 63 }
75 64
76 function runTest() { 65 audit.define("construction", function (task, should) {
77 if (window.testRunner) { 66 task.describe("Construction of ChannelSplitterNode");
78 testRunner.dumpAsText();
79 testRunner.waitUntilDone();
80 }
81
82 window.jsTestIsAsync = true;
83 67
84 // Create stereo offline audio context. 68 // Create stereo offline audio context.
85 context = new OfflineAudioContext(2, lengthInSampleFrames, sampleRate); 69 context = new OfflineAudioContext(2, lengthInSampleFrames, sampleRate);
86 70
87 try { 71 var splitternode;
88 var splitternode = context.createChannelSplitter(0); 72 should(() => {
89 testFailed("Exception should be thrown for numberOfOutputs <= 0."); 73 var splitternode = context.createChannelSplitter(0);
90 } catch(e) { 74 }, "createChannelSplitter(0)")
91 testPassed("Exception been thrown for numberOfOutputs <= 0."); 75 .throw("IndexSizeError");
92 }
93 76
94 try { 77 should(() => {
95 var splitternode = context.createChannelSplitter(33); 78 splitternode = context.createChannelSplitter(33);
96 testFailed("Exception should be thrown for numerOfOutputs >= 32."); 79 }, "createChannelSplitter(33)")
97 } catch(e) { 80 .throw("IndexSizeError");
98 testPassed("Exception been thrown for numberOfOutputs >= 32.");
99 }
100 81
101 try { 82 should(() => {
102 var splitternode = context.createChannelSplitter(32); 83 splitternode = context.createChannelSplitter(32);
103 testPassed("AudioChannelSplitter created successfully with numberOfOutpu ts = 32."); 84 }, "splitternode = context.createChannelSplitter(32)")
104 if (splitternode.numberOfOutputs === 32) 85 .notThrow();
105 testPassed("AudioChannelSplitter has 32 outputs when it is created w ith numberOfOutputs = 32.");
106 else
107 testFailed("AudioChannelSplitter should have 32 outputs when it is c reated with numberOfOutputs = 32.");
108 86
109 if (splitternode.numberOfInputs === 1) 87 should(splitternode.numberOfOutputs,
110 testPassed("AudioChannelSplitter has one input."); 88 "splitternode.numberOfOutputs")
111 else 89 .beEqualTo(32);
112 testFailed("AudioChannelSplitter should have one input."); 90 should(splitternode.numberOfInputs,
113 } catch(e) { 91 "splitternode.numberOfInputs")
114 testFailed("Failed to create AudioChannelSplitter with numberOfInputs = 32."); 92 .beEqualTo(1)
115 }
116 93
117 try { 94 should(() => {
118 var splitternode = context.createChannelSplitter(); 95 splitternode = context.createChannelSplitter();
119 testPassed("AudioChannelSplitter created successfully with empty paramet er."); 96 }, "splitternode = context.createChannelSplitter()")
120 if (splitternode.numberOfOutputs === 6) 97 .notThrow();
121 testPassed("AudioChannelSplitter has 6 outputs when it is created wi th empty parameter.");
122 else
123 testFailed("AudioChannelSplitter should have 6 outputs when it is cr eated with empty parameter.");
124 98
125 if (splitternode.toString().indexOf("ChannelSplitterNode") > -1) 99 should(splitternode.numberOfOutputs,
126 testPassed("ChannelSplitterNode Object is available."); 100 "splitternode.numberOfOutputs")
127 else 101 .beEqualTo(6);
128 testFailed("ChannelSplitterNode Object is not available."); 102
129 } catch(e) { 103 task.done();
130 testFailed("Failed to create AudioChannelSplitter with empty parameter." ); 104 });
131 } 105
106 audit.define("functionality", function (task, should) {
107 task.describe("Functionality of ChannelSplitterNode");
132 108
133 // Create a stereo buffer, with all +1 values in left channel, all -1 in rig ht channel. 109 // Create a stereo buffer, with all +1 values in left channel, all -1 in rig ht channel.
134 sourceBuffer = createStereoBufferWithDCOffset(lengthInSampleFrames, sampleRa te, 1); 110 sourceBuffer = createStereoBufferWithDCOffset(lengthInSampleFrames, sampleRa te, 1);
135 111
136 sourceNode = context.createBufferSource(); 112 sourceNode = context.createBufferSource();
137 sourceNode.buffer = sourceBuffer; 113 sourceNode.buffer = sourceBuffer;
138 114
139 // Create a channel splitter and connect it so that it split the stereo stre am into two mono streams. 115 // Create a channel splitter and connect it so that it split the stereo stre am into two mono streams.
140 channelSplitter = context.createChannelSplitter(2); 116 channelSplitter = context.createChannelSplitter(2);
141 sourceNode.connect(channelSplitter); 117 sourceNode.connect(channelSplitter);
142 118
143 // Create a channel merger to merge the output of channel splitter. 119 // Create a channel merger to merge the output of channel splitter.
144 channelMerger = context.createChannelMerger(); 120 channelMerger = context.createChannelMerger();
145 channelMerger.connect(context.destination); 121 channelMerger.connect(context.destination);
146 122
147 // When merging, exchange channel layout: left->right, right->left 123 // When merging, exchange channel layout: left->right, right->left
148 channelSplitter.connect(channelMerger, 0, 1); 124 channelSplitter.connect(channelMerger, 0, 1);
149 channelSplitter.connect(channelMerger, 1, 0); 125 channelSplitter.connect(channelMerger, 1, 0);
150 126
151 sourceNode.start(0); 127 sourceNode.start(0);
152 128
153 context.oncomplete = checkResult; 129 context.startRendering()
154 context.startRendering(); 130 .then(buffer => checkResult(buffer, should))
155 } 131 .then(task.done.bind(task));
132 });
156 133
157 runTest(); 134 audit.run();
158 135
159 </script> 136 </script>
160 137
161 </body> 138 </body>
162 </html> 139 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/ChannelSplitter/audiochannelsplitter-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698