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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-connect-method-chaining.html

Issue 2781943002: Convert AudioNode tests to new Audit (Closed)
Patch Set: Created 3 years, 8 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/AudioNode/audionode-disconnect.html » ('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 <html> 2 <html>
3 3
4 <head> 4 <head>
5 <script src="../../resources/testharness.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audit-util.js"></script> 7 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audio-testing.js"></script> 8 <script src="../resources/audit.js"></script>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 13
14 // AudioNode dictionary with associated arguments. 14 // AudioNode dictionary with associated arguments.
15 var nodeDictionary = [ 15 var nodeDictionary = [
16 { name: 'Analyser' }, 16 { name: 'Analyser' },
17 { name: 'BiquadFilter' }, 17 { name: 'BiquadFilter' },
18 { name: 'BufferSource' }, 18 { name: 'BufferSource' },
19 { name: 'ChannelMerger', args: [6] }, 19 { name: 'ChannelMerger', args: [6] },
20 { name: 'ChannelSplitter', args: [6] }, 20 { name: 'ChannelSplitter', args: [6] },
21 { name: 'Convolver' }, 21 { name: 'Convolver' },
22 { name: 'Delay', args: [] }, 22 { name: 'Delay', args: [] },
23 { name: 'DynamicsCompressor' }, 23 { name: 'DynamicsCompressor' },
24 { name: 'Gain' }, 24 { name: 'Gain' },
25 { name: 'Oscillator' }, 25 { name: 'Oscillator' },
26 { name: 'Panner' }, 26 { name: 'Panner' },
27 { name: 'ScriptProcessor', args: [512, 1, 1] }, 27 { name: 'ScriptProcessor', args: [512, 1, 1] },
28 { name: 'StereoPanner' }, 28 { name: 'StereoPanner' },
29 { name: 'WaveShaper' } 29 { name: 'WaveShaper' }
30 ]; 30 ];
31 31
32 32
33 function verifyReturnedNode(config) { 33 function verifyReturnedNode(should, config) {
34 Should('The return value of ' + config.desc + 34 should(config.destination === config.returned,
35 'The return value of ' + config.desc +
35 ' matches the destination ' + 36 ' matches the destination ' +
36 config.returned.constructor.name, 37 config.returned.constructor.name)
37 config.destination === config.returned
38 )
39 .beEqualTo(true); 38 .beEqualTo(true);
40 } 39 }
41 40
42 // Test utility for batch method checking: in order to test 3 method 41 // Test utility for batch method checking: in order to test 3 method
43 // signatures, so we create 3 dummy destinations. 42 // signatures, so we create 3 dummy destinations.
44 // 1) .connect(GainNode) 43 // 1) .connect(GainNode)
45 // 2) .connect(BiquadFilterNode, output) 44 // 2) .connect(BiquadFilterNode, output)
46 // 3) .connect(ChannelMergerNode, output, input) 45 // 3) .connect(ChannelMergerNode, output, input)
47 function testConnectMethod(context, options) { 46 function testConnectMethod(context, should, options) {
48 var source = context['create' + options.name].apply(context, options.args) ; 47 var source = context['create' + options.name].apply(context, options.args) ;
49 var sourceName = source.constructor.name; 48 var sourceName = source.constructor.name;
50 49
51 var destination1 = context.createGain(); 50 var destination1 = context.createGain();
52 verifyReturnedNode({ 51 verifyReturnedNode(should, {
53 source: source, 52 source: source,
54 destination: destination1, 53 destination: destination1,
55 returned: source.connect(destination1), 54 returned: source.connect(destination1),
56 desc: sourceName + '.connect(' + destination1.constructor.name + ')' 55 desc: sourceName + '.connect(' + destination1.constructor.name + ')'
57 }); 56 });
58 57
59 var destination2 = context.createBiquadFilter(); 58 var destination2 = context.createBiquadFilter();
60 verifyReturnedNode({ 59 verifyReturnedNode(should, {
61 source: source, 60 source: source,
62 destination: destination2, 61 destination: destination2,
63 returned: source.connect(destination2, 0), 62 returned: source.connect(destination2, 0),
64 desc: sourceName + '.connect(' + destination2.constructor.name + ', 0)' 63 desc: sourceName + '.connect(' + destination2.constructor.name + ', 0)'
65 }); 64 });
66 65
67 var destination3 = context.createChannelMerger(); 66 var destination3 = context.createChannelMerger();
68 verifyReturnedNode({ 67 verifyReturnedNode(should, {
69 source: source, 68 source: source,
70 destination: destination3, 69 destination: destination3,
71 returned: source.connect(destination3, 0, 1), 70 returned: source.connect(destination3, 0, 1),
72 desc: sourceName + '.connect(' + destination3.constructor.name + ', 0, 1 )' 71 desc: sourceName + '.connect(' + destination3.constructor.name + ', 0, 1 )'
73 }); 72 });
74 } 73 }
75 74
76 75
77 var audit = Audit.createTaskRunner(); 76 var audit = Audit.createTaskRunner();
78 77
79 // Task: testing entries from the dictionary. 78 // Task: testing entries from the dictionary.
80 audit.defineTask('from-dictionary', function (done) { 79 audit.define('from-dictionary', (task, should) => {
81 var context = new AudioContext(); 80 var context = new AudioContext();
82 81
83 for (var i = 0; i < nodeDictionary.length; i++) 82 for (var i = 0; i < nodeDictionary.length; i++)
84 testConnectMethod(context, nodeDictionary[i]); 83 testConnectMethod(context, should, nodeDictionary[i]);
85 84
86 done(); 85 task.done();
87 }); 86 });
88 87
89 // Task: testing Media* nodes. 88 // Task: testing Media* nodes.
90 audit.defineTask('media-group', function (done) { 89 audit.define('media-group', (task, should) => {
91 var context = new AudioContext(); 90 var context = new AudioContext();
92 91
93 // Test MediaElementSourceNode needs an <audio> element. 92 // Test MediaElementSourceNode needs an <audio> element.
94 var mediaElement = document.createElement('audio'); 93 var mediaElement = document.createElement('audio');
95 testConnectMethod(context, { name: 'MediaElementSource', args: [mediaEleme nt] }); 94 testConnectMethod(context, should, { name: 'MediaElementSource', args: [me diaElement] });
96 95
97 testConnectMethod(context, { name: 'MediaStreamDestination' }); 96 testConnectMethod(context, should, { name: 'MediaStreamDestination' });
98 97
99 // MediaStreamSourceNode requires 'stream' object to be constructed, which 98 // MediaStreamSourceNode requires 'stream' object to be constructed, which
100 // is a part of MediaStreamDestinationNode. 99 // is a part of MediaStreamDestinationNode.
101 var streamDestination = context.createMediaStreamDestination(); 100 var streamDestination = context.createMediaStreamDestination();
102 var stream = streamDestination.stream; 101 var stream = streamDestination.stream;
103 testConnectMethod(context, { name: 'MediaStreamSource', args: [stream] }); 102 testConnectMethod(context, should, { name: 'MediaStreamSource', args: [str eam] });
104 103
105 done(); 104 task.done();
106 }); 105 });
107 106
108 // Task: test the exception thrown by invalid operation. 107 // Task: test the exception thrown by invalid operation.
109 audit.defineTask('invalid-operation', function (done) { 108 audit.define('invalid-operation', (task, should) => {
110 var contextA = new AudioContext(); 109 var contextA = new AudioContext();
111 var contextB = new AudioContext(); 110 var contextB = new AudioContext();
112 var gain1 = contextA.createGain(); 111 var gain1 = contextA.createGain();
113 var gain2 = contextA.createGain(); 112 var gain2 = contextA.createGain();
114 113
115 // Test if the first connection throws correctly. The first gain node does 114 // Test if the first connection throws correctly. The first gain node does
116 // not have the second output, so it should throw. 115 // not have the second output, so it should throw.
117 Should('Connecting with an invalid output', function () { 116 should(function () {
118 gain1.connect(gain2, 1).connect(contextA.destination); 117 gain1.connect(gain2, 1).connect(contextA.destination);
119 }).throw('IndexSizeError'); 118 }, 'Connecting with an invalid output').throw('IndexSizeError');
120 119
121 // Test if the second connection throws correctly. The contextB's 120 // Test if the second connection throws correctly. The contextB's
122 // destination is not compatible with the nodes from contextA, thus the 121 // destination is not compatible with the nodes from contextA, thus the
123 // first connection succeeds but the second one should throw. 122 // first connection succeeds but the second one should throw.
124 Should('Connecting to a node from the different context', function () { 123 should(function () {
125 gain1.connect(gain2).connect(contextB.destination); 124 gain1.connect(gain2).connect(contextB.destination);
126 }).throw('InvalidAccessError'); 125 }, 'Connecting to a node from the different context').throw('InvalidAccess Error');
127 126
128 done(); 127 task.done();
129 }); 128 });
130 129
131 // Task: verify if the method chaining actually works. 130 // Task: verify if the method chaining actually works.
132 audit.defineTask('verification', function (done) { 131 audit.define('verification', (task, should) => {
133 // We pick the lowest sample rate allowed to run the test efficiently. 132 // We pick the lowest sample rate allowed to run the test efficiently.
134 var context = new OfflineAudioContext(1, 128, 3000); 133 var context = new OfflineAudioContext(1, 128, 3000);
135 134
136 var constantBuffer = createConstantBuffer(context, 1, 1.0); 135 var constantBuffer = createConstantBuffer(context, 1, 1.0);
137 136
138 var source = context.createBufferSource(); 137 var source = context.createBufferSource();
139 source.buffer = constantBuffer; 138 source.buffer = constantBuffer;
140 source.loop = true; 139 source.loop = true;
141 140
142 var gain1 = context.createGain(); 141 var gain1 = context.createGain();
143 gain1.gain.value = 0.5; 142 gain1.gain.value = 0.5;
144 var gain2 = context.createGain(); 143 var gain2 = context.createGain();
145 gain2.gain.value = 0.25; 144 gain2.gain.value = 0.25;
146 145
147 source.connect(gain1).connect(gain2).connect(context.destination); 146 source.connect(gain1).connect(gain2).connect(context.destination);
148 source.start(); 147 source.start();
149 148
150 context.startRendering().then(function (buffer) { 149 context.startRendering().then(function (buffer) {
151 Should('The output of chained connection of gain nodes', buffer.getChann elData(0)) 150 should(buffer.getChannelData(0), 'The output of chained connection of ga in nodes')
152 .beConstantValueOf(0.125); 151 .beConstantValueOf(0.125);
153 }).then(done); 152 }).then(() => task.done());
154 }); 153 });
155 154
156 audit.defineTask('finish', function (done) { 155 audit.run();
157 done();
158 });
159
160 audit.runTasks(
161 'from-dictionary',
162 'media-group',
163 'invalid-operation',
164 'verification',
165 'finish'
166 );
167
168 successfullyParsed = true;
169 </script> 156 </script>
170 </body> 157 </body>
171 158
172 </html> 159 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-disconnect.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698