2012-11-01 23:09:47 +00:00
|
|
|
library AudioContextTest;
|
2014-04-09 19:42:11 +00:00
|
|
|
import 'package:unittest/unittest.dart';
|
|
|
|
import 'package:unittest/html_individual_config.dart';
|
2012-11-01 23:09:47 +00:00
|
|
|
import 'dart:html';
|
2013-04-23 11:54:54 +00:00
|
|
|
import 'dart:typed_data';
|
2012-11-29 17:58:26 +00:00
|
|
|
import 'dart:web_audio';
|
2013-03-18 22:18:25 +00:00
|
|
|
import 'dart:async';
|
2012-04-28 10:34:16 +00:00
|
|
|
|
|
|
|
main() {
|
|
|
|
|
2013-03-18 22:18:25 +00:00
|
|
|
useHtmlIndividualConfiguration();
|
2012-04-28 10:34:16 +00:00
|
|
|
|
2012-10-26 22:52:03 +00:00
|
|
|
var isAudioContext =
|
|
|
|
predicate((x) => x is AudioContext, 'is an AudioContext');
|
|
|
|
|
2013-03-18 22:18:25 +00:00
|
|
|
group('supported', () {
|
|
|
|
test('supported', () {
|
|
|
|
expect(AudioContext.supported, true);
|
|
|
|
});
|
2012-04-28 10:34:16 +00:00
|
|
|
});
|
2013-03-18 22:18:25 +00:00
|
|
|
|
|
|
|
group('functional', () {
|
2015-01-26 20:27:23 +00:00
|
|
|
var context;
|
|
|
|
if (AudioContext.supported) {
|
|
|
|
context = new AudioContext();
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:18:25 +00:00
|
|
|
test('constructorTest', () {
|
|
|
|
if(AudioContext.supported) {
|
2015-01-26 20:27:23 +00:00
|
|
|
expect(context, isNotNull);
|
|
|
|
expect(context, isAudioContext);
|
2012-05-29 16:06:36 +00:00
|
|
|
}
|
2013-03-18 22:18:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('audioRenames', () {
|
|
|
|
if(AudioContext.supported) {
|
|
|
|
GainNode gainNode = context.createGain();
|
2013-07-02 22:32:44 +00:00
|
|
|
gainNode.connectNode(context.destination);
|
2013-03-18 22:18:25 +00:00
|
|
|
expect(gainNode is GainNode, isTrue);
|
|
|
|
|
|
|
|
expect(context.createAnalyser() is AnalyserNode, isTrue);
|
2013-03-18 23:46:53 +00:00
|
|
|
expect(context.createChannelMerger() is AudioNode, isTrue);
|
|
|
|
expect(context.createChannelSplitter() is AudioNode, isTrue);
|
2013-03-18 22:18:25 +00:00
|
|
|
expect(context.createOscillator() is OscillatorNode, isTrue);
|
|
|
|
expect(context.createPanner() is PannerNode, isTrue);
|
|
|
|
expect(context.createScriptProcessor(4096) is ScriptProcessorNode,
|
|
|
|
isTrue);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-23 00:12:09 +00:00
|
|
|
// TODO(9322): This test times out.
|
|
|
|
/*
|
2013-03-18 22:18:25 +00:00
|
|
|
test('onAudioProcess', () {
|
|
|
|
if(AudioContext.supported) {
|
|
|
|
var completer = new Completer<bool>();
|
|
|
|
var context = new AudioContext();
|
|
|
|
var scriptProcessor = context.createScriptProcessor(1024, 1, 2);
|
2013-07-02 22:32:44 +00:00
|
|
|
scriptProcessor.connectNode(context.destination);
|
2013-03-18 22:18:25 +00:00
|
|
|
bool alreadyCalled = false;
|
|
|
|
scriptProcessor.onAudioProcess.listen((event) {
|
|
|
|
if (!alreadyCalled) {
|
|
|
|
completer.complete(true);
|
|
|
|
}
|
|
|
|
alreadyCalled = true;
|
|
|
|
});
|
|
|
|
return completer.future;
|
|
|
|
}
|
|
|
|
});
|
2013-10-23 00:12:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
test('oscillatorTypes', () {
|
|
|
|
if(AudioContext.supported) {
|
|
|
|
OscillatorNode oscillator = context.createOscillator();
|
|
|
|
oscillator.connectNode(context.destination);
|
|
|
|
|
|
|
|
oscillator.type = 'sawtooth';
|
|
|
|
expect(oscillator.type, equals('sawtooth'));
|
|
|
|
|
|
|
|
oscillator.type = 'sine';
|
|
|
|
expect(oscillator.type, equals('sine'));
|
2014-07-15 18:06:35 +00:00
|
|
|
|
2013-10-23 00:12:09 +00:00
|
|
|
oscillator.type = 'square';
|
|
|
|
expect(oscillator.type, equals('square'));
|
2014-07-15 18:06:35 +00:00
|
|
|
|
2013-10-23 00:12:09 +00:00
|
|
|
oscillator.type = 'triangle';
|
|
|
|
expect(oscillator.type, equals('triangle'));
|
|
|
|
|
2014-07-15 18:06:35 +00:00
|
|
|
//expect(() => oscillator.type = 7, throws); Firefox does not throw, it
|
|
|
|
//simply ignores this value.
|
2013-10-23 00:12:09 +00:00
|
|
|
expect(oscillator.type, equals('triangle'));
|
|
|
|
|
2014-07-15 18:06:35 +00:00
|
|
|
// Firefox does not throw when it receives invalid values; it simply
|
|
|
|
// ignores them.
|
|
|
|
//expect(() => oscillator.type = ['heap object not a string'], throws);
|
2013-10-23 00:12:09 +00:00
|
|
|
expect(oscillator.type, equals('triangle'));
|
|
|
|
}
|
|
|
|
});
|
2012-10-30 21:12:52 +00:00
|
|
|
});
|
2012-04-28 10:34:16 +00:00
|
|
|
}
|