OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Test Constructor: AnalyserNode</title> |
| 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> |
| 8 <script src="audionodeoptions.js"></script> |
| 9 </head> |
| 10 |
| 11 <body> |
| 12 <script> |
| 13 var context; |
| 14 |
| 15 var audit = Audit.createTaskRunner(); |
| 16 |
| 17 audit.defineTask("initialize", function (taskDone) { |
| 18 Should("context = new OfflineAudioContext(...)", function () { |
| 19 context = new OfflineAudioContext(1, 1, 48000); |
| 20 }).notThrow(); |
| 21 |
| 22 taskDone(); |
| 23 }); |
| 24 |
| 25 audit.defineTask("invalid constructor", function (taskDone) { |
| 26 var node; |
| 27 var success = true; |
| 28 |
| 29 success = Should("new AnalyserNode()", function () { |
| 30 node = new AnalyserNode(); |
| 31 }).throw("TypeError"); |
| 32 success = Should("new AnalyserNode(1)", function () { |
| 33 node = new AnalyserNode(1) && success; |
| 34 }).throw("TypeError"); |
| 35 success = Should("new AnalyserNode(c, 42)", function () { |
| 36 node = new AnalyserNode(context, 42) && success; |
| 37 }).throw("TypeError"); |
| 38 |
| 39 Should("Invalid constructors", success) |
| 40 .summarize( |
| 41 "correctly threw errors", |
| 42 "did not throw errors in all cases"); |
| 43 |
| 44 taskDone(); |
| 45 }); |
| 46 |
| 47 audit.defineTask("default constructor", function (taskDone) { |
| 48 var node; |
| 49 var success = true; |
| 50 |
| 51 success = Should("node = new AnalyserNode(c)", function () { |
| 52 node = new AnalyserNode(context); |
| 53 }).notThrow(); |
| 54 success = Should("node instanceof AnalyserNode", node instanceof Analyse
rNode) |
| 55 .beEqualTo(true) && success; |
| 56 success = Should("node.fftSize", node.fftSize).beEqualTo(2048) && succes
s; |
| 57 success = Should("node.frequencyBinCount", |
| 58 node.frequencyBinCount).beEqualTo(1024) && success; |
| 59 success = Should("node.minDecibels", node.minDecibels).beEqualTo(-100) &
& success; |
| 60 success = Should("node.maxDecibels", node.maxDecibels).beEqualTo(-30) &&
success; |
| 61 // All AudioParams are stored as single precision values. Compare |
| 62 // against the single-precision float value. |
| 63 success = Should("node.smoothingTimeConstant", node.smoothingTimeConstan
t) |
| 64 .beEqualTo(Math.fround(0.8)) && success; |
| 65 |
| 66 Should("new AnalyserNode(c)", success) |
| 67 .summarize( |
| 68 "constructed node with correct attributes", |
| 69 "did not construct correct node correctly") |
| 70 |
| 71 taskDone(); |
| 72 }); |
| 73 |
| 74 audit.defineTask("test AudioNodeOptions", function (taskDone) { |
| 75 testAudioNodeOptions(context, "AnalyserNode"); |
| 76 taskDone(); |
| 77 }); |
| 78 |
| 79 audit.defineTask("constructor with options", function (taskDone) { |
| 80 var options = { |
| 81 fftSize: 32, |
| 82 maxDecibels: 1, |
| 83 minDecibels: -13, |
| 84 // Choose a value that can be represented the same as a float and as a |
| 85 // double. |
| 86 smoothingTimeConstant: 0.125 |
| 87 }; |
| 88 |
| 89 var node; |
| 90 var success = true; |
| 91 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", function () { |
| 92 node = new AnalyserNode(context, options); |
| 93 }).notThrow(); |
| 94 |
| 95 success = Should("node instanceof AnalyserNode", node instanceof Analyse
rNode) |
| 96 .beEqualTo(true) && success; |
| 97 success = Should("node.fftSize", node.fftSize) |
| 98 .beEqualTo(options.fftSize) && success; |
| 99 success = Should("node.maxDecibels", node.maxDecibels) |
| 100 .beEqualTo(options.maxDecibels) && success; |
| 101 success = Should("node.minDecibels", node.minDecibels) |
| 102 .beEqualTo(options.minDecibels) && success; |
| 103 success = Should("node.smoothingTimeConstant", node.smoothingTimeConstan
t) |
| 104 .beEqualTo(options.smoothingTimeConstant) && success; |
| 105 |
| 106 Should("new AnalyserNode() with options", success) |
| 107 .summarize( |
| 108 "constructed with correct attributes", |
| 109 "was not constructed correctly"); |
| 110 |
| 111 taskDone(); |
| 112 }); |
| 113 |
| 114 audit.defineTask("construct invalid options", function (taskDone) { |
| 115 var node; |
| 116 var success = true; |
| 117 |
| 118 success = Should("node = new AnalyserNode(c, { fftSize: 33 })", function
() { |
| 119 node = new AnalyserNode(context, { |
| 120 fftSize: 33 |
| 121 }); |
| 122 }).throw("IndexSizeError") && success; |
| 123 success = Should("node = new AnalyserNode(c, { maxDecibels: -500 })", fu
nction () { |
| 124 node = new AnalyserNode(context, { |
| 125 maxDecibels: -500 |
| 126 }); |
| 127 }).throw("IndexSizeError") && success; |
| 128 success = Should("node = new AnalyserNode(c, { minDecibels: -10 })", fun
ction () { |
| 129 node = new AnalyserNode(context, { |
| 130 minDecibels: -10 |
| 131 }); |
| 132 }).throw("IndexSizeError") && success; |
| 133 success = Should("node = new AnalyserNode(c, { smoothingTimeConstant: 2
})", function () { |
| 134 node = new AnalyserNode(context, { |
| 135 smoothingTimeConstant: 2 |
| 136 }); |
| 137 }).throw("IndexSizeError") && success; |
| 138 success = Should("node = new AnalyserNode(c, { frequencyBinCount: 33 })"
, function () { |
| 139 node = new AnalyserNode(context, { |
| 140 frequencyBinCount: 33 |
| 141 }); |
| 142 }).notThrow() && success; |
| 143 success = Should("node.frequencyBinCount", node.frequencyBinCount).beEqu
alTo(1024) && |
| 144 success; |
| 145 |
| 146 Should("new AnalyserNode() with invalid option values", success) |
| 147 .summarize( |
| 148 "correctly handled", |
| 149 "was not correctly handled"); |
| 150 |
| 151 taskDone(); |
| 152 }); |
| 153 |
| 154 audit.defineTask("setting min/max", function (taskDone) { |
| 155 var node; |
| 156 var success = true; |
| 157 |
| 158 // Recall the default values of minDecibels and maxDecibels are -100, |
| 159 // and -30, respectively. Setting both values in the constructor should |
| 160 // not signal an error in any of the following cases. |
| 161 var options = { |
| 162 minDecibels: -10, |
| 163 maxDecibels: 20 |
| 164 }; |
| 165 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 166 function () { |
| 167 node = new AnalyserNode(context, options); |
| 168 }).notThrow() && success; |
| 169 |
| 170 options = { |
| 171 maxDecibels: 20, |
| 172 minDecibels: -10 |
| 173 }; |
| 174 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 175 function () { |
| 176 node = new AnalyserNode(context, options); |
| 177 }).notThrow() && success; |
| 178 |
| 179 options = { |
| 180 minDecibels: -200, |
| 181 maxDecibels: -150 |
| 182 }; |
| 183 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 184 function () { |
| 185 node = new AnalyserNode(context, options); |
| 186 }).notThrow() && success; |
| 187 |
| 188 options = { |
| 189 maxDecibels: -150, |
| 190 minDecibels: -200 |
| 191 }; |
| 192 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 193 function () { |
| 194 node = new AnalyserNode(context, options); |
| 195 }).notThrow() && success; |
| 196 |
| 197 // But these should signal because minDecibel > maxDecibel |
| 198 options = { |
| 199 maxDecibels: -150, |
| 200 minDecibels: -10 |
| 201 }; |
| 202 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 203 function () { |
| 204 node = new AnalyserNode(context, options); |
| 205 }).throw("IndexSizeError") && success; |
| 206 |
| 207 options = { |
| 208 minDecibels: -10, |
| 209 maxDecibels: -150 |
| 210 }; |
| 211 success = Should("node = new AnalyserNode(c, " + JSON.stringify(options)
+ ")", |
| 212 function () { |
| 213 node = new AnalyserNode(context, options); |
| 214 }).throw("IndexSizeError") && success; |
| 215 |
| 216 Should("new AnalyserNode with minDecibels/maxDecibels options values", s
uccess) |
| 217 .summarize( |
| 218 "correctly handled", |
| 219 "incorrectly handled"); |
| 220 |
| 221 taskDone(); |
| 222 }); |
| 223 audit.runTasks(); |
| 224 </script> |
| 225 </body> |
| 226 </html> |
OLD | NEW |