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
|
<!DOCTYPE html>
<html>
<head>
<title>
Test Constructor: AudioBufferSource
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit-util.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<script src="/webaudio/resources/audionodeoptions.js"></script>
</head>
<body>
<script id="layout-test-code">
let context;
let audit = Audit.createTaskRunner();
audit.define('initialize', (task, should) => {
context = initializeContext(should);
task.done();
});
audit.define('invalid constructor', (task, should) => {
testInvalidConstructor(should, 'AudioBufferSourceNode', context);
task.done();
});
audit.define('default constructor', (task, should) => {
let prefix = 'node0';
let node =
testDefaultConstructor(should, 'AudioBufferSourceNode', context, {
prefix: prefix,
numberOfInputs: 0,
numberOfOutputs: 1,
channelCount: 2,
channelCountMode: 'max',
channelInterpretation: 'speakers'
});
testDefaultAttributes(should, node, prefix, [
{name: 'buffer', value: null},
{name: 'detune', value: 0},
{name: 'loop', value: false},
{name: 'loopEnd', value: 0.0},
{name: 'loopStart', value: 0.0},
{name: 'playbackRate', value: 1.0},
]);
task.done();
});
audit.define('nullable buffer', (task, should) => {
let node;
let options = {buffer: null};
should(
() => {
node = new AudioBufferSourceNode(context, options);
},
'node1 = new AudioBufferSourceNode(c, ' + JSON.stringify(options))
.notThrow();
should(node.buffer, 'node1.buffer').beEqualTo(null);
task.done();
});
audit.define('constructor options', (task, should) => {
let node;
let buffer = context.createBuffer(2, 1000, context.sampleRate);
let options = {
buffer: buffer,
detune: .5,
loop: true,
loopEnd: (buffer.length / 2) / context.sampleRate,
loopStart: 5 / context.sampleRate,
playbackRate: .75
};
let message = 'node = new AudioBufferSourceNode(c, ' +
JSON.stringify(options) + ')';
should(() => {
node = new AudioBufferSourceNode(context, options);
}, message).notThrow();
// Use the factory method to create an equivalent node and compare the
// results from the constructor against this node.
let factoryNode = context.createBufferSource();
factoryNode.buffer = options.buffer;
factoryNode.detune.value = options.detune;
factoryNode.loop = options.loop;
factoryNode.loopEnd = options.loopEnd;
factoryNode.loopStart = options.loopStart;
factoryNode.playbackRate.value = options.playbackRate;
should(node.buffer === buffer, 'node2.buffer === buffer')
.beEqualTo(true);
should(node.detune.value, 'node2.detune.value')
.beEqualTo(factoryNode.detune.value);
should(node.loop, 'node2.loop').beEqualTo(factoryNode.loop);
should(node.loopEnd, 'node2.loopEnd').beEqualTo(factoryNode.loopEnd);
should(node.loopStart, 'node2.loopStart')
.beEqualTo(factoryNode.loopStart);
should(node.playbackRate.value, 'node2.playbackRate.value')
.beEqualTo(factoryNode.playbackRate.value);
task.done();
});
audit.run();
</script>
</body>
</html>
|