Improve debugging ability of some webrtc tests
[WebKit-https.git] / LayoutTests / webrtc / audio-replace-track.html
index 0156dde..952bc8b 100644 (file)
@@ -2,7 +2,7 @@
 <html>
 <head>
     <meta charset="utf-8">
-    <title>Testing local audio capture playback causes "playing" event to fire</title>
+    <title>Testing replacing an audio track during a WebRTC call</title>
     <script src="../resources/testharness.js"></script>
     <script src="../resources/testharnessreport.js"></script>
     <script src ="routines.js"></script>
@@ -12,6 +12,7 @@
     var sender;
     var remoteStream;
     var secondStream;
+    var receivingConnection;
     promise_test((test) => {
         if (window.testRunner)
             testRunner.setUserMediaPermission(true);
@@ -21,6 +22,7 @@
                 createConnections((firstConnection) => {
                     sender = firstConnection.addTrack(firstStream.getAudioTracks()[0], firstStream);
                 }, (secondConnection) => {
+                    receivingConnection = secondConnection;
                     secondConnection.ontrack = (trackEvent) => { resolve(trackEvent.streams[0]); };
                 });
                 setTimeout(() => reject("Test timed out"), 5000);
     }, "Starting an audio connection");
 
     promise_test(() => {
+        if (receivingConnection.connectionState === "connected")
+            return Promise.resolve();
+        return new Promise((resolve, reject) => {
+            receivingConnection.onconnectionstatechange = () => {
+                if (receivingConnection.connectionState === "connected")
+                    resolve();
+            };
+            setTimeout(() => reject("Test timed out"), 5000);
+        });
+    }, "Ensuring connection state is connected");
+
+    promise_test(() => {
         return doHumAnalysis(remoteStream, true).then((result) => {
             assert_true(result, "heard hum 1");
         });