OLD | NEW |
(Empty) | |
| 1 library AudioContextTest; |
| 2 import 'package:unittest/unittest.dart'; |
| 3 import 'package:unittest/html_individual_config.dart'; |
| 4 import 'dart:html'; |
| 5 import 'dart:typed_data'; |
| 6 import 'dart:web_audio'; |
| 7 import 'dart:async'; |
| 8 |
| 9 main() { |
| 10 |
| 11 useHtmlIndividualConfiguration(); |
| 12 |
| 13 var isAudioContext = |
| 14 predicate((x) => x is AudioContext, 'is an AudioContext'); |
| 15 |
| 16 group('supported', () { |
| 17 test('supported', () { |
| 18 expect(AudioContext.supported, true); |
| 19 }); |
| 20 }); |
| 21 |
| 22 group('functional', () { |
| 23 var context; |
| 24 if (AudioContext.supported) { |
| 25 context = new AudioContext(); |
| 26 } |
| 27 |
| 28 test('constructorTest', () { |
| 29 if(AudioContext.supported) { |
| 30 expect(context, isNotNull); |
| 31 expect(context, isAudioContext); |
| 32 } |
| 33 }); |
| 34 |
| 35 test('audioRenames', () { |
| 36 if(AudioContext.supported) { |
| 37 GainNode gainNode = context.createGain(); |
| 38 gainNode.connectNode(context.destination); |
| 39 expect(gainNode is GainNode, isTrue); |
| 40 |
| 41 expect(context.createAnalyser() is AnalyserNode, isTrue); |
| 42 expect(context.createChannelMerger() is AudioNode, isTrue); |
| 43 expect(context.createChannelSplitter() is AudioNode, isTrue); |
| 44 expect(context.createOscillator() is OscillatorNode, isTrue); |
| 45 expect(context.createPanner() is PannerNode, isTrue); |
| 46 expect(context.createScriptProcessor(4096) is ScriptProcessorNode, |
| 47 isTrue); |
| 48 } |
| 49 }); |
| 50 |
| 51 // TODO(9322): This test times out. |
| 52 /* |
| 53 test('onAudioProcess', () { |
| 54 if(AudioContext.supported) { |
| 55 var completer = new Completer<bool>(); |
| 56 var context = new AudioContext(); |
| 57 var scriptProcessor = context.createScriptProcessor(1024, 1, 2); |
| 58 scriptProcessor.connectNode(context.destination); |
| 59 bool alreadyCalled = false; |
| 60 scriptProcessor.onAudioProcess.listen((event) { |
| 61 if (!alreadyCalled) { |
| 62 completer.complete(true); |
| 63 } |
| 64 alreadyCalled = true; |
| 65 }); |
| 66 return completer.future; |
| 67 } |
| 68 }); |
| 69 */ |
| 70 |
| 71 test('oscillatorTypes', () { |
| 72 if(AudioContext.supported) { |
| 73 OscillatorNode oscillator = context.createOscillator(); |
| 74 oscillator.connectNode(context.destination); |
| 75 |
| 76 oscillator.type = 'sawtooth'; |
| 77 expect(oscillator.type, equals('sawtooth')); |
| 78 |
| 79 oscillator.type = 'sine'; |
| 80 expect(oscillator.type, equals('sine')); |
| 81 |
| 82 oscillator.type = 'square'; |
| 83 expect(oscillator.type, equals('square')); |
| 84 |
| 85 oscillator.type = 'triangle'; |
| 86 expect(oscillator.type, equals('triangle')); |
| 87 |
| 88 //expect(() => oscillator.type = 7, throws); Firefox does not throw, it |
| 89 //simply ignores this value. |
| 90 expect(oscillator.type, equals('triangle')); |
| 91 |
| 92 // Firefox does not throw when it receives invalid values; it simply |
| 93 // ignores them. |
| 94 //expect(() => oscillator.type = ['heap object not a string'], throws); |
| 95 expect(oscillator.type, equals('triangle')); |
| 96 } |
| 97 }); |
| 98 }); |
| 99 } |
OLD | NEW |