| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Constructor: Oscillator</title> | 4 <title>Test Constructor: Oscillator</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/audit.js"></script> |
| 9 <script src="audionodeoptions.js"></script> | 9 <script src="new-audionodeoptions.js"></script> |
| 10 </head> | 10 </head> |
| 11 | 11 |
| 12 <body> | 12 <body> |
| 13 <script> | 13 <script> |
| 14 var context; | 14 var context; |
| 15 | 15 |
| 16 var audit = Audit.createTaskRunner(); | 16 var audit = Audit.createTaskRunner(); |
| 17 | 17 |
| 18 audit.defineTask("initialize", function (taskDone) { | 18 audit.define('initialize', (task, should) => { |
| 19 Should("context = new OfflineAudioContext(...)", function () { | 19 context = initializeContext(should); |
| 20 context = new OfflineAudioContext(1, 1, 48000); | 20 task.done(); |
| 21 }).notThrow(); | |
| 22 | |
| 23 taskDone(); | |
| 24 }); | 21 }); |
| 25 | 22 |
| 26 audit.defineTask("invalid constructor", function (taskDone) { | 23 audit.define('invalid constructor', (task, should) => { |
| 27 var node; | 24 testInvalidConstructor(should, 'OscillatorNode', context); |
| 28 var success = true; | 25 task.done(); |
| 29 | |
| 30 success = Should("new OscillatorNode()", function () { | |
| 31 node = new OscillatorNode(); | |
| 32 }).throw("TypeError"); | |
| 33 success = Should("new OscillatorNode(1)", function () { | |
| 34 node = new OscillatorNode(1) && success; | |
| 35 }).throw("TypeError"); | |
| 36 success = Should("new OscillatorNode(context, 42)", function () { | |
| 37 node = new OscillatorNode(context, 42) && success; | |
| 38 }).throw("TypeError"); | |
| 39 | |
| 40 Should("Invalid constructors", success) | |
| 41 .summarize( | |
| 42 "correctly threw errors", | |
| 43 "did not throw errors in all cases"); | |
| 44 | |
| 45 taskDone(); | |
| 46 }); | 26 }); |
| 47 | 27 |
| 48 audit.defineTask("default constructor", function (taskDone) { | 28 audit.define('default constructor', (task, should) => { |
| 49 var node; | 29 let prefix = 'node0'; |
| 50 var success = true; | 30 let node = testDefaultConstructor(should, 'OscillatorNode', context, { |
| 31 prefix: prefix, |
| 32 numberOfInputs: 0, |
| 33 numberOfOutputs: 1, |
| 34 channelCount: 2, |
| 35 channelCountMode: 'max', |
| 36 channelInterpretation: 'speakers' |
| 37 }); |
| 51 | 38 |
| 52 success = Should("node0 = new OscillatorNode(context)", function () { | 39 testDefaultAttributes( |
| 53 node = new OscillatorNode(context); | 40 should, node, prefix, |
| 54 }).notThrow(); | 41 [{name: 'type', value: 'sine'}, {name: 'frequency', value: 440}]); |
| 55 success = Should("node0 instanceof OscillatorNode", node instanceof Osci
llatorNode) | |
| 56 .beEqualTo(true) && success; | |
| 57 | 42 |
| 58 success = Should("node0.type", node.type) | 43 task.done(); |
| 59 .beEqualTo("sine") && success; | |
| 60 success = Should("node0.detune.value", node.detune.value) | |
| 61 .beEqualTo(0) && success; | |
| 62 success = Should("node0.frequency.value", node.frequency.value) | |
| 63 .beEqualTo(440) && success; | |
| 64 | |
| 65 success = Should("node0.channelCount", node.channelCount) | |
| 66 .beEqualTo(2) && success; | |
| 67 success = Should("node0.channelCountMode", node.channelCountMode) | |
| 68 .beEqualTo("max") && success; | |
| 69 success = Should("node0.channelInterpretation", node.channelInterpretati
on) | |
| 70 .beEqualTo("speakers") && success; | |
| 71 | |
| 72 Should("new OscillatorNode(context)", success) | |
| 73 .summarize( | |
| 74 "constructed node with correct attributes", | |
| 75 "did not construct correct node correctly") | |
| 76 | |
| 77 taskDone(); | |
| 78 }); | 44 }); |
| 79 | 45 |
| 80 audit.defineTask("test AudioNodeOptions", function (taskDone) { | 46 audit.define('test AudioNodeOptions', (task, should) => { |
| 81 testAudioNodeOptions(context, "OscillatorNode"); | 47 testAudioNodeOptions(should, context, 'OscillatorNode'); |
| 82 taskDone(); | 48 task.done(); |
| 83 }); | 49 }); |
| 84 | 50 |
| 85 audit.defineTask("constructor options", function (taskDone) { | 51 audit.define('constructor options', (task, should) => { |
| 86 var node; | 52 var node; |
| 87 var success = true; | 53 var options = {type: 'sawtooth', detune: 7, frequency: 918}; |
| 88 var options = { | |
| 89 type: "sawtooth", | |
| 90 detune: 7, | |
| 91 frequency: 918 | |
| 92 }; | |
| 93 | 54 |
| 94 success = Should("node1 = new OscillatorNode(c, " + JSON.stringify(optio
ns) + ")", | 55 should( |
| 95 function () { | 56 () => { |
| 96 node = new OscillatorNode(context, options); | 57 node = new OscillatorNode(context, options); |
| 97 }).notThrow(); | 58 }, |
| 59 'node1 = new OscillatorNode(c, ' + JSON.stringify(options) + ')') |
| 60 .notThrow(); |
| 98 | 61 |
| 99 success = Should("node1.type", node.type) | 62 should(node.type, 'node1.type').beEqualTo(options.type); |
| 100 .beEqualTo(options.type) && success; | 63 should(node.detune.value, 'node1.detune.value') |
| 101 success = Should("node1.detune.value", node.detune.value) | 64 .beEqualTo(options.detune); |
| 102 .beEqualTo(options.detune) && success; | 65 should(node.frequency.value, 'node1.frequency.value') |
| 103 success = Should("node1.frequency.value", node.frequency.value) | 66 .beEqualTo(options.frequency); |
| 104 .beEqualTo(options.frequency) && success; | |
| 105 | 67 |
| 106 success = Should("node1.channelCount", node.channelCount) | 68 should(node.channelCount, 'node1.channelCount').beEqualTo(2); |
| 107 .beEqualTo(2) && success; | 69 should(node.channelCountMode, 'node1.channelCountMode') |
| 108 success = Should("node1.channelCountMode", node.channelCountMode) | 70 .beEqualTo('max'); |
| 109 .beEqualTo("max") && success; | 71 should(node.channelInterpretation, 'node1.channelInterpretation') |
| 110 success = Should("node1.channelInterpretation", node.channelInterpretati
on) | 72 .beEqualTo('speakers'); |
| 111 .beEqualTo("speakers") && success; | |
| 112 | 73 |
| 113 // Test that type and periodicWave options work as described. | 74 // Test that type and periodicWave options work as described. |
| 114 options = { | 75 options = { |
| 115 type: "sine", | 76 type: 'sine', |
| 116 periodicWave: new PeriodicWave(context, { | 77 periodicWave: new PeriodicWave(context, {real: [1, 1]}) |
| 117 real: [1, 1] | |
| 118 }) | |
| 119 }; | 78 }; |
| 120 success = Should("node2 = new OscillatorNode(c, " + JSON.stringify(optio
ns) + ")", | 79 should( |
| 121 function () { | 80 () => { |
| 122 node = new OscillatorNode(context, options); | 81 node = new OscillatorNode(context, options); |
| 123 }) | 82 }, |
| 124 .notThrow() && success; | 83 'new OscillatorNode(c, ' + JSON.stringify(options) + ')') |
| 125 Should("node2.type", node.type).beEqualTo("custom"); | 84 .notThrow(); |
| 85 |
| 86 options = {type: 'custom'}; |
| 87 should( |
| 88 () => { |
| 89 node = new OscillatorNode(context, options); |
| 90 }, |
| 91 'new OscillatorNode(c, ' + JSON.stringify(options) + ')') |
| 92 .throw('InvalidStateError'); |
| 126 | 93 |
| 127 options = { | 94 options = { |
| 128 type: "custom" | 95 type: 'custom', |
| 96 periodicWave: new PeriodicWave(context, {real: [1, 1]}) |
| 129 }; | 97 }; |
| 130 success = Should("new OscillatorNode(c, " + JSON.stringify(options) + ")
", | 98 should(() => { |
| 131 function () { | 99 node = new OscillatorNode(context, options); |
| 132 node = new OscillatorNode(context, options); | 100 }, 'new OscillatorNode(, ' + JSON.stringify(options) + ')').notThrow(); |
| 133 }) | |
| 134 .throw("InvalidStateError") && success; | |
| 135 | 101 |
| 136 options = { | 102 task.done(); |
| 137 type: "custom", | |
| 138 periodicWave: new PeriodicWave(context, { | |
| 139 real: [1, 1] | |
| 140 }) | |
| 141 }; | |
| 142 success = Should("new OscillatorNode(, " + JSON.stringify(options) + ")"
, | |
| 143 function () { | |
| 144 node = new OscillatorNode(context, options); | |
| 145 }) | |
| 146 .notThrow() && success; | |
| 147 | |
| 148 Should("new OscillatorNode() with options", success) | |
| 149 .summarize( | |
| 150 "constructed with correct attributes", | |
| 151 "was not constructed correctly"); | |
| 152 | |
| 153 taskDone(); | |
| 154 }); | 103 }); |
| 155 | 104 |
| 156 audit.runTasks(); | 105 audit.run(); |
| 157 </script> | 106 </script> |
| 158 </body> | 107 </body> |
| 159 </html> | 108 </html> |
| OLD | NEW |