-
Notifications
You must be signed in to change notification settings - Fork 36
/
audio-context-constructor.js
129 lines (84 loc) · 3.44 KB
/
audio-context-constructor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import 'core-js/es7/reflect';
import { UNPATCHED_AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER, unpatchedAudioContextConstructor } from '../../../../src/providers/unpatched-audio-context-constructor';
import { ReflectiveInjector } from '@angular/core';
import { WINDOW_PROVIDER } from '../../../../src/providers/window';
import { loadFixture } from '../../../helper/load-fixture';
import { spy } from 'sinon';
describe('audioContextConstructor', () => {
let audioContext;
let AudioContext;
afterEach(() => audioContext.close());
beforeEach(() => {
const injector = ReflectiveInjector.resolveAndCreate([
UNPATCHED_AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER,
WINDOW_PROVIDER
]);
AudioContext = injector.get(unpatchedAudioContextConstructor);
audioContext = new AudioContext();
});
describe('outputLatency', () => {
// bug #40
it('should not be implemented', () => {
expect(audioContext.outputLatency).to.be.undefined;
});
});
describe('state', () => {
// bug #34
it('should be set to running right away', () => {
expect(audioContext.state).to.equal('running');
});
});
describe('createChannelSplitter()', () => {
// bug #30
it('should allow to set the channelCountMode', () => {
const channelSplitterNode = audioContext.createChannelSplitter();
channelSplitterNode.channelCountMode = 'explicit';
});
// bug #31
it('should have a channelInterpretation of max', () => {
const channelSplitterNode = audioContext.createChannelSplitter();
expect(channelSplitterNode.channelInterpretation).to.equal('speakers');
});
// bug #32
it('should allow to set the channelInterpretation', () => {
const channelSplitterNode = audioContext.createChannelSplitter();
channelSplitterNode.channelInterpretation = 'discrete';
});
});
describe('createGain()', () => {
let gainNode;
beforeEach(() => {
gainNode = audioContext.createGain();
});
describe('cancelAndHoldAtTime()', () => {
// bug #28
it('should not be implemented', () => {
expect(gainNode.cancelAndHoldAtTime).to.be.undefined;
});
});
});
describe('decodeAudioData()', () => {
// bug #1
it('should require the success callback function as a parameter', (done) => {
loadFixture('1000-frames-of-noise.wav', (err, arrayBuffer) => {
expect(err).to.be.null;
audioContext
.decodeAudioData(arrayBuffer, undefined, () => {})
.catch((err) => {
expect(err).to.be.an.instanceOf(TypeError);
expect(err.message).to.equal("Failed to execute 'decodeAudioData' on 'BaseAudioContext': The callback provided as parameter 2 is not a function.");
done();
});
});
});
// bug #6
it('should not call the errorCallback at all', (done) => {
const errorCallback = spy();
audioContext.decodeAudioData(null, () => {}, errorCallback);
setTimeout(() => {
expect(errorCallback).to.have.not.been.called;
done();
}, 1000);
});
});
});