OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test Clamping of Distance for PannerNode</title> | 4 <title>Test Clamping of Distance for PannerNode</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/audio-testing.js"></script> |
9 </head> | 9 </head> |
10 | 10 |
11 <body> | 11 <body> |
12 <script> | 12 <script> |
13 // Arbitrary sample rate and render length. | 13 // Arbitrary sample rate and render length. |
14 var sampleRate = 48000; | 14 var sampleRate = 48000; |
15 var renderFrames = 128; | 15 var renderFrames = 128; |
16 | 16 |
17 var audit = Audit.createTaskRunner(); | 17 var audit = Audit.createTaskRunner(); |
18 | 18 |
19 audit.defineTask("ref-distance-error", function (taskDone) { | 19 audit.defineTask("ref-distance-error", function (taskDone) { |
20 testDistanceLimits({name: "refDistance"}); | 20 testDistanceLimits({name: "refDistance", isZeroAllowed: true}); |
21 taskDone(); | 21 taskDone(); |
22 }); | 22 }); |
23 | 23 |
24 audit.defineTask("max-distance-error", function (taskDone) { | 24 audit.defineTask("max-distance-error", function (taskDone) { |
25 testDistanceLimits({name: "maxDistance"}); | 25 testDistanceLimits({name: "maxDistance", isZeroAllowed: false}); |
26 taskDone(); | 26 taskDone(); |
27 }); | 27 }); |
28 | 28 |
29 function testDistanceLimits(options) { | 29 function testDistanceLimits(options) { |
30 // Verify that exceptions are thrown for invalid values of refDistance. | 30 // Verify that exceptions are thrown for invalid values of refDistance. |
31 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 31 var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
32 | 32 |
33 var attrName = options.name; | 33 var attrName = options.name; |
34 var prefix = "new PannerNode(c, {" + attrName + ": "; | 34 var prefix = "new PannerNode(c, {" + attrName + ": "; |
35 | 35 |
36 success = Should(prefix + "-1})", function () { | 36 success = Should(prefix + "-1})", function () { |
37 var nodeOptions = {}; | 37 var nodeOptions = {}; |
38 nodeOptions[attrName] = -1; | 38 nodeOptions[attrName] = -1; |
39 new PannerNode(context, nodeOptions); | 39 new PannerNode(context, nodeOptions); |
40 }).throw("RangeError"); | 40 }).throw("RangeError"); |
41 | 41 |
42 success = Should(prefix + "0})", function () { | 42 if (options.isZeroAllowed) { |
43 var nodeOptions = {}; | 43 success = Should(prefix + "0})", function () { |
44 nodeOptions[attrName] = 0; | 44 var nodeOptions = {}; |
45 new PannerNode(context, nodeOptions); | 45 nodeOptions[attrName] = 0; |
46 }).throw("RangeError") && success; | 46 new PannerNode(context, nodeOptions); |
| 47 }).notThrow() && success; |
| 48 } else { |
| 49 success = Should(prefix + "0})", function () { |
| 50 var nodeOptions = {}; |
| 51 nodeOptions[attrName] = 0; |
| 52 new PannerNode(context, nodeOptions); |
| 53 }).throw("RangeError") && success; |
| 54 } |
47 | 55 |
48 // The smallest representable positive single float. | 56 // The smallest representable positive single float. |
49 var leastPositiveDoubleFloat = 4.9406564584124654e-324; | 57 var leastPositiveDoubleFloat = 4.9406564584124654e-324; |
50 | 58 |
51 success = Should(prefix + leastPositiveDoubleFloat + "})", | 59 success = Should(prefix + leastPositiveDoubleFloat + "})", |
52 function () { | 60 function () { |
53 var nodeOptions = {}; | 61 var nodeOptions = {}; |
54 nodeOptions[attrName] = leastPositiveDoubleFloat; | 62 nodeOptions[attrName] = leastPositiveDoubleFloat; |
55 new PannerNode(context, nodeOptions); | 63 new PannerNode(context, nodeOptions); |
56 }).notThrow() && success; | 64 }).notThrow() && success; |
57 | 65 |
58 prefix = "panner." + attrName + " = "; | 66 prefix = "panner." + attrName + " = "; |
59 panner = new PannerNode(context); | 67 panner = new PannerNode(context); |
60 success = Should(prefix + "-1", function () { | 68 success = Should(prefix + "-1", function () { |
61 panner[attrName] = -1; | 69 panner[attrName] = -1; |
62 }).throw("RangeError") && success; | 70 }).throw("RangeError") && success; |
63 | 71 |
64 success = Should(prefix + "0", function () { | 72 if (options.isZeroAllowed) { |
65 panner[attrName] = 0; | 73 success = Should(prefix + "0", function () { |
66 }).throw("RangeError") && success; | 74 panner[attrName] = 0; |
| 75 }).notThrow() && success; |
| 76 } else { |
| 77 success = Should(prefix + "0", function () { |
| 78 panner[attrName] = 0; |
| 79 }).throw("RangeError") && success; |
| 80 } |
67 | 81 |
68 success = Should(prefix + leastPositiveDoubleFloat, function () { | 82 success = Should(prefix + leastPositiveDoubleFloat, function () { |
69 panner[attrName] = leastPositiveDoubleFloat; | 83 panner[attrName] = leastPositiveDoubleFloat; |
70 }).notThrow() && success; | 84 }).notThrow() && success; |
71 | 85 |
72 Should("Invalid " + attrName + " values handled", success) | 86 Should("Invalid " + attrName + " values handled", success) |
73 .summarize("correctly", "incorrectly"); | 87 .summarize("correctly", "incorrectly"); |
74 | 88 |
75 } | 89 } |
76 | 90 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 .beEqualTo(true); | 218 .beEqualTo(true); |
205 Should("Test panner output " + JSON.stringify(options), actual) | 219 Should("Test panner output " + JSON.stringify(options), actual) |
206 .beEqualToArray(expected); | 220 .beEqualToArray(expected); |
207 }); | 221 }); |
208 } | 222 } |
209 | 223 |
210 audit.runTasks(); | 224 audit.runTasks(); |
211 </script> | 225 </script> |
212 </body> | 226 </body> |
213 </html> | 227 </html> |
OLD | NEW |