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
|
<!doctype html>
<title>Test MessagePort while AudioContext is not running</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
const get_node_and_message = (context) => {
const node = new AudioWorkletNode(context, 'port-processor');
return new Promise((resolve) => {
node.port.onmessage = (event) => resolve({node: node, event: event});
});
};
const ping_for_message = (node) => {
return new Promise((resolve) => {
node.port.onmessage = resolve;
node.port.postMessage('ping');
});
};
const modulePath = 'processors/port-processor.js';
promise_test(async () => {
const realtime = new AudioContext();
await realtime.audioWorklet.addModule(modulePath);
await realtime.suspend();
const currentTime = realtime.currentTime;
let {node, event} = await get_node_and_message(realtime);
assert_equals(event.data.timeStamp, currentTime, 'created message time');
event = await ping_for_message(node);
assert_equals(event.data.timeStamp, currentTime, 'pong time');
}, 'realtime suspended');
let offline;
promise_test(async () => {
offline = new OfflineAudioContext({length: 128 + 1, sampleRate: 16384});
await offline.audioWorklet.addModule(modulePath);
assert_equals(offline.currentTime, 0, 'time before start');
let {node, event} = await get_node_and_message(offline);
assert_equals(event.data.timeStamp, 0, 'created time before start');
event = await ping_for_message(node);
assert_equals(event.data.timeStamp, 0, 'pong time before start');
}, 'offline before start');
promise_test(async () => {
await offline.startRendering();
const expected = 2 * 128 / offline.sampleRate;
assert_equals(offline.currentTime, expected, 'time on complete');
let {node, event} = await get_node_and_message(offline);
assert_equals(event.data.timeStamp, expected, "created time on complete");
event = await ping_for_message(node);
assert_equals(event.data.timeStamp, expected, "pong time on complete");
}, 'offline on complete');
</script>
|