Chromium Code Reviews| 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 success = Should("new AudioBuffer(context, {numberOfChannels: 0})", func tion () { | |
|
hongchan
2016/09/13 22:13:22
We can apply the same technique of JSON.stringify
Raymond Toy
2016/09/14 18:02:22
Done.
| |
| 90 var buffer = new AudioBuffer(context, {numberOfChannels: 0, length: 1} ); | |
| 91 }).throw("NotSupportedError"); | |
| 92 | |
| 93 success = Should("new AudioBuffer(context, {numberOfChannels: 99})", fun ction () { | |
| 94 var buffer = new AudioBuffer(context, {numberOfChannels: 99, length: 0 }); | |
| 95 }).throw("NotSupportedError") && success; | |
| 96 | |
| 97 success = Should("new AudioBuffer(context, {length: 0})", function () { | |
| 98 var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 0} ); | |
| 99 }).throw("NotSupportedError") && success; | |
| 100 | |
| 101 success = Should("new AudioBuffer(context, {sampleRate: 100})", function () { | |
| 102 var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 1, | |
| 103 sampleRate: 100}); | |
| 104 }).throw("NotSupportedError") && success; | |
| 105 | |
| 106 Should("Invalid option values handled", success) | |
| 107 .summarize("correctly", "incorrectly"); | |
| 108 | |
| 109 taskDone(); | |
| 110 }); | |
| 111 | |
| 112 audit.defineTask("default constructor", function (taskDone) { | |
| 113 var buffer; | |
| 114 var success = true; | |
| 115 | |
| 116 success = Should( | |
| 117 "buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17})" , | |
| 118 function () { | |
| 119 buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17}) ; | |
| 120 }).notThrow(); | |
| 121 | |
| 122 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | |
| 123 .beEqualTo(5) && success; | |
| 124 success = Should("buffer.length", buffer.length) | |
| 125 .beEqualTo(17) && success; | |
| 126 success = Should("buffer.sampleRate", buffer.sampleRate) | |
| 127 .beEqualTo(context.sampleRate) && success; | |
| 128 | |
| 129 Should("Default constructor values set", success) | |
| 130 .summarize("correctly", "incorrectly"); | |
| 131 | |
| 132 taskDone(); | |
| 133 }); | |
| 134 | |
| 135 audit.defineTask("valid constructor", function (taskDone) { | |
| 136 var buffer; | |
| 137 var success = true; | |
| 138 | |
| 139 var options = { | |
| 140 numberOfChannels: 3, | |
| 141 length: 42, | |
| 142 sampleRate: 54321 | |
| 143 }; | |
| 144 | |
| 145 var message = "new AudioBuffer(context, {"; | |
|
hongchan
2016/09/13 22:13:22
var message = "..."
+ "..." + val1
+ "..." + v
| |
| 146 message += "numberOfChannels: " + options.numberOfChannels; | |
| 147 message += ", length: " + options.length; | |
| 148 message += ", sampleRate: " + options.sampleRate; | |
| 149 message += "}"; | |
| 150 success = Should(message, function () { | |
| 151 buffer = new AudioBuffer(context, options); | |
| 152 }).notThrow(); | |
| 153 | |
| 154 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | |
| 155 .beEqualTo(options.numberOfChannels) && success; | |
| 156 | |
| 157 success = Should("buffer.length", buffer.length) | |
| 158 .beEqualTo(options.length) && success; | |
| 159 | |
| 160 success = Should("buffer.sampleRate", buffer.sampleRate) | |
| 161 .beEqualTo(options.sampleRate) && success; | |
| 162 | |
| 163 // Verify that we actually got the right number of channels | |
| 164 for (var k = 0; k < options.numberOfChannels; ++k) { | |
| 165 var data; | |
| 166 var message = "buffer.getChannelData(" + k + ")"; | |
| 167 success = Should(message, function () { | |
| 168 data = buffer.getChannelData(k); | |
| 169 }).notThrow() && success; | |
| 170 | |
| 171 success = Should(message + " length", data.length) | |
| 172 .beEqualTo(options.length) && success; | |
| 173 } | |
| 174 | |
| 175 Should("buffer.getChannelData(" + options.numberOfChannels + ")", | |
| 176 function () { | |
| 177 buffer.getChannelData(options.numberOfChannels); | |
| 178 }).throw("IndexSizeError") && success; | |
| 179 | |
| 180 Should("AudioBuffer constructed", success) | |
| 181 .summarize("correctly", "incorrectly"); | |
| 182 | |
| 183 taskDone(); | |
| 184 }); | |
| 185 | |
| 186 audit.runTasks(); | |
| 187 </script> | |
| 188 </body> | |
| 189 </html> | |
| OLD | NEW |