Chromium Code Reviews| 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(context, 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(context)", 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(context)", 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(context, ...)", 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(..., { fftSize: 33 })", functi on () { | |
| 119 node = new AnalyserNode(context, { | |
| 120 fftSize: 33 | |
| 121 }); | |
| 122 }).throw("IndexSizeError") && success; | |
| 123 success = Should("node = new AnalyserNode(..., { maxDecibels: -500 })", function () { | |
| 124 node = new AnalyserNode(context, { | |
| 125 maxDecibels: -500 | |
| 126 }); | |
| 127 }).throw("IndexSizeError") && success; | |
| 128 success = Should("node = new AnalyserNode(..., { minDecibels: -10 })", f unction () { | |
| 129 node = new AnalyserNode(context, { | |
| 130 minDecibels: -10 | |
| 131 }); | |
| 132 }).throw("IndexSizeError") && success; | |
| 133 success = Should("node = new AnalyserNode(..., { smoothingTimeConstant: 2 })", function () { | |
| 134 node = new AnalyserNode(context, { | |
| 135 smoothingTimeConstant: 2 | |
| 136 }); | |
| 137 }).throw("IndexSizeError") && success; | |
| 138 success = Should("node = new AnalyserNode(..., { 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 success = Should("node = new AnalyserNode(..., {minDecibels: -10, maxDec ibels: 20})", | |
|
hongchan
2016/09/13 22:13:22
var opts = { minDecibels: -10, maxDecibels: 20 };
Raymond Toy
2016/09/14 18:02:22
Done.
| |
| 162 function () { | |
| 163 node = new AnalyserNode(context, {minDecibels: -10, maxDecibels: 20} ); | |
| 164 }).notThrow() && success; | |
| 165 success = Should("node = new AnalyserNode(..., {maxDecibels: 20, minDeci bels: -10})", | |
| 166 function () { | |
| 167 node = new AnalyserNode(context, {maxDecibels: 20, minDecibels: -10} ); | |
| 168 }).notThrow() && success; | |
| 169 | |
| 170 success = Should("node = new AnalyserNode(..., {minDecibels: -200, maxDe cibels: -150})", | |
| 171 function () { | |
| 172 node = new AnalyserNode(context, {minDecibels: -200, maxDecibels: -1 50}); | |
| 173 }).notThrow() && success; | |
| 174 | |
| 175 success = Should("node = new AnalyserNode(..., {maxDecibels: -150, minDe cibels: -200})", | |
| 176 function () { | |
| 177 node = new AnalyserNode(context, {maxDecibels: -150, minDecibels: -2 00}); | |
| 178 }).notThrow() && success; | |
| 179 | |
| 180 // But these should signal because minDecibel > maxDecibel | |
| 181 success = Should("node = new AnalyserNode(..., {maxDecibels: -150, minD ecibels: -10})", | |
| 182 function () { | |
| 183 node = new AnalyserNode(context, {maxDecibels: -150, minDecibels: -1 0}); | |
| 184 }).throw("IndexSizeError") && success; | |
| 185 success = Should("node = new AnalyserNode(..., {minDecibels: -10, maxDe cibels: -150})", | |
| 186 function () { | |
| 187 node = new AnalyserNode(context, {minDecibels: -10, maxDecibels: -15 0}); | |
| 188 }).throw("IndexSizeError") && success; | |
| 189 | |
| 190 Should("new AnalyserNode with minDecibels/maxDecibels options values", s uccess) | |
| 191 .summarize( | |
| 192 "correctly handled", | |
| 193 "incorrectly handled"); | |
| 194 | |
| 195 taskDone(); | |
| 196 }); | |
| 197 audit.runTasks(); | |
| 198 </script> | |
| 199 </body> | |
| 200 </html> | |
| OLD | NEW |