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 success = Should("new PannerNode(c, {channelCount: 1})", |
| 128 function () { |
| 129 node = new PannerNode(context, { |
| 130 channelCount: 1 |
| 131 }); |
| 132 }).notThrow() && success; |
| 133 success = Should("node.channelCount", node.channelCount) |
| 134 .beEqualTo(1) && success; |
| 135 |
| 136 success = Should("new PannerNode(c, {channelCount: 2})", |
| 137 function () { |
| 138 node = new PannerNode(context, { |
| 139 channelCount: 2 |
| 140 }); |
| 141 }).notThrow() && success; |
| 142 success = Should("node.channelCount", node.channelCount) |
| 143 .beEqualTo(2) && success; |
| 144 |
| 145 // Test that other channel counts throw an error |
| 146 success = Should("new PannerNode(c, {channelCount: 0})", |
| 147 function () { |
| 148 node = new PannerNode(context, { |
| 149 channelCount: 0 |
| 150 }); |
| 151 }).throw("NotSupportedError") && success; |
| 152 success = Should("new PannerNode(c, {channelCount: 3})", |
| 153 function () { |
| 154 node = new PannerNode(context, { |
| 155 channelCount: 3 |
| 156 }); |
| 157 }).throw("NotSupportedError") && success; |
| 158 success = Should("new PannerNode(c, {channelCount: 99})", |
| 159 function () { |
| 160 node = new PannerNode(context, { |
| 161 channelCount: 99 |
| 162 }); |
| 163 }).throw("NotSupportedError") && success; |
| 164 |
| 165 // Test channelCountMode. A mode of "max" is illegal, but others are ok
. |
| 166 success = Should('new PannerNode(c, {channelCountMode: "clamped-max"})', |
| 167 function () { |
| 168 node = new PannerNode(context, { |
| 169 channelCountMode: "clamped-max" |
| 170 }); |
| 171 }).notThrow() && success; |
| 172 success = Should("node.channelCountMode", node.channelCountMode) |
| 173 .beEqualTo("clamped-max") && success; |
| 174 |
| 175 success = Should('new PannerNode(c, {channelCountMode: "explicit"})', |
| 176 function () { |
| 177 node = new PannerNode(context, { |
| 178 channelCountMode: "explicit" |
| 179 }); |
| 180 }).notThrow() && success; |
| 181 success = Should("node.channelCountMode", node.channelCountMode) |
| 182 .beEqualTo("explicit") && success; |
| 183 |
| 184 success = Should('new PannerNode(c, {channelCountMode: "max"})', |
| 185 function () { |
| 186 node = new PannerNode(context, { |
| 187 channelCountMode: "max" |
| 188 }); |
| 189 }).throw("NotSupportedError") && success; |
| 190 success = Should('new PannerNode(c, {channelCountMode: "foobar"})', |
| 191 function () { |
| 192 node = new PannerNode(context, { |
| 193 channelCountMode: "foobar" |
| 194 }); |
| 195 }).throw("NotSupportedError") && success; |
| 196 |
| 197 // Test channelInterpretation. |
| 198 success = Should('new PannerNode(c, {channelInterpretation: "speakers"})
', |
| 199 function () { |
| 200 node = new PannerNode(context, { |
| 201 channelInterpretation: "speakers" |
| 202 }); |
| 203 }).notThrow() && success; |
| 204 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 205 .beEqualTo("speakers") && success; |
| 206 success = Should('new PannerNode(c, {channelInterpretation: "discrete"})
', |
| 207 function () { |
| 208 node = new PannerNode(context, { |
| 209 channelInterpretation: "discrete" |
| 210 }); |
| 211 }).notThrow() && success; |
| 212 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 213 .beEqualTo("discrete") && success; |
| 214 success = Should('new PannerNode(c, {channelInterpretation: "foobar"})', |
| 215 function () { |
| 216 node = new PannerNode(context, { |
| 217 channelInterpretation: "foobar" |
| 218 }); |
| 219 }).throw("NotSupportedError") && success; |
| 220 |
| 221 Should("AudioNodeOptions for PannerNode", success) |
| 222 .summarize( |
| 223 "were correctly handled", |
| 224 "were not correctly handled"); |
| 225 |
| 226 taskDone(); |
| 227 }); |
| 228 |
| 229 audit.defineTask("constructor with options", function (taskDone) { |
| 230 var node; |
| 231 var success = true; |
| 232 var options = { |
| 233 panningModel: "HRTF", |
| 234 positionX: 3, |
| 235 positionY: 4, |
| 236 positionZ: 5, |
| 237 orientationX: -3, |
| 238 orientationY: -4, |
| 239 orientationZ: -5, |
| 240 distanceModel: "linear", |
| 241 refDistance: 42, |
| 242 maxDistance: 99, |
| 243 rolloffFactor: .25, |
| 244 coneInnerAngle: 10, |
| 245 coneOuterAngle: 50, |
| 246 coneOuterGain: .25 |
| 247 }; |
| 248 |
| 249 success = Should("node = new PannerNode(context, <options>)", function (
) { |
| 250 node = new PannerNode(context, options); |
| 251 }).notThrow(); |
| 252 success = Should("node instanceof PannerNode", node instanceof PannerNod
e) |
| 253 .beEqualTo(true) && success; |
| 254 |
| 255 success = Should("node.panningModel", node.panningModel) |
| 256 .beEqualTo(options.panningModel) && success; |
| 257 success = Should("node.positionX.value", node.positionX.value) |
| 258 .beEqualTo(options.positionX) && success; |
| 259 success = Should("node.positionY.value", node.positionY.value) |
| 260 .beEqualTo(options.positionY) && success; |
| 261 success = Should("node.positionZ.value", node.positionZ.value) |
| 262 .beEqualTo(options.positionZ) && success; |
| 263 success = Should("node.orientationX.value", node.orientationX.value) |
| 264 .beEqualTo(options.orientationX) && success; |
| 265 success = Should("node.orientationY.value", node.orientationY.value) |
| 266 .beEqualTo(options.orientationY) && success; |
| 267 success = Should("node.orientationZ.value", node.orientationZ.value) |
| 268 .beEqualTo(options.orientationZ) && success; |
| 269 success = Should("node.distanceModel", node.distanceModel) |
| 270 .beEqualTo(options.distanceModel) && success; |
| 271 success = Should("node.refDistance", node.refDistance) |
| 272 .beEqualTo(options.refDistance) && success; |
| 273 success = Should("node.maxDistance", node.maxDistance) |
| 274 .beEqualTo(options.maxDistance) && success; |
| 275 success = Should("node.rolloffFactor", node.rolloffFactor) |
| 276 .beEqualTo(options.rolloffFactor) && success; |
| 277 success = Should("node.coneInnerAngle", node.coneInnerAngle) |
| 278 .beEqualTo(options.coneInnerAngle) && success; |
| 279 success = Should("node.coneOuterAngle", node.coneOuterAngle) |
| 280 .beEqualTo(options.coneOuterAngle) && success; |
| 281 success = Should("node.coneOuterGain", node.coneOuterGain) |
| 282 .beEqualTo(options.coneOuterGain) && success; |
| 283 |
| 284 success = Should("node.channelCount", node.channelCount) |
| 285 .beEqualTo(2) && success; |
| 286 success = Should("node.channelCountMode", node.channelCountMode) |
| 287 .beEqualTo("clamped-max") && success; |
| 288 success = Should("node.channelInterpretation", node.channelInterpretatio
n) |
| 289 .beEqualTo("speakers") && success; |
| 290 |
| 291 Should("new PannerNode() with options", success) |
| 292 .summarize( |
| 293 "constructed with correct attributes", |
| 294 "was not constructed correctly"); |
| 295 |
| 296 taskDone(); |
| 297 }); |
| 298 |
| 299 audit.runTasks(); |
| 300 </script> |
| 301 </body> |
| 302 </html> |
OLD | NEW |