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

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

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