Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test Constructor: AudioBufferSource</title> | |
| 5 <script src="../../resources/testharness.js"></script> | |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 7 <script src="../resources/audio-testing.js"></script> | |
| 8 <script src="audionodeoptions.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 var context; | |
| 14 | |
| 15 var audit = Audit.createTaskRunner(); | |
| 16 | |
| 17 audit.defineTask("initialize", function (taskDone) { | |
| 18 Should("context = new OfflineAudioContext(...)", function () { | |
| 19 context = new OfflineAudioContext(1, 1, 48000); | |
| 20 }).notThrow(); | |
| 21 | |
| 22 taskDone(); | |
| 23 }); | |
| 24 | |
| 25 audit.defineTask("invalid constructor", function (taskDone) { | |
| 26 var node; | |
| 27 var success = true; | |
| 28 | |
| 29 success = Should("new AudioBufferSourceNode()", function () { | |
| 30 node = new AudioBufferSourceNode(); | |
| 31 }).throw("TypeError"); | |
| 32 success = Should("new AudioBufferSourceNode(1)", function () { | |
| 33 node = new AudioBufferSourceNode(1) && success; | |
| 34 }).throw("TypeError"); | |
| 35 success = Should("new AudioBufferSourceNode(context, 42)", function () { | |
| 36 node = new AudioBufferSourceNode(context, 42) && success; | |
| 37 }).throw("TypeError"); | |
| 38 | |
| 39 Should("Invalid constructors", success) | |
| 40 .summarize( | |
| 41 "correctly threw errors", | |
| 42 "did not throw errors in all cases"); | |
| 43 | |
| 44 taskDone(); | |
| 45 }); | |
| 46 | |
| 47 audit.defineTask("default constructor", function (taskDone) { | |
| 48 var node; | |
| 49 var success = true; | |
| 50 | |
| 51 success = Should("node = new AudioBufferSourceNode(context)", function ( ) { | |
| 52 node = new AudioBufferSourceNode(context); | |
| 53 }).notThrow() && success; | |
| 54 | |
| 55 success = Should("node instanceof AudioBufferSourceNode", | |
| 56 node instanceof AudioBufferSourceNode).beEqualTo(true) && success; | |
| 57 | |
| 58 success = Should("node.buffer === null", node.buffer === null) | |
| 59 .beEqualTo(true) && success; | |
| 60 | |
| 61 // This node using the factory method is used as a reference for the | |
| 62 // defautl values. | |
| 63 var factoryNode = context.createBufferSource(); | |
| 64 | |
| 65 var testAttributes = ["buffer", "detune", "loop", "loopEnd", "loopStart" , | |
| 66 "playbackRate"]; | |
| 67 | |
| 68 for (var index in testAttributes) { | |
| 69 var name = testAttributes[index]; | |
| 70 | |
| 71 if (node[name] instanceof AudioParam) { | |
| 72 success = Should("node." + name + ".value", node[name].value) | |
| 73 .beEqualTo(factoryNode[name].value) && success; | |
| 74 } else { | |
| 75 success = Should("node." + name, node[name]) | |
| 76 .beEqualTo(factoryNode[name]) && success; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 Should("AudioBufferSourceNode constructed", success) | |
| 81 .summarize("correctly", "incorrectly"); | |
| 82 | |
| 83 taskDone(); | |
| 84 }); | |
| 85 | |
| 86 audit.defineTask("constructor options", function (taskDone) { | |
| 87 var node; | |
| 88 var success = true; | |
| 89 | |
| 90 var buffer = context.createBuffer(2, 1000, context.sampleRate); | |
| 91 | |
| 92 var options = { | |
| 93 buffer: buffer, | |
| 94 detune: .5, | |
| 95 loop: true, | |
| 96 loopEnd: (buffer.length / 2) / context.sampleRate, | |
| 97 loopStart: 5 / context.sampleRate, | |
| 98 playbackRate: .75 | |
| 99 } | |
|
hongchan
2016/09/13 22:13:22
missing ;
Raymond Toy
2016/09/14 18:02:22
Done.
| |
| 100 | |
| 101 message = "node = new AudioBufferSourceNode(context, {"; | |
|
hongchan
2016/09/13 22:13:22
Let's not repeat |message| here and on.
Raymond Toy
2016/09/14 18:02:22
Using JSON.stringify instead.
| |
| 102 message += "buffer: buffer"; | |
| 103 message += ", detune: " + options.detune; | |
| 104 message += ", loop: " + options.loop; | |
| 105 message += ", loopEnd: " + options.loopEnd; | |
| 106 message += ", loopStart: " + options.loopStart; | |
| 107 message += ", playbackRate: " + options.playbackRate; | |
| 108 message += "})"; | |
| 109 | |
| 110 success = Should(message, function () { | |
| 111 node = new AudioBufferSourceNode(context, options); | |
| 112 }).notThrow(); | |
| 113 | |
| 114 var factoryNode = context.createBufferSource(); | |
| 115 factoryNode.buffer = options.buffer; | |
| 116 factoryNode.detune.value = options.detune; | |
| 117 factoryNode.loop = options.loop; | |
| 118 factoryNode.loopEnd = options.loopEnd; | |
| 119 factoryNode.loopStart = options.loopStart; | |
| 120 factoryNode.playbackRate.value = options.playbackRate; | |
| 121 | |
| 122 success = Should("node.buffer === buffer", node.buffer === buffer) | |
| 123 .beEqualTo(true) && success; | |
| 124 success = Should("node.detune.value", node.detune.value) | |
| 125 .beEqualTo(factoryNode.detune.value) && success; | |
| 126 success = Should("node.loop", node.loop) | |
| 127 .beEqualTo(factoryNode.loop) && success; | |
| 128 success = Should("node.loopEnd", node.loopEnd) | |
| 129 .beEqualTo(factoryNode.loopEnd) && success; | |
| 130 success = Should("node.loopStart", node.loopStart) | |
| 131 .beEqualTo(factoryNode.loopStart) && success; | |
| 132 success = Should("node.playbackRate.value", node.playbackRate.value) | |
| 133 .beEqualTo(factoryNode.playbackRate.value) && success; | |
| 134 | |
| 135 Should("AudioBufferSource with options cosntructed", success) | |
| 136 .summarize("correctly", "incorrectly"); | |
| 137 | |
| 138 taskDone(); | |
| 139 }); | |
| 140 | |
| 141 audit.runTasks(); | |
| 142 </script> | |
| 143 </body> | |
| 144 </html> | |
| OLD | NEW |