Skip to content

Commit

Permalink
test MessagePort while AudioContext is not running
Browse files Browse the repository at this point in the history
Depends on D65072

Differential Revision: https://phabricator.services.mozilla.com/D65073

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1596655
gecko-commit: 50e12683407166297882386eba9a34afec3109f8
gecko-integration-branch: autoland
gecko-reviewers: padenot
  • Loading branch information
karlt authored and moz-wptsync-bot committed Mar 4, 2020
1 parent 34f3aca commit aaf82b0
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = async (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 = async (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>

0 comments on commit aaf82b0

Please sign in to comment.