Bug 1363667 - P7.1 - await on sync sources in mochitest
MozReview-Commit-ID: 200XlBGldKa
--- a/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
+++ b/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
@@ -6,20 +6,34 @@
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1363667",
title: "Test audio receiver getSynchronizationSources"
});
- var testGetSynchronizationSources = (test) => {
+ var waitForSyncSources = async (test) => {
let receivers = [...test.pcRemote.getReceivers(),
...test.pcLocal.getReceivers()];
is(receivers.length, 2, "Expected number of receivers");
+ // Wait for sync sources
+ while (true) {
+ if (receivers[0].getSynchronizationSources().length > 0 &&
+ receivers[1].getSynchronizationSources().length > 0) {
+ break;
+ }
+ await wait(250);
+ }
+ }
+
+ var testGetSynchronizationSources = async (test) => {
+ await waitForSyncSources(test);
+ let receivers = [...test.pcRemote.getReceivers(),
+ ...test.pcLocal.getReceivers()];
for (let recv of receivers) {
let syncSources = recv.getSynchronizationSources();
ok(syncSources,
"Receiver has Synchronization sources " + JSON.stringify(syncSources));
is(syncSources.length, 1, "Each receiver has only a single sync source");
let source = recv.getSynchronizationSources()[0];
ok(source.audioLevel,
`Synchronization source has audio level. (${source.audioLevel})`);
@@ -29,17 +43,18 @@
`Synchronization source audio level is int. (${source.audioLevel})`);
ok(source.timestamp,
`Synchronization source has timestamp (${source.timestamp})`);
ok(Number.isInteger(source.timestamp),
`Synchronization source timestamp is int (${source.timestamp})`);
}
}
- var testSynchronizationSourceCached = (test) => {
+ var testSynchronizationSourceCached = async (test) => {
+ await waitForSyncSources(test);
let receivers = [...test.pcRemote.getReceivers(),
...test.pcLocal.getReceivers()];
is(receivers.length, 2, "Expected number of receivers");
for (let recv of receivers) {
is(JSON.stringify(recv.getSynchronizationSources()),
JSON.stringify(recv.getSynchronizationSources()),
"Subsequent getSynchronizationSources calls are cached.");
}