OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Test Constructor: AudioBuffer</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 AudioBuffer()", function () { |
| 29 node = new AudioBuffer(); |
| 30 }).throw("TypeError"); |
| 31 success = Should("new AudioBuffer(1)", function () { |
| 32 node = new AudioBuffer(1) && success; |
| 33 }).throw("TypeError"); |
| 34 success = Should("new AudioBuffer(context, 42)", function () { |
| 35 node = new AudioBuffer(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("required options", function (taskDone) { |
| 47 var success = true; |
| 48 |
| 49 success = Should("new AudioBuffer(context, {})", function () { |
| 50 var buffer = new AudioBuffer(context, {}); |
| 51 }).throw("NotFoundError"); |
| 52 |
| 53 success = Should("new AudioBuffer(context, {numberOfChannels: 1}", |
| 54 function () { |
| 55 var buffer = new AudioBuffer(context, { |
| 56 numberOfChannels: 1 |
| 57 }); |
| 58 }).throw("NotFoundError") && success; |
| 59 |
| 60 // The sampleRate isn't required, but numberOfChannels and length are. |
| 61 success = Should( |
| 62 "new AudioBuffer(context, {numberOfChannels: 1, length: 1}", |
| 63 function () { |
| 64 var buffer = new AudioBuffer(context, { |
| 65 numberOfChannels: 1, |
| 66 length: 1 |
| 67 }); |
| 68 }).notThrow() && success; |
| 69 |
| 70 success = Should( |
| 71 "new AudioBuffer(context, {numberOfChannels: 1, length: 1, sampleRate:
48000}", |
| 72 function () { |
| 73 var buffer = new AudioBuffer(context, { |
| 74 numberOfChannels: 1, |
| 75 length: 1, |
| 76 sampleRate: 48000 |
| 77 }); |
| 78 }).notThrow() && success; |
| 79 |
| 80 Should("Missing option values handled", success) |
| 81 .summarize("correctly", "incorrectly"); |
| 82 |
| 83 taskDone(); |
| 84 }); |
| 85 |
| 86 audit.defineTask("invalid option values", function (taskDone) { |
| 87 var success = true; |
| 88 |
| 89 var options = { |
| 90 numberOfChannels: 0, |
| 91 length: 1 |
| 92 }; |
| 93 success = Should("new AudioBuffer(c, " + JSON.stringify(options) + ")",
function () { |
| 94 var buffer = new AudioBuffer(context, options); |
| 95 }).throw("NotSupportedError"); |
| 96 |
| 97 options = { |
| 98 numberOfChannels: 99, |
| 99 length: 0 |
| 100 }; |
| 101 success = Should("new AudioBuffer(c, " + JSON.stringify(options) + ")",
function () { |
| 102 var buffer = new AudioBuffer(context, options); |
| 103 }).throw("NotSupportedError") && success; |
| 104 |
| 105 options = { |
| 106 numberOfChannels: 1, |
| 107 length: 0 |
| 108 }; |
| 109 success = Should("new AudioBuffer(c, " + JSON.stringify(options) + ")",
function () { |
| 110 var buffer = new AudioBuffer(context, options); |
| 111 }).throw("NotSupportedError") && success; |
| 112 |
| 113 options = { |
| 114 numberOfChannels: 1, |
| 115 length: 1, |
| 116 sampleRate: 100 |
| 117 }; |
| 118 success = Should("new AudioBuffer(c, " + JSON.stringify(options) + ")",
function () { |
| 119 var buffer = new AudioBuffer(context, options); |
| 120 }).throw("NotSupportedError") && success; |
| 121 |
| 122 Should("Invalid option values handled", success) |
| 123 .summarize("correctly", "incorrectly"); |
| 124 |
| 125 taskDone(); |
| 126 }); |
| 127 |
| 128 audit.defineTask("default constructor", function (taskDone) { |
| 129 var buffer; |
| 130 var success = true; |
| 131 |
| 132 var options = { |
| 133 numberOfChannels: 5, |
| 134 length: 17 |
| 135 }; |
| 136 success = Should( |
| 137 "buffer = new AudioBuffer(c, " + JSON.stringify(options) + ")", |
| 138 function () { |
| 139 buffer = new AudioBuffer(context, options); |
| 140 }).notThrow(); |
| 141 |
| 142 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) |
| 143 .beEqualTo(options.numberOfChannels) && success; |
| 144 success = Should("buffer.length", buffer.length) |
| 145 .beEqualTo(options.length) && success; |
| 146 success = Should("buffer.sampleRate", buffer.sampleRate) |
| 147 .beEqualTo(context.sampleRate) && success; |
| 148 |
| 149 Should("Default constructor values set", success) |
| 150 .summarize("correctly", "incorrectly"); |
| 151 |
| 152 taskDone(); |
| 153 }); |
| 154 |
| 155 audit.defineTask("valid constructor", function (taskDone) { |
| 156 var buffer; |
| 157 var success = true; |
| 158 |
| 159 var options = { |
| 160 numberOfChannels: 3, |
| 161 length: 42, |
| 162 sampleRate: 54321 |
| 163 }; |
| 164 |
| 165 var message = "new AudioBuffer(c, {" + JSON.stringify(options) + ")"; |
| 166 success = Should(message, function () { |
| 167 buffer = new AudioBuffer(context, options); |
| 168 }).notThrow(); |
| 169 |
| 170 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) |
| 171 .beEqualTo(options.numberOfChannels) && success; |
| 172 |
| 173 success = Should("buffer.length", buffer.length) |
| 174 .beEqualTo(options.length) && success; |
| 175 |
| 176 success = Should("buffer.sampleRate", buffer.sampleRate) |
| 177 .beEqualTo(options.sampleRate) && success; |
| 178 |
| 179 // Verify that we actually got the right number of channels |
| 180 for (var k = 0; k < options.numberOfChannels; ++k) { |
| 181 var data; |
| 182 var message = "buffer.getChannelData(" + k + ")"; |
| 183 success = Should(message, function () { |
| 184 data = buffer.getChannelData(k); |
| 185 }).notThrow() && success; |
| 186 |
| 187 success = Should(message + " length", data.length) |
| 188 .beEqualTo(options.length) && success; |
| 189 } |
| 190 |
| 191 Should("buffer.getChannelData(" + options.numberOfChannels + ")", |
| 192 function () { |
| 193 buffer.getChannelData(options.numberOfChannels); |
| 194 }).throw("IndexSizeError") && success; |
| 195 |
| 196 Should("AudioBuffer constructed", success) |
| 197 .summarize("correctly", "incorrectly"); |
| 198 |
| 199 taskDone(); |
| 200 }); |
| 201 |
| 202 audit.runTasks(); |
| 203 </script> |
| 204 </body> |
| 205 </html> |
OLD | NEW |