various fixes, incl. avoiding feature detection
authorDominique Hazaël-Massieux <dom@w3.org>
Fri, 15 Jun 2012 15:08:33 +0200
changeset 27 cebb63d26a31
parent 26 de85fe3f590f
child 28 dccd708b64df
various fixes, incl. avoiding feature detection
submitted/W3C/audio.html
submitted/W3C/deny.html
submitted/W3C/empty-option-param.html
submitted/W3C/localstream-stop.html
submitted/W3C/mediastreamtrack-end.html
submitted/W3C/mediastreamtrack-init.html
submitted/W3C/mediastreamtracklist-add.html
submitted/W3C/mediastreamtracklist-finished.html
submitted/W3C/mediastreamtracklist-remove.html
submitted/W3C/mediastreamtracklist.html
submitted/W3C/stream-ended.html
submitted/W3C/stream-label.html
submitted/W3C/unknownkey-option-param.html
submitted/W3C/video.html
--- a/submitted/W3C/audio.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/audio.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,16 +18,14 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that a MediaStream with at least one audio track is returned");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({audio:true}, function (stream) {
-  t.step(function () { 
-     assert_true(stream instanceof LocalMediaStream, "getUserMedia success callback comes with a LocalMediaStream object");
-     assert_true(stream.audioTracks.length >= 1, "the media stream has at least one audio track");
-     assert_equals(stream.videoTracks.length, 0, "the media stream has zero video track");
-  });
-  t.done();
+t.step(function() {
+  navigator.getUserMedia({audio:true}, t.step_func(function (stream) {
+    assert_true(stream instanceof LocalMediaStream, "getUserMedia success callback comes with a LocalMediaStream object");
+    assert_true(stream.audioTracks.length >= 1, "the media stream has at least one audio track");
+    assert_equals(stream.videoTracks.length, 0, "the media stream has zero video track");
+    t.done();
+  }));
 });
-}
 </script>
 </body>
 </html>
