Bug 796890 - Create Mochitest for Video/Audio connection (send/receive/disconnect). r=jesup
authorHenrik Skupin <hskupin@mozilla.com>
Sun, 23 Dec 2012 23:04:37 +0100
changeset 126079 a395e2d60c1638361cb7730cc610183b354b9ff1
parent 126078 7f5fad93ef78556fd77f140ac550646f3d0d8407
child 126080 b190d329f7f3123f4941a31b9908eb0f3d757835
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs796890
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 796890 - Create Mochitest for Video/Audio connection (send/receive/disconnect). r=jesup
dom/media/tests/mochitest/Makefile.in
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/test_peerConnection_basicAudio.html
dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html
dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html
dom/media/tests/mochitest/test_peerConnection_basicVideo.html
--- a/dom/media/tests/mochitest/Makefile.in
+++ b/dom/media/tests/mochitest/Makefile.in
@@ -21,13 +21,15 @@ MOCHITEST_FILES = \
   $(NULL)
 
 # The following tests are leaking and cannot be run by default yet
 ifdef MOZ_WEBRTC_LEAKING_TESTS
 MOCHITEST_FILES += \
   test_getUserMedia_basicAudio.html \
   test_getUserMedia_basicVideoAudio.html \
   test_peerConnection_basicAudio.html \
+  test_peerConnection_basicAudioVideo.html \
+  test_peerConnection_basicAudioVideoCombined.html \
   test_peerConnection_basicVideo.html \
   $(NULL)
 endif
 
 include $(topsrcdir)/config/rules.mk
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -2,16 +2,23 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 var PeerConnection = {
   pc1_offer : null,
   pc2_answer : null,
 
+  /**
+   * Establishes the peer connection between two clients
+   *
+   * @param {object) aPCLocal Local client
+   * @param {object} aPCRemote Remote client
+   * @param {function} aSuccessCallback Method to call when the connection has been established
+   */
   handShake: function PC_handShake(aPCLocal, aPCRemote, aSuccessCallback) {
 
     function onCreateOfferSuccess(aOffer) {
       pc1_offer = aOffer;
       aPCLocal.setLocalDescription(aOffer, onSetLocalDescriptionSuccess1,
                                    unexpectedCallbackAndFinish);
     }
 
@@ -35,10 +42,30 @@ var PeerConnection = {
                                     unexpectedCallbackAndFinish);
     }
 
     function onSetRemoteDescriptionSuccess2() {
       aSuccessCallback();
     }
 
     aPCLocal.createOffer(onCreateOfferSuccess, unexpectedCallbackAndFinish);
+  },
+
+  /**
+   * Finds the given media stream in the list of available streams.
+   *
+   * This function is necessary because localStreams and remoteStreams don't have
+   * an indexOf method.
+   *
+   * @param {object} aMediaStreamList List of available media streams
+   * @param {object} aMediaStream Media stream to check for
+   * @return {number} Index in the media stream list
+   */
+  findStream: function PC_findStream(aMediaStreamList, aMediaStream) {
+    for (var index = 0; index < aMediaStreamList.length; index++) {
+      if (aMediaStreamList[index] === aMediaStream) {
+        return index;
+      }
+    }
+
+    return -1
   }
 };
--- a/dom/media/tests/mochitest/test_peerConnection_basicAudio.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudio.html
@@ -9,17 +9,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="head.js"></script>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=796888">Basic audio-only peer connection</a>
 <p id="display"></p>
-<div id="content" style="">
+<div id="content" style="display: none">
   <audio id="audioPCLocal" controls></audio>
   <audio id="audioPCRemote" controls></audio>
   <audio id="audioLocal" controls></audio>
 </div>
 <pre id="test">
 <script type="application/javascript">
   var audioLocal;
   var audioPCLocal;
