Bug 866514: reland since this isn't the cause of bug 870002 rs=me a=akeybl
authorRandell Jesup <rjesup@jesup.org>
Tue, 04 Jun 2013 13:45:10 -0400
changeset 137745 f53c829089202f7a1e30c958f48dff78b0d52c3a
parent 137744 0ed8a89f8484c157ed6b7233d7944457821e57da
child 137746 18cbe54e3c88358c3f389f5062f81899014fb16a
push id2540
push userrjesup@wgate.com
push dateTue, 04 Jun 2013 17:47:00 +0000
treeherdermozilla-beta@f53c82908920 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, akeybl
bugs866514, 870002
milestone22.0
Bug 866514: reland since this isn't the cause of bug 870002 rs=me a=akeybl
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/test_getUserMedia_basicAudio.html
dom/media/tests/mochitest/test_getUserMedia_basicVideo.html
dom/media/tests/mochitest/test_getUserMedia_basicVideoAudio.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -135,16 +135,54 @@ function runTest(aCallback, desktopSuppo
         unexpectedCallbackAndFinish(err);
       }
     });
   }
 }
 
 
 /**
+ * Checks that the media stream tracks have the expected amount of tracks
+ * with the correct kind and id based on the type and constraints given.
+ *
+ * @param {Object} constraints specifies whether the stream should have
+ *                             audio, video, or both
+ * @param {String} type the type of media stream tracks being checked
+ * @param {sequence<MediaStreamTrack>} mediaStreamTracks the media stream
+ *                                     tracks being checked
+ */
+function checkMediaStreamTracksByType(constraints, type, mediaStreamTracks) {
+  if(constraints[type]) {
+    is(mediaStreamTracks.length, 1, 'One ' + type + ' track shall be present');
+
+    if(mediaStreamTracks.length) {
+      is(mediaStreamTracks[0].kind, type, 'Track kind should be ' + type);
+      ok(mediaStreamTracks[0].id, 'Track id should be defined');
+    }
+  } else {
+    is(mediaStreamTracks.length, 0, 'No ' + type + ' tracks shall be present');
+  }
+}
+
+/**
+ * Check that the given media stream contains the expected media stream
+ * tracks given the associated audio & video constraints provided.
+ *
+ * @param {Object} constraints specifies whether the stream should have
+ *                             audio, video, or both
+ * @param {MediaStream} mediaStream the media stream being checked
+ */
+function checkMediaStreamTracks(constraints, mediaStream) {
+  checkMediaStreamTracksByType(constraints, 'audio',
+    mediaStream.getAudioTracks());
+  checkMediaStreamTracksByType(constraints, 'video',
+    mediaStream.getVideoTracks());
+}
+
+/**
  * A callback function fired only under unexpected circumstances while
  * running the tests. Kills off the test as well gracefully.
  *
  * @param {object} aObj
  *        The object fired back from the callback
  */
 function unexpectedCallbackAndFinish(aObj) {
   if (aObj && aObj.name && aObj.message) {
--- a/dom/media/tests/mochitest/test_getUserMedia_basicAudio.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicAudio.html
@@ -20,20 +20,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script type="application/javascript">
   /**
    * Run a test to verify that we can complete a start and stop media playback
    * cycle for an audio LocalMediaStream on an audio HTMLMediaElement.
    */
   runTest(function () {
     var testAudio = document.getElementById('testAudio');
+    var constraints = {audio: true};
 
-    getUserMedia({audio: true}, function (aStream) {
+    getUserMedia(constraints, function (aStream) {
+      checkMediaStreamTracks(constraints, aStream);
+
       var playback = new LocalMediaStreamPlayback(testAudio, aStream);
-
       playback.playMedia(false, function () {
         aStream.stop();
         SimpleTest.finish();
       }, unexpectedCallbackAndFinish);
 
     }, unexpectedCallbackAndFinish);
 
   }, true);
--- a/dom/media/tests/mochitest/test_getUserMedia_basicVideo.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicVideo.html
@@ -20,20 +20,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script type="application/javascript">
   /**
    * Run a test to verify that we can complete a start and stop media playback
    * cycle for an video LocalMediaStream on a video HTMLMediaElement.
    */
   runTest(function () {
     var testVideo = document.getElementById('testVideo');
+    var constraints = {video: true};
 
-    getUserMedia({video: true}, function (aStream) {
+    getUserMedia(constraints, function (aStream) {
+      checkMediaStreamTracks(constraints, aStream);
+
       var playback = new LocalMediaStreamPlayback(testVideo, aStream);
-
       playback.playMedia(false, function () {
         aStream.stop();
         SimpleTest.finish();
       }, unexpectedCallbackAndFinish);
 
     }, unexpectedCallbackAndFinish);
 
   }, true);
--- a/dom/media/tests/mochitest/test_getUserMedia_basicVideoAudio.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicVideoAudio.html
@@ -20,20 +20,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script type="application/javascript">
   /**
    * Run a test to verify that we can complete a start and stop media playback
    * cycle for a video and audio LocalMediaStream on a video HTMLMediaElement.
    */
   runTest(function () {
     var testVideoAudio = document.getElementById('testVideoAudio');
+    var constraints = {video: true, audio: true};
 
-    getUserMedia({video: true, audio: true}, function (aStream) {
+    getUserMedia(constraints, function (aStream) {
+      checkMediaStreamTracks(constraints, aStream);
+
       var playback = new LocalMediaStreamPlayback(testVideoAudio, aStream);
-
       playback.playMedia(false, function () {
         aStream.stop();
         SimpleTest.finish();
       }, unexpectedCallbackAndFinish);
 
     }, unexpectedCallbackAndFinish);
   }, true);