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
diff --git a/webaudio/the-audio-api/the-audioworklet-interface/suspended-context-messageport.https.html b/webaudio/the-audio-api/the-audioworklet-interface/suspended-context-messageport.https.html
new file mode 100644
index 0000000..5f5b10a
--- /dev/null
+++ b/webaudio/the-audio-api/the-audioworklet-interface/suspended-context-messageport.https.html
@@ -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>