Bug 1033885 - tests for mediaDevices.getUserMedia. r=drno
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 27 Oct 2014 15:48:37 -0400
changeset 212825 162d085b801959d019e45c64cb237d3b17b67da7
parent 212824 a461238e8fb2a708acd4f000ae2d03a87f87ee4f
child 212826 3a8b152acd9c569a66b7f44fc12f0162b2c867e0
push id27730
push usercbook@mozilla.com
push dateWed, 29 Oct 2014 12:26:03 +0000
treeherdermozilla-central@fe5c1cb8075a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1033885
milestone36.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 1033885 - tests for mediaDevices.getUserMedia. r=drno
dom/media/tests/mochitest/constraints.js
dom/media/tests/mochitest/test_getUserMedia_peerIdentity.html
dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
--- a/dom/media/tests/mochitest/constraints.js
+++ b/dom/media/tests/mochitest/constraints.js
@@ -43,34 +43,32 @@ var common_tests = [
                                        { facingMode:'user' },
                                        { bar:0 }] } },
     error: null }
 ];
 
 
 /**
  * Starts the test run by running through each constraint
- * test by verifying that the right callback and error message is fired.
+ * test by verifying that the right resolution and rejection is fired.
  */
 
 function testConstraints(tests) {
-  var i = 0;
-  next();
-
-  function Success() {
-    ok(!tests[i].error, tests[i].message);
-    i++;
-    next();
+  function testgum(p, test) {
+    return p.then(function() {
+      return navigator.mediaDevices.getUserMedia(test.constraints);
+    })
+    .then(function() {
+      is(null, test.error, test.message);
+    }, function(reason) {
+      is(reason.name, test.error, test.message + ": " + reason.message);
+    });
   }
-  function Failure(err) {
-    ok(tests[i].error? (err.name == tests[i].error) : false,
-       tests[i].message + " (err=" + err.name + ")");
-    i++;
-    next();
-  }
-  function next() {
-    if (i < tests.length) {
-      navigator.mozGetUserMedia(tests[i].constraints, Success, Failure);
-    } else {
-      SimpleTest.finish();
-    }
-  }
-};
+
+  var p = new Promise(function(resolve) { resolve(); });
+  tests.forEach(function(test) {
+    p = testgum(p, test);
+  });
+  p.catch(function(reason) {
+    ok(false, "Unexpected failure: " + reason.message);
+  })
+  .then(SimpleTest.finish);
+}
--- a/dom/media/tests/mochitest/test_getUserMedia_peerIdentity.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_peerIdentity.html
@@ -21,29 +21,30 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script type="application/javascript">
 function theTest() {
   function testPeerIdentityConstraint(withConstraint, done) {
     var config = { audio: true, video: true, fake: true };
     if (withConstraint) {
       config.peerIdentity = 'user@example.com';
     }
     info('getting media with constraints: ' + JSON.stringify(config));
-    navigator.mozGetUserMedia(config, function(stream) {
+    navigator.mediaDevices.getUserMedia(config).then(function(stream) {
       var oneDone = false;
       function checkDone() {
         if (oneDone) {
           done();
         }
         oneDone = true;
       }
       var cancelAudioCheck = audioIsSilence(withConstraint, stream, checkDone);
       var cancelVideoCheck = videoIsBlack(withConstraint, stream, checkDone);
       setTimeout(cancelAudioCheck, 3*60*1000);
       setTimeout(cancelVideoCheck, 3*60*1000);
-    }, function(e) {
+    })
+    .catch(function(e) {
       ok(false, 'gUM error: ' + e);
     });
   };
 
   // without constraint
   testPeerIdentityConstraint(false, function() {
     // with the constraint
     testPeerIdentityConstraint(true, SimpleTest.finish.bind(SimpleTest));
--- a/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
+++ b/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
@@ -32,33 +32,33 @@
     var flowtest = test.chain.remove("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
     test.chain.append(flowtest);
     test.chain.append([["PC_LOCAL_REPLACE_VIDEOTRACK",
       function (test) {
         var stream = test.pcLocal._pc.getLocalStreams()[0];
         var track = stream.getVideoTracks()[0];
         var sender = test.pcLocal._pc.getSenders().find(isSenderOfTrack, track);
         ok(sender, "track has a sender");
-        navigator.mozGetUserMedia({video:true, fake: true}, function(newStream) {
+        navigator.mediaDevices.getUserMedia({video:true, fake: true})
+        .then(function(newStream) {
           var newtrack = newStream.getVideoTracks()[0];
-          sender.replaceTrack(newtrack,
-            function() {
-              ok(true, "replaceTrack success callback is called");
-              is(sender.track, newtrack, "sender.track has been replaced");
-              test.next();
-            },
-            function(err) {
-              ok(false, "replaceTrack failed with error = " + err);
-              test.next();
-            });
-        },
-        function(err) {
-          ok(false, "mozGetUserMedia failed. error = " + err);
-          test.next();
-        });
+          return new Promise(function(resolve, reject) {
+            sender.replaceTrack(newtrack, function() {
+              resolve(newtrack);
+            }, reject);
+          });
+        })
+        .then(function(newtrack) {
+          ok(true, "replaceTrack success callback is called");
+          is(sender.track, newtrack, "sender.track has been replaced");
+        })
+        .catch(function(reason) {
+          ok(false, "unexpected error = " + reason.message);
+        })
+        .then(test.next.bind(test));
       }
     ]]);
     test.chain.append(flowtest);
 
     test.run();
   });
 </script>
 </pre>