@@ -69,30 +69,29 @@ https://bugzilla.mozilla.org/show_bug.cg
         audioLocal.play();
 
         PeerConnection.handShake(pcLocal, pcRemote, function () {
           is(pcLocal.localStreams.length, 1,
              "A single local stream has been attached to the local peer");
           is(pcRemote.localStreams.length, 1,
              "A single local stream has been attached to the remote peer");
 
-          // Bug 816780 - onaddstream() gets called twice even if only audio or audio is requested
           is(test_data.pcLocal.audio.length, 1,
              "A remote audio stream has been attached to the local peer");
-          todo_is(test_data.pcLocal.video.length, 0,
-                  "No remote video stream has been attached to the local peer");
+          is(test_data.pcLocal.video.length, 0,
+             "A temporary remote video stream has been attached to the local peer");
           is(test_data.pcRemote.audio.length, 1,
              "A remote audio stream has been attached to the remote peer");
-          todo_is(test_data.pcRemote.video.length, 0,
-                  "No remote video stream has been attached to the remote peer");
+          is(test_data.pcRemote.video.length, 0,
+             "A temporary remote video stream has been attached to the remote peer");
 
-          is(test_data.pcLocal.audio[0], pcLocal.remoteStreams[0],
-             "Remote stream for local peer is accessible");
-          is(test_data.pcRemote.audio[0], pcRemote.remoteStreams[0],
-             "Remote stream for remote peer is accessible");
+          ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.audio[0]) !== -1,
+             "Remote audio stream for local peer is accessible");
+          ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.audio[0]) !== -1,
+             "Remote audio stream for remote peer is accessible");
 
           info("For now simply disconnect. We will add checks for media in a follow-up bug");
           disconnect();
         });
       }, unexpectedCallbackAndFinish);
     }, unexpectedCallbackAndFinish);
   });
 
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html
@@ -0,0 +1,156 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=796890
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Basic video-only peer connection</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=796890">Basic audio-video peer connection</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <audio id="audioPCLocal" controls></audio>
+  <audio id="audioPCRemote" controls></audio>
+  <audio id="audioLocal" controls></audio>
+
+  <video id="videoPCLocal" width="160" height="120" controls></video>
+  <video id="videoPCRemote" width="160" height="120" controls></video>
+  <video id="videoLocal" width="160" height="120" controls></video>
+</div>
+<pre id="test">
+<script type="application/javascript">
+  var audioLocal;
+  var audioPCLocal;
+  var audioPCRemote;
+
+  var videoLocal;
+  var videoPCLocal;
+  var videoPCRemote;
+
+  var pcLocal;
+  var pcRemote;
+
+  var test_data = {
+    pcLocal: { audio: [], video: []},
+    pcRemote: { audio: [], video: []}
+  };
+
+  runTest(function () {
+    audioLocal = document.getElementById("audioLocal");
+    audioPCLocal = document.getElementById("audioPCLocal");
+    audioPCRemote = document.getElementById("audioPCRemote");
+
+    videoLocal = document.getElementById("videoLocal");
+    videoPCLocal = document.getElementById("videoPCLocal");
+    videoPCRemote = document.getElementById("videoPCRemote");
+
+    pcLocal = new mozRTCPeerConnection();
+    pcRemote = new mozRTCPeerConnection();
+
+    pcLocal.onaddstream = function (aObj) {
+      test_data.pcLocal[aObj.type].push(aObj.stream);
+
+      switch (aObj.type) {
+        case "audio":
+          audioPCRemote.mozSrcObject = aObj.stream;
+          audioPCRemote.play();
+          break;
+        case "video":
+          videoPCRemote.mozSrcObject = aObj.stream;
+          videoPCRemote.play();
+          break;
+        default:
+          ok(false, "Not supported type of MediaStream for local peer: " + aObj.type);
+      }
+    };
+
+    pcRemote.onaddstream = function (aObj) {
+      test_data.pcRemote[aObj.type].push(aObj.stream);
+
+      switch (aObj.type) {
+        case "audio":
+          audioPCLocal.mozSrcObject = aObj.stream;
+          audioPCLocal.play();
+          break;
+        case "video":
+          videoPCLocal.mozSrcObject = aObj.stream;
+          videoPCLocal.play();
+          break;
+        default:
+          ok(false, "Not supported type of MediaStream for remote peer: " + aObj.type);
+      }
+    };
+
+    navigator.mozGetUserMedia({audio: true, fake: true},
+                              function onSuccess(aLocalAudioInputStream) {
+      pcLocal.addStream(aLocalAudioInputStream);
+
+      audioLocal.mozSrcObject = aLocalAudioInputStream;
+      audioLocal.play();
+
+      navigator.mozGetUserMedia({video: true, fake: true},
+                                function onSuccess(aLocalVideoInputStream) {
+        pcLocal.addStream(aLocalVideoInputStream);
+
+        videoLocal.mozSrcObject = aLocalVideoInputStream;
+        videoLocal.play();
+
+        navigator.mozGetUserMedia({audio: true, fake: true},
+                                  function onSuccess(aRemoteAudioInputStream) {
+          pcRemote.addStream(aRemoteAudioInputStream);
+
+          navigator.mozGetUserMedia({video: true, fake: true},
+                                    function onSuccess(aRemoteVideoInputStream) {
+            pcRemote.addStream(aRemoteVideoInputStream);
+
+            PeerConnection.handShake(pcLocal, pcRemote, function () {
+              is(pcLocal.localStreams.length, 2,
+                 "Two local streams have been attached to the local peer");
+              is(pcRemote.localStreams.length, 2,
+                 "Two local local streams have been attached to the remote peer");
+
+              is(test_data.pcLocal.video.length, 1,
+                 "A remote video stream has been attached to the local peer");
+              is(test_data.pcLocal.audio.length, 1,
+                 "A remote audio stream has been attached to the local peer");
+              is(test_data.pcRemote.video.length, 1,
+                 "A remote video stream has been attached to the remote peer");
+              is(test_data.pcRemote.audio.length, 1,
+                 "A remote audio stream has been attached to the remote peer");
+
+              ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.audio[0]) !== -1,
+                 "Remote audio stream for local peer is accessible");
+              ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.video[0]) !== -1,
+                 "Remote video stream for local peer is accessible");
+              ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.audio[0]) !== -1,
+                 "Remote audio stream for remote peer is accessible");
+              ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.video[0]) !== -1,
+                 "Remote video stream for remote peer is accessible");
+
+              info("For now simply disconnect. We will add checks for media in a follow-up bug");
+              disconnect();
+            });
+          }, unexpectedCallbackAndFinish);
+        }, unexpectedCallbackAndFinish);
+      }, unexpectedCallbackAndFinish);
+    }, unexpectedCallbackAndFinish);
+  });
+
+  function disconnect() {
+    pcLocal.close();
+    pcRemote.close();
+
+    info("We can't run any checks and clean-up code due to a crash (see bug 820072)");
+
+    SimpleTest.finish();
+  }
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html
@@ -0,0 +1,144 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=796890
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Basic video-only peer connection</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=796890">Basic audio-video peer connection</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <audio id="audioPCLocal" controls></audio>
+  <audio id="audioPCRemote" controls></audio>
+  <audio id="audioLocal" controls></audio>
+
+  <video id="videoPCLocal" width="160" height="120" controls></video>
+  <video id="videoPCRemote" width="160" height="120" controls></video>
+  <video id="videoLocal" width="160" height="120" controls></video>
+</div>
+<pre id="test">
+<script type="application/javascript">
+  var audioLocal;
+  var audioPCLocal;
+  var audioPCRemote;
+
+  var videoLocal;
+  var videoPCLocal;
+  var videoPCRemote;
+
+  var pcLocal;
+  var pcRemote;
+
+  var test_data = {
+    pcLocal: { audio: [], video: []},
+    pcRemote: { audio: [], video: []}
+  };
+
+  runTest(function () {
+    audioLocal = document.getElementById("audioLocal");
+    audioPCLocal = document.getElementById("audioPCLocal");
+    audioPCRemote = document.getElementById("audioPCRemote");
+
+    videoLocal = document.getElementById("videoLocal");
+    videoPCLocal = document.getElementById("videoPCLocal");
+    videoPCRemote = document.getElementById("videoPCRemote");
+
+    pcLocal = new mozRTCPeerConnection();
+    pcRemote = new mozRTCPeerConnection();
+
+    pcLocal.onaddstream = function (aObj) {
+      test_data.pcLocal[aObj.type].push(aObj.stream);
+
+      switch (aObj.type) {
+        case "audio":
+          audioPCRemote.mozSrcObject = aObj.stream;
+          audioPCRemote.play();
+          break;
+        case "video":
+          videoPCRemote.mozSrcObject = aObj.stream;
+          videoPCRemote.play();
+          break;
+        default:
+          ok(false, "Not supported type of MediaStream for local peer: " + aObj.type);
+      }
+    };
+
+    pcRemote.onaddstream = function (aObj) {
+      test_data.pcRemote[aObj.type].push(aObj.stream);
+
+      switch (aObj.type) {
+        case "audio":
+          audioPCLocal.mozSrcObject = aObj.stream;
+          audioPCLocal.play();
+          break;
+        case "video":
+          videoPCLocal.mozSrcObject = aObj.stream;
+          videoPCLocal.play();
+          break;
+        default:
+          ok(false, "Not supported type of MediaStream for remote peer: " + aObj.type);
+      }
+    };
+
+    navigator.mozGetUserMedia({audio: true, video: true, fake: true},
+                              function onSuccess(aLocalInputStream) {
+      pcLocal.addStream(aLocalInputStream);
+
+      navigator.mozGetUserMedia({audio: true, video: true, fake: true},
+                                function onSuccess(aRemoteInputStream) {
+        pcRemote.addStream(aRemoteInputStream);
+
+        videoLocal.mozSrcObject = aLocalInputStream;
+        videoLocal.play();
+
+        PeerConnection.handShake(pcLocal, pcRemote, function () {
+          is(pcLocal.localStreams.length, 1,
+             "A single local stream has been attached to the local peer");
+          is(pcRemote.localStreams.length, 1,
+             "A single local stream has been attached to the remote peer");
+
+          // Bug 816780 - onaddstream fires twice on a peerconnection when you add a stream with both audio and video
+          is(test_data.pcLocal.video.length, 1,
+             "A remote video stream has been attached to the local peer");
+          is(test_data.pcLocal.audio.length, 1,
+             "A remote audio stream has been attached to the local peer");
+          is(test_data.pcRemote.video.length, 1,
+             "A remote video stream has been attached to the remote peer");
+          is(test_data.pcRemote.audio.length, 1,
+             "A remote audio stream has been attached to the remote peer");
+
+          ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.audio[0]) !== -1,
+             "Remote audio stream for local peer is accessible");
+          ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.video[0]) !== -1,
+             "Remote video stream for local peer is accessible");
+          ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.audio[0]) !== -1,
+             "Remote audio stream for remote peer is accessible");
+          ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.video[0]) !== -1,
+             "Remote video stream for remote peer is accessible");
+
+          info("For now simply disconnect. We will add checks for media in a follow-up bug");
+          disconnect();
+        });
+      }, unexpectedCallbackAndFinish);
+    }, unexpectedCallbackAndFinish);
+  });
+
+  function disconnect() {
+    pcLocal.close();
+    pcRemote.close();
+
+    info("We can't run any checks and clean-up code due to a crash (see bug 820072)");
+
+    SimpleTest.finish();
+  }
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/tests/mochitest/test_peerConnection_basicVideo.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicVideo.html
@@ -4,23 +4,22 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=796888
 -->
 <head>
   <meta charset="utf-8">
   <title>Basic video-only peer connection</title>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="head.js"></script>
