Bug 1363667 - P7.1 - await on sync sources in mochitest draft
authorNico Grunbaum
Thu, 16 Nov 2017 22:06:57 -0800
changeset 706493 f376374281eb73b2acdf84927f8d8e321091f917
parent 706492 1db4346841a00590c4f241d90f8f1c4ea0dcffa0
child 706494 5b0cbd986f4659ee1d24a0dba389ea32de75d9b3
push id91808
push userna-g@nostrum.com
push dateSat, 02 Dec 2017 00:48:28 +0000
bugs1363667
milestone59.0a1
Bug 1363667 - P7.1 - await on sync sources in mochitest MozReview-Commit-ID: 200XlBGldKa
dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
--- 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.");
     }