f81052f2c8
BUG= R=jmesserly@google.com Review URL: https://codereview.chromium.org//18577002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24709 260f80e4-7a28-3924-810f-c04153c831b5
81 lines
2.4 KiB
Dart
81 lines
2.4 KiB
Dart
library AudioContextTest;
|
|
import '../../pkg/unittest/lib/unittest.dart';
|
|
import '../../pkg/unittest/lib/html_individual_config.dart';
|
|
import 'dart:html';
|
|
import 'dart:typed_data';
|
|
import 'dart:web_audio';
|
|
import 'dart:async';
|
|
|
|
main() {
|
|
|
|
useHtmlIndividualConfiguration();
|
|
|
|
var isAudioContext =
|
|
predicate((x) => x is AudioContext, 'is an AudioContext');
|
|
|
|
group('supported', () {
|
|
test('supported', () {
|
|
expect(AudioContext.supported, true);
|
|
});
|
|
});
|
|
|
|
group('functional', () {
|
|
test('constructorTest', () {
|
|
if(AudioContext.supported) {
|
|
var ctx = new AudioContext();
|
|
expect(ctx, isNotNull);
|
|
expect(ctx, isAudioContext);
|
|
}
|
|
});
|
|
|
|
test('createBuffer', () {
|
|
if(AudioContext.supported) {
|
|
var ctx = new AudioContext();
|
|
Float32List view = new Float32List.fromList([]);
|
|
try {
|
|
// Test that native overload is chosen correctly. Native
|
|
// implementation should throw 'SyntaxError' DomException because the
|
|
// buffer is empty.
|
|
AudioBuffer buffer = ctx.createBufferFromBuffer(view.buffer, false);
|
|
} catch (e) {
|
|
expect(e.name, DomException.SYNTAX);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('audioRenames', () {
|
|
if(AudioContext.supported) {
|
|
AudioContext context = new AudioContext();
|
|
GainNode gainNode = context.createGain();
|
|
gainNode.connectNode(context.destination);
|
|
expect(gainNode is GainNode, isTrue);
|
|
|
|
expect(context.createAnalyser() is AnalyserNode, isTrue);
|
|
expect(context.createChannelMerger() is AudioNode, isTrue);
|
|
expect(context.createChannelSplitter() is AudioNode, isTrue);
|
|
expect(context.createOscillator() is OscillatorNode, isTrue);
|
|
expect(context.createPanner() is PannerNode, isTrue);
|
|
expect(context.createScriptProcessor(4096) is ScriptProcessorNode,
|
|
isTrue);
|
|
}
|
|
});
|
|
|
|
test('onAudioProcess', () {
|
|
if(AudioContext.supported) {
|
|
var completer = new Completer<bool>();
|
|
var context = new AudioContext();
|
|
var scriptProcessor = context.createScriptProcessor(1024, 1, 2);
|
|
scriptProcessor.connectNode(context.destination);
|
|
bool alreadyCalled = false;
|
|
scriptProcessor.onAudioProcess.listen((event) {
|
|
if (!alreadyCalled) {
|
|
completer.complete(true);
|
|
}
|
|
alreadyCalled = true;
|
|
});
|
|
return completer.future;
|
|
}
|
|
});
|
|
});
|
|
}
|