-  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=796888">Basic video-only peer connection</a>
 <p id="display"></p>
-<div id="content" style="">
+<div id="content" style="display: none">
   <video id="videoPCLocal" width="160" height="120" controls></video>
   <video id="videoPCRemote" width="160" height="120" controls></video>
   <video id="videoLocal" width="160" height="120" controls></video>
 </div>
 <pre id="test">
 <script type="application/javascript">
   var videoLocal;
   var videoPCLocal;
@@ -70,30 +69,29 @@ https://bugzilla.mozilla.org/show_bug.cg
         videoLocal.play();
 
         PeerConnection.handShake(pcLocal, pcRemote, function () {
           is(pcLocal.localStreams.length, 1,
              "A single local stream has been attached to the local peer");
           is(pcRemote.localStreams.length, 1,
              "A single local stream has been attached to the remote peer");
 
-          // Bug 816780 - onaddstream() gets called twice even if only video or audio is requested
           is(test_data.pcLocal.video.length, 1,
-             "A remote audio stream has been attached to the local peer");
-          todo_is(test_data.pcLocal.audio.length, 0,
-                  "No remote video stream has been attached to the local peer");
+             "A remote video stream has been attached to the local peer");
+          is(test_data.pcLocal.audio.length, 0,
+             "A temporary remote audio stream has been attached to the local peer");
           is(test_data.pcRemote.video.length, 1,
-             "A remote audio stream has been attached to the remote peer");
-          todo_is(test_data.pcRemote.audio.length, 0,
-                  "No remote video stream has been attached to the remote peer");
+             "A remote video stream has been attached to the remote peer");
+          is(test_data.pcRemote.audio.length, 0,
+             "A temporary remote audio stream has been attached to the remote peer");
 
-          todo_is(test_data.pcLocal.video[0], pcLocal.remoteStreams[0],
-                  "Remote stream for local peer is accessible");
-          todo_is(test_data.pcRemote.video[0], pcRemote.remoteStreams[0],
-                  "Remote stream for remote peer is accessible");
+          ok(PeerConnection.findStream(pcLocal.remoteStreams, test_data.pcLocal.video[0]) !== -1,
+             "Remote video stream for local peer is accessible");
+          ok(PeerConnection.findStream(pcRemote.remoteStreams, test_data.pcRemote.video[0]) !== -1,
+             "Remote video stream for remote peer is accessible");
 
           info("For now simply disconnect. We will add checks for media in a follow-up bug");
           disconnect();
         });
       }, unexpectedCallbackAndFinish);
     }, unexpectedCallbackAndFinish);
   });