OLD | NEW |
---|---|
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test Constructor: StereoPanner</title> | 4 <title>Test Constructor: StereoPanner</title> |
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 <script src="audionodeoptions.js"></script> | 9 <script src="new-audionodeoptions.js"></script> |
10 </head> | 10 </head> |
11 | 11 |
12 <body> | 12 <body> |
13 <script> | 13 <script> |
14 var context; | 14 var context; |
15 | 15 |
16 var audit = Audit.createTaskRunner(); | 16 var audit = Audit.createTaskRunner(); |
17 | 17 |
18 audit.defineTask("initialize", function (taskDone) { | 18 audit.define('initialize', (task, should) => { |
19 Should("context = new OfflineAudioContext(...)", function () { | 19 context = initializeContext(should); |
20 context = new OfflineAudioContext(1, 1, 48000); | 20 task.done(); |
21 }).notThrow(); | |
22 | |
23 taskDone(); | |
24 }); | 21 }); |
25 | 22 |
26 audit.defineTask("invalid constructor", function (taskDone) { | 23 audit.define('invalid constructor', (task, should) => { |
27 var node; | 24 testInvalidConstructor(should, 'StereoPannerNode', context); |
28 var success = true; | 25 task.done(); |
29 | |
30 success = Should("new StereoPannerNode()", function () { | |
31 node = new StereoPannerNode(); | |
32 }).throw("TypeError"); | |
33 success = Should("new StereoPannerNode(1)", function () { | |
34 node = new StereoPannerNode(1) && success; | |
35 }).throw("TypeError"); | |
36 success = Should("new StereoPannerNode(context, 42)", function () { | |
37 node = new StereoPannerNode(context, 42) && success; | |
38 }).throw("TypeError"); | |
39 | |
40 Should("Invalid constructors", success) | |
41 .summarize( | |
42 "correctly threw errors", | |
43 "did not throw errors in all cases"); | |
44 | |
45 taskDone(); | |
46 }); | 26 }); |
47 | 27 |
48 audit.defineTask("default constructor", function (taskDone) { | 28 audit.define('default constructor', (task, should) => { |
49 var node; | 29 let prefix = 'node0'; |
50 var success = true; | 30 let node = testDefaultConstructor(should, 'StereoPannerNode', context, { |
31 prefix: prefix, | |
32 numberOfInputs: 1, | |
33 numberOfOutputs: 1, | |
34 channelCount: 2, | |
35 channelCountMode: 'clamped-max', | |
36 channelInterpretation: 'speakers' | |
37 }); | |
51 | 38 |
52 success = Should("node0 = new StereoPannerNode(context)", function () { | 39 testDefaultAttributes(should, node, prefix, [{name: 'pan', value: 0}]); |
53 node = new StereoPannerNode(context); | |
54 }).notThrow(); | |
55 success = Should("node0 instanceof StereoPannerNode", node instanceof St ereoPannerNode) | |
56 .beEqualTo(true) && success; | |
57 | 40 |
58 success = Should("node0.pan.value", node.pan.value) | 41 task.done(); |
59 .beEqualTo(0) && success; | |
60 | |
61 Should("new StereoPannerNode(context)", success) | |
62 .summarize( | |
63 "constructed node with correct attributes", | |
64 "did not construct correct node correctly") | |
65 | |
66 taskDone(); | |
67 }); | 42 }); |
68 | 43 |
69 audit.defineTask("test AudioNodeOptions", function (taskDone) { | 44 audit.define('test AudioNodeOptions', (task, should) => { |
70 // Can't use testAudioNodeOptions because the constraints for this node | 45 // Can't use testAudioNodeOptions because the constraints for this node |
71 // are not supported there. | 46 // are not supported there. |
72 var node; | 47 var node; |
73 var success = true; | |
74 | 48 |
75 // Test that we can set the channel count to 1 or 2. | 49 // Test that we can set the channel count to 1 or 2. |
76 var options = { | 50 var options = {channelCount: 1}; |
hongchan
2017/04/28 18:40:52
I think this can be refactored. WDYT?
Raymond Toy
2017/04/28 19:55:14
Refactored how?
hongchan
2017/05/02 16:35:22
Something like this?
function checkStereoPannerNo
| |
77 channelCount: 1 | 51 should( |
78 }; | 52 () => { |
79 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 53 node = new StereoPannerNode(context, options); |
80 function () { | 54 }, |
81 node = new StereoPannerNode(context, options); | 55 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
82 }).notThrow() && success; | 56 .notThrow(); |
83 success = Should("node.channelCount", node.channelCount) | 57 should(node.channelCount, 'node.channelCount').beEqualTo(1); |
84 .beEqualTo(1) && success; | |
85 | 58 |
86 options = { | 59 options = {channelCount: 2}; |
87 channelCount: 2 | 60 should( |
88 }; | 61 () => { |
89 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 62 node = new StereoPannerNode(context, options); |
90 function () { | 63 }, |
91 node = new StereoPannerNode(context, options); | 64 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
92 }).notThrow() && success; | 65 .notThrow(); |
93 success = Should("node.channelCount", node.channelCount) | 66 should(node.channelCount, 'node.channelCount').beEqualTo(2); |
94 .beEqualTo(2) && success; | |
95 | 67 |
96 // Test that other channel counts throw an error | 68 // Test that other channel counts throw an error |
97 options = { | 69 options = {channelCount: 0}; |
98 channelCount: 0 | 70 should( |
99 }; | 71 () => { |
100 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 72 node = new StereoPannerNode(context, options); |
101 function () { | 73 }, |
102 node = new StereoPannerNode(context, options); | 74 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
103 }).throw("NotSupportedError") && success; | 75 .throw('NotSupportedError'); |
104 | 76 |
105 options = { | 77 options = {channelCount: 3}; |
106 channelCount: 3 | 78 should( |
107 }; | 79 () => { |
108 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 80 node = new StereoPannerNode(context, options); |
109 function () { | 81 }, |
110 node = new StereoPannerNode(context, options); | 82 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
111 }).throw("NotSupportedError") && success; | 83 .throw('NotSupportedError'); |
112 | 84 |
113 options = { | 85 options = {channelCount: 99}; |
114 channelCount: 99 | 86 should( |
115 }; | 87 () => { |
116 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 88 node = new StereoPannerNode(context, options); |
117 function () { | 89 }, |
118 node = new StereoPannerNode(context, options); | 90 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
119 }).throw("NotSupportedError") && success; | 91 .throw('NotSupportedError'); |
120 | 92 |
121 // Test channelCountMode. A mode of "max" is illegal, but others are | 93 // Test channelCountMode. A mode of "max" is illegal, but others are |
122 // ok. | 94 // ok. |
123 options = { | 95 options = {channelCountMode: 'clamped-max'}; |
124 channelCountMode: "clamped-max" | 96 should( |
125 }; | 97 () => { |
126 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 98 node = new StereoPannerNode(context, options); |
127 function () { | 99 }, |
128 node = new StereoPannerNode(context, options); | 100 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
129 }).notThrow() && success; | 101 .notThrow(); |
130 success = Should("node.channelCountMode", node.channelCountMode) | 102 should(node.channelCountMode, 'node.channelCountMode') |
131 .beEqualTo(options.channelCountMode) && success; | 103 .beEqualTo(options.channelCountMode); |
132 | 104 |
133 options = { | 105 options = {channelCountMode: 'explicit'}; |
134 channelCountMode: "explicit" | 106 should( |
135 }; | 107 () => { |
136 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 108 node = new StereoPannerNode(context, options); |
137 function () { | 109 }, |
138 node = new StereoPannerNode(context, options); | 110 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
139 }).notThrow() && success; | 111 .notThrow(); |
140 success = Should("node.channelCountMode", node.channelCountMode) | 112 should(node.channelCountMode, 'node.channelCountMode') |
141 .beEqualTo(options.channelCountMode) && success; | 113 .beEqualTo(options.channelCountMode); |
142 | 114 |
143 options = { | 115 options = {channelCountMode: 'max'}; |
144 channelCountMode: "max" | 116 should( |
145 }; | 117 () => { |
146 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 118 node = new StereoPannerNode(context, options); |
147 function () { | 119 }, |
148 node = new StereoPannerNode(context, options); | 120 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
149 }).throw("NotSupportedError") && success; | 121 .throw('NotSupportedError'); |
150 | 122 |
151 options = { | 123 options = {channelCountMode: 'foobar'}; |
152 channelCountMode: "foobar" | 124 should( |
153 }; | 125 () => { |
154 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 126 node = new StereoPannerNode(context, options); |
155 function () { | 127 }, |
156 node = new StereoPannerNode(context, options); | 128 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
157 }).throw("TypeError") && success; | 129 .throw('TypeError'); |
158 | 130 |
159 // Test channelInterpretation. | 131 // Test channelInterpretation. |
160 options = { | 132 options = {channelInterpretation: 'speakers'}; |
161 channelInterpretation: "speakers" | 133 should( |
162 }; | 134 () => { |
163 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 135 node = new StereoPannerNode(context, options); |
164 function () { | 136 }, |
165 node = new StereoPannerNode(context, options); | 137 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
166 }).notThrow() && success; | 138 .notThrow(); |
167 success = Should("node.channelInterpretation", node.channelInterpretatio n) | 139 should(node.channelInterpretation, 'node.channelInterpretation') |
168 .beEqualTo(options.channelInterpretation) && success; | 140 .beEqualTo(options.channelInterpretation); |
169 | 141 |
170 options = { | 142 options = {channelInterpretation: 'discrete'}; |
171 channelInterpretation: "discrete" | 143 should( |
172 }; | 144 () => { |
173 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 145 node = new StereoPannerNode(context, options); |
174 function () { | 146 }, |
175 node = new StereoPannerNode(context, options); | 147 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
176 }).notThrow() && success; | 148 .notThrow(); |
177 success = Should("node.channelInterpretation", node.channelInterpretatio n) | 149 should(node.channelInterpretation, 'node.channelInterpretation') |
178 .beEqualTo(options.channelInterpretation) && success; | 150 .beEqualTo(options.channelInterpretation); |
179 | 151 |
180 options = { | 152 options = {channelInterpretation: 'foobar'}; |
181 channelInterpretation: "foobar" | 153 should( |
182 }; | 154 () => { |
183 success = Should("new StereoPannerNode(c, " + JSON.stringify(options) + ")", | 155 node = new StereoPannerNode(context, options); |
184 function () { | 156 }, |
185 node = new StereoPannerNode(context, options); | 157 'new StereoPannerNode(c, ' + JSON.stringify(options) + ')') |
186 }).throw("TypeError") && success; | 158 .throw('TypeError'); |
187 | 159 |
188 Should("AudioNodeOptions for StereoPannerNode", success) | 160 task.done(); |
189 .summarize( | |
190 "were correctly handled", | |
191 "were not correctly handled"); | |
192 | |
193 taskDone(); | |
194 }); | 161 }); |
195 | 162 |
196 audit.defineTask("constructor with options", function (taskDone) { | 163 audit.define('constructor with options', (task, should) => { |
197 var node; | 164 var node; |
198 var success = true; | |
199 var options = { | 165 var options = { |
200 pan: 0.75, | 166 pan: 0.75, |
201 }; | 167 }; |
202 | 168 |
203 success = Should("node1 = new StereoPannerNode(, " + JSON.stringify(opti ons) + ")", | 169 should( |
204 function () { | 170 () => { |
205 node = new StereoPannerNode(context, options); | 171 node = new StereoPannerNode(context, options); |
206 }).notThrow(); | 172 }, |
207 success = Should("node1 instanceof StereoPannerNode", node instanceof St ereoPannerNode) | 173 'node1 = new StereoPannerNode(, ' + JSON.stringify(options) + ')') |
208 .beEqualTo(true) && success; | 174 .notThrow(); |
175 should( | |
176 node instanceof StereoPannerNode, | |
177 'node1 instanceof StereoPannerNode') | |
178 .beEqualTo(true); | |
209 | 179 |
210 success = Should("node1.pan.value", node.pan.value) | 180 should(node.pan.value, 'node1.pan.value').beEqualTo(options.pan); |
211 .beEqualTo(options.pan) && success; | |
212 | 181 |
213 Should("new StereoPannerNode() with options", success) | 182 task.done(); |
214 .summarize( | |
215 "constructed with correct attributes", | |
216 "was not constructed correctly"); | |
217 | |
218 taskDone(); | |
219 }); | 183 }); |
220 | 184 |
221 audit.runTasks(); | 185 audit.run(); |
222 </script> | 186 </script> |
223 </body> | 187 </body> |
224 </html> | 188 </html> |
OLD | NEW |