Bug 796888 - Create Mochitest for Video only connection (connect/disconnect). r=jesup
authorHenrik Skupin <hskupin@mozilla.com>
Thu, 13 Dec 2012 21:38:49 +0100
changeset 115972 2fc7800b9847e6ace0f0b6f10a99aa99cda59d0a
parent 115971 a41d57f0102000c6007738736ffbe3fb13ce86e7
child 115973 b6d87e6d9a7eff726f6534bf0c34b2e33f0da3e2
push id24034
push useremorley@mozilla.com
push dateFri, 14 Dec 2012 15:28:57 +0000
treeherdermozilla-central@50d8f411d305 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs796888
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 796888 - Create Mochitest for Video only connection (connect/disconnect). r=jesup
dom/media/tests/mochitest/Makefile.in
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/test_peerConnection_basicVideo.html
--- a/dom/media/tests/mochitest/Makefile.in
+++ b/dom/media/tests/mochitest/Makefile.in
@@ -12,19 +12,21 @@ include $(DEPTH)/config/autoconf.mk
 
 # Bug 814718 prevents us from running the following test:
 #  test_getUserMedia_basicVideo.html
 
 MOCHITEST_FILES = \
   test_getUserMedia_exceptions.html \
   head.js \
   mediaStreamPlayback.js \
+  pc.js \
   $(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_basicVideo.html \
   $(NULL)
 endif
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/pc.js
@@ -0,0 +1,44 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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,
+
+  handShake: function PC_handShake(aPCLocal, aPCRemote, aSuccessCallback) {
+
+    function onCreateOfferSuccess(aOffer) {
+      pc1_offer = aOffer;
+      aPCLocal.setLocalDescription(aOffer, onSetLocalDescriptionSuccess1,
+                                   unexpectedCallbackAndFinish);
+    }
+
+    function onSetLocalDescriptionSuccess1() {
+      aPCRemote.setRemoteDescription(pc1_offer, onSetRemoteDescriptionSuccess1,
+                                     unexpectedCallbackAndFinish);
+    }
+
+    function onSetRemoteDescriptionSuccess1() {
+      aPCRemote.createAnswer(onCreateAnswerSuccess, unexpectedCallbackAndFinish);
+    }
+
+    function onCreateAnswerSuccess(aAnswer) {
+      pc2_answer = aAnswer;
+      aPCRemote.setLocalDescription(aAnswer, onSetLocalDescriptionSuccess2,
+                                    unexpectedCallbackAndFinish);
+    }
+
+    function onSetLocalDescriptionSuccess2() {
+      aPCLocal.setRemoteDescription(pc2_answer, onSetRemoteDescriptionSuccess2,
+                                    unexpectedCallbackAndFinish);
+    }
+
+    function onSetRemoteDescriptionSuccess2() {
+      aSuccessCallback();
+    }
+
+    aPCLocal.createOffer(onCreateOfferSuccess, unexpectedCallbackAndFinish);
+  }
+};
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_basicVideo.html
@@ -0,0 +1,103 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+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="">
+  <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;
+  var videoPCRemote;
+
+  var pcLocal;
+  var pcRemote;
+
+  var test_data = {
+    pcLocal: [],
+    pcRemote: []
+  };
+
+  runTest(function () {
+    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'].push(aObj);
+
+      if (aObj.type === "video") {
+        videoPCRemote.mozSrcObject = aObj.stream;
+        videoPCRemote.play();
+      }
+    };
+
+    pcRemote.onaddstream = function (aObj) {
+      test_data['pcRemote'].push(aObj);
+
+      if (aObj.type === "video") {
+        videoPCLocal.mozSrcObject = aObj.stream;
+        videoPCLocal.play();
+      }
+    };
+
+    navigator.mozGetUserMedia({video: true, fake: true}, function onSuccess(aLocalInputStream) {
+      pcLocal.addStream(aLocalInputStream);
+
+      navigator.mozGetUserMedia({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() gets called twice even if only video or audio is requested
+          todo_is(test_data.pcLocal.length, 1, "Only one stream has been attached to the local peer");
+          todo_is(test_data.pcLocal[0].type, "video", "Video stream has been attached to the local peer");
+          todo_is(test_data.pcRemote.length, 1, "Only one stream has been attached to the remote peer");
+          todo_is(test_data.pcRemote[0].type, "video", "Video stream has been attached to the remote peer");
+
+          is(test_data.pcLocal[0].stream, pcLocal.remoteStreams[0], "Remote stream for local peer is accessible");
+          is(test_data.pcRemote[0].stream, pcRemote.remoteStreams[0], "Remote 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>