dart-sdk/tests/lib/html/audiocontext_test.dart
Srujan Gaddam a925f4770f [dart:html] Remove 2.7 annotation from lib/html
Strips out the temporary annotation so all the tests without
NNBD related changes can run in strong mode.

Change-Id: I88f18916f0c5a45a80eddb73941db19984f0bfcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140652
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-04-06 20:41:14 +00:00

100 lines
3 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:html';
import 'dart:typed_data';
import 'dart:web_audio';
import 'package:expect/minitest.dart';
main() {
var isAudioContext =
predicate((x) => x is AudioContext, 'is an AudioContext');
group('supported', () {
test('supported', () {
expect(AudioContext.supported, true);
});
});
group('functional', () {
var context;
if (AudioContext.supported) {
context = new AudioContext();
}
test('constructorTest', () {
if (AudioContext.supported) {
expect(context, isNotNull);
expect(context, isAudioContext);
}
});
test('audioRenames', () {
if (AudioContext.supported) {
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);
}
});
// TODO(9322): This test times out.
/*
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;
}
});
*/
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'));
oscillator.type = 'square';
expect(oscillator.type, equals('square'));
oscillator.type = 'triangle';
expect(oscillator.type, equals('triangle'));
//expect(() => oscillator.type = 7, throws); Firefox does not throw, it
//simply ignores this value.
expect(oscillator.type, equals('triangle'));
// Firefox does not throw when it receives invalid values; it simply
// ignores them.
//expect(() => oscillator.type = ['heap object not a string'], throws);
expect(oscillator.type, equals('triangle'));
}
});
});
}