Bug 866514 - Basic gUM mochitests for media stream tracks. r=roc, a=akeybl
authorJason Smith <jsmith@mozilla.com>
Sun, 05 May 2013 19:48:37 -0700
changeset 137609 8f3fb4aa0107a5000ba76e6d6163433c58c4e696
parent 137608 9d0d2d5e649759a5013907f0d9c881f299a90fd1
child 137610 dd4d3bc92ee8c4cc6c36d2dec2c29ca0aafbd371
push id2457
push userryanvm@gmail.com
push dateTue, 14 May 2013 13:50:32 +0000
treeherdermozilla-beta@8f3fb4aa0107 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, akeybl
bugs866514
milestone22.0
Bug 866514 - Basic gUM mochitests for media stream tracks. r=roc, 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);