--- a/submitted/W3C/deny.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/deny.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,20 +18,16 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that the error callback is triggered when permission is denied");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({video: true}, function (stream) {
-    t.step(function () {
-      assert_unreached("The success callback should not be triggered since access is to be denied");
-      t.done();
-    });
-  }, function (error) {
-    t.step(function () {
-      console.log(error);
-      assert_equals(error.code, 1, "Error code 1 is returned for permission denied");
-      t.done();
-    });
-  });
-}
+t.step(function() {
+  navigator.getUserMedia({video: true}, t.step_func(function (stream) {
+    assert_unreached("The success callback should not be triggered since access is to be denied");
+    t.done();
+  }),
+  t.step_func(function (error) {
+    assert_equals(error.code, 1, "Error code 1 is returned for permission denied");
+    t.done();
+  }));
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/empty-option-param.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/empty-option-param.html	Fri Jun 15 15:08:33 2012 +0200
@@ -17,18 +17,17 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that getUserMedia raises a NOT_SUPPORTED_ERR exception when used with an empty options parameter");
-if (window.navigator.getUserMedia) { 
-  t.step( function () {
-     assert_throws("NOT_SUPPORTED_ERR", 
-                   function () { 
-                     navigator.getUserMedia({}, function (stream) {
-                       assert_unreached("This should never be triggered since doesnotexist is not a valid key for the options parameter");
-                       t.done();
-                     })
-                   });
-     t.done();
+t.step( function () {
+  assert_throws("NOT_SUPPORTED_ERR", 
+    function () { 
+      navigator.getUserMedia({}, function (stream) {
+        assert_unreached("This should never be triggered since the constraints parameter is empty");
+        t.done();
+      })
   });
-}
+  t.done();
+});
+
 </script>
 </body>
 </html>
--- a/submitted/W3C/localstream-stop.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/localstream-stop.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,14 +18,12 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that a LocalMediaStream handles stop() correctly");
-if (window.navigator.getUserMedia) { 
+t.step(function () {
   navigator.getUserMedia({video:true}, function (stream) {
     // onended is not supposed to be fired when stop() is invoked
-    stream.onended = function () {
-      t.step(function () { 
-        assert_unreached("onended is not fired when stop is invoked");
-        t.done();
-      });
+    stream.onended = t.step_func(function () {
+      assert_unreached("onended is not fired when stop is invoked");
+      t.done();
     };
 
     stream.stop();
@@ -37,7 +35,7 @@
       t.done();
     });
   });
-}
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtrack-end.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtrack-end.html	Fri Jun 15 15:08:33 2012 +0200
@@ -17,42 +17,41 @@
 <script src=featuredetection.js></script>
 <script src=prefix.js></script>
 <script>
-var t = async_test("Tests that the video MediaStreamTrack objects are properly ended on permission revocation");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia("audio,video", function (stream) {
-    t.step(function () { 
-     for (var i = 0 ; i < stream.videoTracks.length ; i++) {
-        var track = stream.videoTracks[i];
+var t = async_test("Tests that the video MediaStreamTrack objects are properly ended on permission revocation", {timeout: 10000}); // longer timeout since requires user interaction
+t.step(function () {
+  navigator.getUserMedia({audio: true,video: true}, t.step_func(function (stream) {
+    for (var i = 0 ; i < stream.videoTracks.length ; i++) {
+      var track = stream.videoTracks[i];
 	assert_equals(track.readyState, track.LIVE, "The video track object #" + i + " is in live state");
-     }
-     for (var i = 0 ; i < stream.audioTracks.length ; i++) {
-        var track = stream.audioTracks[i];
-	assert_equals(track.readyState, track.LIVE, "The audio track object #" + i + " is in live state");
-     }
+    }
+    for (var i = 0 ; i < stream.audioTracks.length ; i++) {
+      var track = stream.audioTracks[i];
+      assert_equals(track.readyState, track.LIVE, "The audio track object #" + i + " is in live state");
+    }
+    t.step(function () {
+      stream.audioTracks[0].readyState = stream.audioTracks[0].ENDED;
+      assert_equals(track.readyState, track.ENDED, "The audio track object #0 is in ended state");
+      stream.audioTracks[0].onended = function () { 
+        assert_unreached("The ended event is not supposed to be sent since the track was already in ended state");
+        t.done();
+      };
     });
     t.step(function () {
-       stream.audioTracks[0].readyState = stream.audioTracks[0].ENDED;
-       assert_equals(track.readyState, track.LIVE, "The audio track object #0 is in ended state");
-       stream.audioTracks[0].onended = function () { 
-         assert_unreached("The ended event is not supposed to be sent since the track was already in ended state");
-         t.done();
-
-       };
-       stream.videoTracks[0].onended = function () { 
-	 assert_true(true, "Video track #0 has been ended as expected");
-       };
-       for (var i = 0 ; i < stream.videoTracks.length ; i++) {
-         var track = stream.videoTracks[i];
-	 assert_equals(track.readyState, track.ENDED, "The video track object #" + i + " is in ended state");
-       }
-       for (var i = 1 ; i < stream.audioTracks.length ; i++) {
-         var track = stream.audioTracks[i];
-	 assert_equals(track.readyState, track.ENDED, "The audio track object #" + i + " is in ended state");
-       }
-       t.done();
+      stream.videoTracks[0].onended = t.step_func(function () { 
+        assert_true(true, "Video track #0 has been ended as expected");
+        t.done();
+      });
+      for (var i = 0 ; i < stream.videoTracks.length ; i++) {
+        var track = stream.videoTracks[i];
+        assert_equals(track.readyState, track.ENDED, "The video track object #" + i + " is in ended state");
+      }
+      for (var i = 1 ; i < stream.audioTracks.length ; i++) {
+        var track = stream.audioTracks[i];
+        assert_equals(track.readyState, track.ENDED, "The audio track object #" + i + " is in ended state");
+      }
     });
+  }));
 });
-}
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtrack-init.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtrack-init.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,20 +18,18 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that the video MediaStreamTrack objects are properly initialized");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({video: true}, function (stream) {
-  t.step(function () { 
-     for (var i = 0 ; i < stream.videoTracks.length ; i++) {
-        var track = stream.videoTracks[i];
-	assert_true(track instanceof MediaStreamTrack, "The track object #" + i + " is an instance of MediaStreamTrack");
-	assert_equals(track.readyState, track.LIVE, "The track object #" + i + " is in live state");
-	assert_equals(track.kind, "video", "The track object #" + i + " is of video kind");
-	assert_true(track.enabled, "The track object #" + i + " is enabed"); // Not clear that this is required by the spec
-     }
-  });
-  t.done();
+t.step(function () {
+  navigator.getUserMedia({video: true}, t.step_func(function (stream) {
+    for (var i = 0 ; i < stream.videoTracks.length ; i++) {
+      var track = stream.videoTracks[i];
+      assert_true(track instanceof MediaStreamTrack, "The track object #" + i + " is an instance of MediaStreamTrack");
+      assert_equals(track.readyState, track.LIVE, "The track object #" + i + " is in live state");
+      assert_equals(track.kind, "video", "The track object #" + i + " is of video kind");
+      assert_true(track.enabled, "The track object #" + i + " is enabed"); // Not clear that this is required by the spec
+    }
+    t.done();
+  }));
 });
-}
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtracklist-add.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtracklist-add.html	Fri Jun 15 15:08:33 2012 +0200
@@ -17,14 +17,14 @@
 <script src=featuredetection.js></script>
 <script src=prefix.js></script>
 <script>
-var t = async_test("Tests that an addition to a MediaStreamTrackList works as expected");
-if (window.navigator.getUserMedia) { 
+var t = async_test("Tests that an addition to a MediaStreamTrackList works as expected", {timeout: 10000}); // longer timeout since requires double user interaction
+t.step(function () {
   var audio, video;
 
-  navigator.getUserMedia({audio:true}, gotAudio);
+  navigator.getUserMedia({audio: true}, gotAudio);
   function gotAudio(stream) {
     audio = stream;
-    navigator.getUserMedia({video:true}, gotVideo);
+    navigator.getUserMedia({video: true}, gotVideo);
   }
 
   function gotVideo(stream) {
@@ -36,17 +36,17 @@
        video.audioTracks.add(audio.audioTracks[0]);
        assert_equals(video.audioTracks.length, 1, "video mediastream still has one audio track");
     });
-    audio.onaddtrack = function () {
+    audio.onaddtrack = t.step_func(function () {
        assert_true(true, "onaddtrack is triggered on adding a track");
        t.done();
-    };
+    });
     t.step(function () {
        assert_equals(audio.videoTracks.length, 0, "audio mediastream starts with no video track");
        audio.videoTracks.add(video.videoTracks[1]);
        assert_equals(audio.videoTracks.length, 1, "audio mediastream now has one video track");
     });
   }
-}
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtracklist-finished.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtracklist-finished.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,7 +18,7 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that an addition to a finished MediaStream raises an exception");
-if (window.navigator.getUserMedia) { 
+t.step(function () {
   var audio, video;
 
   navigator.getUserMedia({audio:true}, gotAudio);
@@ -40,7 +40,7 @@
      });
     t.done();
   }
-}
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtracklist-remove.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtracklist-remove.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,7 +18,7 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that a removal from a MediaStreamTrackList works as expected");
-if (window.navigator.getUserMedia) { 
+t.step(function () {
   var video;
 
   navigator.getUserMedia({video:true}, gotVideo);
@@ -36,7 +36,7 @@
        t.done();
     };
   }
-}
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/mediastreamtracklist.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/mediastreamtracklist.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,7 +18,7 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that an addition to a MediaStreamTrackList works as expected");
-if (window.navigator.getUserMedia) { 
+t.step(function () {
   var audio, video;
 
   navigator.getUserMedia({audio:true}, gotAudio);
@@ -46,7 +46,7 @@
        assert_equals(audio.videoTracks.length, 1, "audio mediastream now has one video track");
     });
   }
-}
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/stream-ended.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/stream-ended.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,21 +18,17 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that a MediaStream handles ended correctly");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({video:true}, function (stream) {
-    t.step(function () { 
-       assert_true(!stream.ended, "the media stream starts with ended set to false");
-    });
-    stream.addEventListener("ended", function() {
-       t.step(function () {
-           assert_true(stream.ended, "stream.ended now set to true");
-           assert_true(true, "ended event triggered");
-         });
-       t.done();
-       }, false);
+t.step(function () {
+  navigator.getUserMedia("video", t.step_func(function (stream) {
+    assert_true(!stream.ended, "the media stream starts with ended set to false");
+    stream.addEventListener("ended", t.step_func(function() {
+      assert_true(stream.ended, "stream.ended now set to true");
+      assert_true(true, "ended event triggered");
+      t.done();
+      }), false);
     stream.ended = true;
-  });
-}
+  }));
+});
 </script>
 </body>
 </html>
--- a/submitted/W3C/stream-label.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/stream-label.html	Fri Jun 15 15:08:33 2012 +0200
@@ -19,15 +19,13 @@
 <script>
 var t = async_test("Tests that a MediaStream with a correct label is returned");
 var allowedCharacters = /^[\u0021\u0023-\u0027\u002A-\u002B\u002D-\u002E\u0030-\u0039\u0041-\u005A\u005E-\u007E]*$/;
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({video:true}, function (stream) {
-  t.step(function () { 
+t.step(function () {
+  navigator.getUserMedia({video: true}, t.step_func(function (stream) {
      assert_true(stream.label.length === 36, "the media stream label has 36 characters");
      assert_regexp_match(stream.label, allowedCharacters, "the media stream label uses the set of allowed characters");
-  });
-  t.done();
+     t.done();
+  }));
 });
-}
 </script>
 </body>
 </html>
--- a/submitted/W3C/unknownkey-option-param.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/unknownkey-option-param.html	Fri Jun 15 15:08:33 2012 +0200
@@ -16,19 +16,15 @@
 <script src=featuredetection.js></script>
 <script src=prefix.js></script>
 <script>
-var t = async_test("Tests that getUserMedia raises a NOT_SUPPORTED_ERR exception when used with an unknown key in the options parameter");
-if (window.navigator.getUserMedia) { 
-  t.step( function () {
-     assert_throws("NOT_SUPPORTED_ERR", 
-                   function () { 
-                     navigator.getUserMedia({doesnotexist:true}, function (stream) {
-                       assert_unreached("This should never be triggered since doesnotexist is not a valid key for the options parameter");
-                       t.done();
-                     })
-                   });
-     t.done();
-  });
-}
+test(function () {
+  assert_throws("NOT_SUPPORTED_ERR", 
+    function () { 
+      navigator.getUserMedia({doesnotexist:true}, function (stream) {});
+    }
+  )
+  }
+);
+
 </script>
 </body>
 </html>
--- a/submitted/W3C/video.html	Thu May 31 23:13:28 2012 +0200
+++ b/submitted/W3C/video.html	Fri Jun 15 15:08:33 2012 +0200
@@ -18,16 +18,14 @@
 <script src=prefix.js></script>
 <script>
 var t = async_test("Tests that a MediaStream with at least one video track is returned");
-if (window.navigator.getUserMedia) { 
-  navigator.getUserMedia({video:true}, function (stream) {
-  t.step(function () { 
-     assert_true(stream instanceof LocalMediaStream, "getUserMedia success callback comes with a LocalMediaStream object");
-     assert_equals(stream.audioTracks.length, 0, "the media stream has zero audio track");
-     assert_true(stream.videoTracks.length >= 1, "the media stream has at least one video track");
-  });
-  t.done();
+t.step(function() {
+  navigator.getUserMedia({video: true}, t.step_func(function (stream) {
+    assert_true(stream instanceof LocalMediaStream, "getUserMedia success callback comes with a LocalMediaStream object");
+    assert_equals(stream.audioTracks.length, 0, "the media stream has zero audio track");
+    assert_true(stream.videoTracks.length >= 1, "the media stream has at least one video track");
+    t.done();
+  }));
 });
-}
 </script>
 </body>
 </html>