ctor-oscillator.html (3640B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test Constructor: Oscillator 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/webaudio/resources/audit-util.js"></script> 10 <script src="/webaudio/resources/audit.js"></script> 11 <script src="/webaudio/resources/audionodeoptions.js"></script> 12 </head> 13 <body> 14 <script id="layout-test-code"> 15 let context; 16 17 let audit = Audit.createTaskRunner(); 18 19 audit.define('initialize', (task, should) => { 20 context = initializeContext(should); 21 task.done(); 22 }); 23 24 audit.define('invalid constructor', (task, should) => { 25 testInvalidConstructor(should, 'OscillatorNode', context); 26 task.done(); 27 }); 28 29 audit.define('default constructor', (task, should) => { 30 let prefix = 'node0'; 31 let node = testDefaultConstructor(should, 'OscillatorNode', context, { 32 prefix: prefix, 33 numberOfInputs: 0, 34 numberOfOutputs: 1, 35 channelCount: 2, 36 channelCountMode: 'max', 37 channelInterpretation: 'speakers' 38 }); 39 40 testDefaultAttributes( 41 should, node, prefix, 42 [{name: 'type', value: 'sine'}, {name: 'frequency', value: 440}]); 43 44 task.done(); 45 }); 46 47 audit.define('test AudioNodeOptions', (task, should) => { 48 testAudioNodeOptions(should, context, 'OscillatorNode'); 49 task.done(); 50 }); 51 52 audit.define('constructor options', (task, should) => { 53 let node; 54 let options = {type: 'sawtooth', detune: 7, frequency: 918}; 55 56 should( 57 () => { 58 node = new OscillatorNode(context, options); 59 }, 60 'node1 = new OscillatorNode(c, ' + JSON.stringify(options) + ')') 61 .notThrow(); 62 63 should(node.type, 'node1.type').beEqualTo(options.type); 64 should(node.detune.value, 'node1.detune.value') 65 .beEqualTo(options.detune); 66 should(node.frequency.value, 'node1.frequency.value') 67 .beEqualTo(options.frequency); 68 69 should(node.channelCount, 'node1.channelCount').beEqualTo(2); 70 should(node.channelCountMode, 'node1.channelCountMode') 71 .beEqualTo('max'); 72 should(node.channelInterpretation, 'node1.channelInterpretation') 73 .beEqualTo('speakers'); 74 75 // Test that type and periodicWave options work as described. 76 options = { 77 type: 'sine', 78 periodicWave: new PeriodicWave(context, {real: [1, 1]}) 79 }; 80 should(() => { 81 node = new OscillatorNode(context, options); 82 }, 'new OscillatorNode(c, ' + JSON.stringify(options) + ')').notThrow(); 83 84 options = {type: 'custom'}; 85 should( 86 () => { 87 node = new OscillatorNode(context, options); 88 }, 89 'new OscillatorNode(c, ' + JSON.stringify(options) + ')') 90 .throw(DOMException, 'InvalidStateError'); 91 92 options = { 93 type: 'custom', 94 periodicWave: new PeriodicWave(context, {real: [1, 1]}) 95 }; 96 should(() => { 97 node = new OscillatorNode(context, options); 98 }, 'new OscillatorNode(c, ' + JSON.stringify(options) + ')').notThrow(); 99 100 should( 101 () => { 102 node = new OscillatorNode(context, {periodicWave: null}); 103 }, 104 'new OscillatorNode(c, {periodicWave: null}') 105 .throw(DOMException, 'TypeError'); 106 task.done(); 107 }); 108 109 audit.run(); 110 </script> 111 </body> 112 </html>