-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test MessagePort while AudioContext is not running
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
1 parent
34f3aca
commit aaf82b0
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
webaudio/the-audio-api/the-audioworklet-interface/suspended-context-messageport.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |