OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Test Constructor: Panner</title> |
| 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> |
| 8 </head> |
| 9 |
| 10 <body> |
| 11 <script> |
| 12 var context; |
| 13 |
| 14 var audit = Audit.createTaskRunner(); |
| 15 |
| 16 audit.defineTask("initialize", function (taskDone) { |
| 17 Should("context = new OfflineAudioContext(...)", function () { |
| 18 context = new OfflineAudioContext(1, 1, 48000); |
| 19 }).notThrow(); |
| 20 |
| 21 taskDone(); |
| 22 }); |
| 23 |
| 24 audit.defineTask("invalid constructor", function (taskDone) { |
| 25 var node; |
| 26 var success = true; |
| 27 |
| 28 success = Should("new PannerNode()", function () { |
| 29 node = new PannerNode(); |
| 30 }).throw("TypeError"); |
| 31 success = Should("new PannerNode(1)", function () { |
| 32 node = new PannerNode(1) && success; |
| 33 }).throw("TypeError"); |
| 34 success = Should("new PannerNode(context, 42)", function () { |
| 35 node = new PannerNode(context, 42) && success; |
| 36 }).throw("TypeError"); |
| 37 |
| 38 Should("Invalid constructors", success) |
| 39 .summarize( |
| 40 "correctly threw errors", |
| 41 "did not throw errors in all cases"); |
| 42 |
| 43 taskDone(); |
| 44 }); |
| 45 |
| 46 audit.defineTask("default constructor", function (taskDone) { |
| 47 var node; |
| 48 var success = true; |
| 49 |
| 50 success = Should("node = new PannerNode(context)", function () { |
| 51 node = new PannerNode(context); |
| 52 }).notThrow(); |
| 53 success = Should("node instanceof PannerNode", node instanceof PannerNod
e) |
| 54 .beEqualTo(true) && success; |
| 55 |
| 56 success = Should("node.panningModel", node.panningModel) |
| 57 .beEqualTo("equalpower") && success; |
| 58 success = Should("node.positionX.value", node.positionX.value) |
| 59 .beEqualTo(0) && success; |
| 60 success = Should("node.positionY.value", node.positionY.value) |
| 61 .beEqualTo(0) && success; |
| 62 success = Should("node.positionZ.value", node.positionZ.value) |
| 63 .beEqualTo(0) && success; |
| 64 success = Should("node.orientationX.value", node.orientationX.value) |
| 65 .beEqualTo(1) && success; |
| 66 success = Should("node.orientationY.value", node.orientationY.value) |
| 67 .beEqualTo(0) && success; |
| 68 success = Should("node.orientationZ.value", node.orientationZ.value) |
| 69 .beEqualTo(0) && success; |
| 70 success = Should("node.distanceModel", node.distanceModel) |
| 71 .beEqualTo("inverse") && success; |
| 72 success = Should("node.refDistance", node.refDistance) |
| 73 .beEqualTo(1) && success; |
| 74 success = Should("node.maxDistance", node.maxDistance) |
| 75 .beEqualTo(10000) && success; |
| 76 success = Should("node.rolloffFactor", node.rolloffFactor) |
| 77 .beEqualTo(1) && success; |
| 78 success = Should("node.coneInnerAngle", node.coneInnerAngle) |
| 79 .beEqualTo(360) && success; |
| 80 success = Should("node.coneOuterAngle", node.coneOuterAngle) |
| 81 .beEqualTo(360) && success; |
| 82 success = Should("node.coneOuterGain", node.coneOuterGain) |
| 83 .beEqualTo(0) && success; |
| 84 |
| 85 // Test the listener too, while we're at it. |
| 86 success = Should("context.listener.positionX.value", context.listener.po
sitionX.value) |
| 87 .beEqualTo(0) && success; |
| 88 success = Should("context.listener.positionY.value", context.listener.po
sitionY.value) |
| 89 .beEqualTo(0) && success; |
| 90 success = Should("context.listener.positionZ.value", context.listener.po
sitionZ.value) |
| 91 .beEqualTo(0) && success; |
| 92 success = Should("context.listener.forwardX.value", context.listener.for
wardX.value) |
| 93 .beEqualTo(0) && success; |
| 94 success = Should("context.listener.forwardY.value", context.listener.for
wardY.value) |
| 95 .beEqualTo(0) && success; |
| 96 success = Should("context.listener.forwardZ.value", context.listener.for
wardZ.value) |
| 97 .beEqualTo(-1) && success; |
| 98 success = Should("context.listener.upX.value", context.listener.upX.valu
e) |
| 99 .beEqualTo(0) && success; |
| 100 success = Should("context.listener.upY.value", context.listener.upY.valu
e) |
| 101 .beEqualTo(1) && success; |
| 102 success = Should("context.listener.upZ.value", context.listener.upZ.valu
e) |
| 103 .beEqualTo(0) && success; |
| 104 |
| 105 success = Should("node.channelCount", node.channelCount) |
| 106 .beEqualTo(2) && success; |
| 107 success = Should("node.channelCountMode", node.channelCountMode) |
| 108 .beEqualTo("clamped-max") && success; |
| 109 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 110 .beEqualTo("speakers") && success; |
| 111 |
| 112 Should("new PannerNode(context)", success) |
| 113 .summarize( |
| 114 "constructed node with correct attributes", |
| 115 "did not construct correct node correctly") |
| 116 |
| 117 taskDone(); |
| 118 }); |
| 119 |
| 120 audit.defineTask("test AudioNodeOptions", function (taskDone) { |
| 121 // Can't use testAudioNodeOptions because the constraints for this node |
| 122 // are not supported there. |
| 123 var node; |
| 124 var success = true; |
| 125 |
| 126 // Test that we can set the channel count to 1 or 2. |
| 127 var options = { |
| 128 channelCount: 1 |
| 129 }; |
| 130 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 131 function () { |
| 132 node = new PannerNode(context, options); |
| 133 }).notThrow() && success; |
| 134 success = Should("node.channelCount", node.channelCount) |
| 135 .beEqualTo(options.channelCount) && success; |
| 136 |
| 137 options = { |
| 138 channelCount: 2 |
| 139 }; |
| 140 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 141 function () { |
| 142 node = new PannerNode(context, options); |
| 143 }).notThrow() && success; |
| 144 success = Should("node.channelCount", node.channelCount) |
| 145 .beEqualTo(options.channelCount) && success; |
| 146 |
| 147 // Test that other channel counts throw an error |
| 148 options = { |
| 149 channelCount: 0 |
| 150 }; |
| 151 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 152 function () { |
| 153 node = new PannerNode(context, options); |
| 154 }).throw("NotSupportedError") && success; |
| 155 |
| 156 options = { |
| 157 channelCount: 3 |
| 158 }; |
| 159 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 160 function () { |
| 161 node = new PannerNode(context, options); |
| 162 }).throw("NotSupportedError") && success; |
| 163 |
| 164 options = { |
| 165 channelCount: 99 |
| 166 }; |
| 167 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 168 function () { |
| 169 node = new PannerNode(context, options); |
| 170 }).throw("NotSupportedError") && success; |
| 171 |
| 172 // Test channelCountMode. A mode of "max" is illegal, but others are |
| 173 // ok. |
| 174 options = { |
| 175 channelCountMode: "clamped-max" |
| 176 }; |
| 177 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 178 function () { |
| 179 node = new PannerNode(context, options); |
| 180 }).notThrow() && success; |
| 181 success = Should("node.channelCountMode", node.channelCountMode) |
| 182 .beEqualTo(options.channelCountMode) && success; |
| 183 |
| 184 options = { |
| 185 channelCountMode: "explicit" |
| 186 }; |
| 187 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 188 function () { |
| 189 node = new PannerNode(context, options); |
| 190 }).notThrow() && success; |
| 191 success = Should("node.channelCountMode", node.channelCountMode) |
| 192 .beEqualTo(options.channelCountMode); |
| 193 |
| 194 options = { |
| 195 channelCountMode: "max" |
| 196 }; |
| 197 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 198 function () { |
| 199 node = new PannerNode(context, options); |
| 200 }).throw("NotSupportedError") && success; |
| 201 |
| 202 options = { |
| 203 channelCountMode: "foobar" |
| 204 }; |
| 205 success = Should('new PannerNode(c, " + JSON.stringify(options) + ")', |
| 206 function () { |
| 207 node = new PannerNode(context, options); |
| 208 }).throw("TypeError") && success; |
| 209 |
| 210 // Test channelInterpretation. |
| 211 options = { |
| 212 channelInterpretation: "speakers" |
| 213 }; |
| 214 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 215 function () { |
| 216 node = new PannerNode(context, options); |
| 217 }).notThrow() && success; |
| 218 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 219 .beEqualTo(options.channelInterpretation) && success; |
| 220 |
| 221 options = { |
| 222 channelInterpretation: "discrete" |
| 223 }; |
| 224 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 225 function () { |
| 226 node = new PannerNode(context, options); |
| 227 }).notThrow() && success; |
| 228 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 229 .beEqualTo(options.channelInterpretation) && success; |
| 230 |
| 231 options = { |
| 232 channelInterpretation: "foobar" |
| 233 }; |
| 234 success = Should("new PannerNode(c, " + JSON.stringify(options) + ")", |
| 235 function () { |
| 236 node = new PannerNode(context, options); |
| 237 }).throw("TypeError") && success; |
| 238 |
| 239 Should("AudioNodeOptions for PannerNode", success) |
| 240 .summarize( |
| 241 "were correctly handled", |
| 242 "were not correctly handled"); |
| 243 |
| 244 taskDone(); |
| 245 }); |
| 246 |
| 247 audit.defineTask("constructor with options", function (taskDone) { |
| 248 var node; |
| 249 var success = true; |
| 250 var options = { |
| 251 panningModel: "HRTF", |
| 252 positionX: 3, |
| 253 positionY: 4, |
| 254 positionZ: 5, |
| 255 orientationX: -3, |
| 256 orientationY: -4, |
| 257 orientationZ: -5, |
| 258 distanceModel: "linear", |
| 259 refDistance: 42, |
| 260 maxDistance: 99, |
| 261 rolloffFactor: .25, |
| 262 coneInnerAngle: 10, |
| 263 coneOuterAngle: 50, |
| 264 coneOuterGain: .25 |
| 265 }; |
| 266 |
| 267 success = Should("node = new PannerNode(c, " + JSON.stringify(options) +
")", function () { |
| 268 node = new PannerNode(context, options); |
| 269 }).notThrow(); |
| 270 success = Should("node instanceof PannerNode", node instanceof PannerNod
e) |
| 271 .beEqualTo(true) && success; |
| 272 |
| 273 success = Should("node.panningModel", node.panningModel) |
| 274 .beEqualTo(options.panningModel) && success; |
| 275 success = Should("node.positionX.value", node.positionX.value) |
| 276 .beEqualTo(options.positionX) && success; |
| 277 success = Should("node.positionY.value", node.positionY.value) |
| 278 .beEqualTo(options.positionY) && success; |
| 279 success = Should("node.positionZ.value", node.positionZ.value) |
| 280 .beEqualTo(options.positionZ) && success; |
| 281 success = Should("node.orientationX.value", node.orientationX.value) |
| 282 .beEqualTo(options.orientationX) && success; |
| 283 success = Should("node.orientationY.value", node.orientationY.value) |
| 284 .beEqualTo(options.orientationY) && success; |
| 285 success = Should("node.orientationZ.value", node.orientationZ.value) |
| 286 .beEqualTo(options.orientationZ) && success; |
| 287 success = Should("node.distanceModel", node.distanceModel) |
| 288 .beEqualTo(options.distanceModel) && success; |
| 289 success = Should("node.refDistance", node.refDistance) |
| 290 .beEqualTo(options.refDistance) && success; |
| 291 success = Should("node.maxDistance", node.maxDistance) |
| 292 .beEqualTo(options.maxDistance) && success; |
| 293 success = Should("node.rolloffFactor", node.rolloffFactor) |
| 294 .beEqualTo(options.rolloffFactor) && success; |
| 295 success = Should("node.coneInnerAngle", node.coneInnerAngle) |
| 296 .beEqualTo(options.coneInnerAngle) && success; |
| 297 success = Should("node.coneOuterAngle", node.coneOuterAngle) |
| 298 .beEqualTo(options.coneOuterAngle) && success; |
| 299 success = Should("node.coneOuterGain", node.coneOuterGain) |
| 300 .beEqualTo(options.coneOuterGain) && success; |
| 301 |
| 302 success = Should("node.channelCount", node.channelCount) |
| 303 .beEqualTo(2) && success; |
| 304 success = Should("node.channelCountMode", node.channelCountMode) |
| 305 .beEqualTo("clamped-max") && success; |
| 306 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 307 .beEqualTo("speakers") && success; |
| 308 |
| 309 Should("new PannerNode() with options", success) |
| 310 .summarize( |
| 311 "constructed with correct attributes", |
| 312 "was not constructed correctly"); |
| 313 |
| 314 taskDone(); |
| 315 }); |
| 316 |
| 317 audit.runTasks(); |
| 318 </script> |
| 319 </body> |
| 320 </html> |
OLD | NEW |