test for mediastream constructor
authorDominique Hazael-Massieux <dom@w3.org>
Tue, 04 Jun 2013 18:43:43 +0200
changeset 74 b167dd7bae36
parent 73 e3113bce02ba
child 75 0576b21710f5
test for mediastream constructor
submitted/W3C/mediastream-constructor.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/submitted/W3C/mediastream-constructor.html	Tue Jun 04 18:43:43 2013 +0200
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+<head>
+<title>MediaStream constructor algorithm</title>
+<link rel="author" title="Dominique Hazael-Massieux" href="mailto:[email protected]"/>
+<link rel="help" href="http://dev.w3.org/2011/webrtc/editor/getusermedia.html#navigatorusermedia">
+<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
+</head>
+<body>
+<p>When prompted, accept to share your video and audio stream.</p>
+<h1>Description</h1>
+<p>This test checks that the MediaStream constructor follows the algorithm set in the spec.</p>
+
+<div id='log'></div>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=featuredetection.js></script>
+<script src=prefix.js></script>
+<script>
+var t = async_test("Tests that a MediaStream constructor follows the algorithm set in the spec", {timeout: 10000});
+t.step(function() {
+  navigator.getUserMedia({video: true, audio:true}, t.step_func(function (stream) {
+    var stream1 = new MediaStream();
+    assert_not_equals(stream.id, stream1.id, "Two different MediaStreams have different ids");
+    var stream2 = new MediaStream(stream);
+    assert_not_equals(stream.id, stream2.id, "A MediaStream constructed from another have different ids");
+    var audioTrack1 = stream.getAudioTracks()[0];
+    var videoTrack = stream.getVideoTracks()[0];
+    assert_equals(audioTrack1, stream2.getAudioTracks()[0], "A MediaStream constructed from another share the same audio track");
+    assert_equals(videoTrack, stream2.getVideoTracks()[0], "A MediaStream constructed from another share the same video track");
+    var stream4 = new MediaStream([audioTrack1]);
+    assert_equals(stream4.getTrackById(audioTrack1.id), audioTrack1, "a non-ended track gets added via the MediaStream constructor");
+
+    var audioTrack2 = audioTrack1.clone();
+    audioTrack2.addEventListener("ended", t.step_func(function () {      
+      var stream3 = new MediaStream([audioTrack2, videoTrack]);
+      assert_equals(stream3.getTrackById(audioTrack2.id), null, "an ended track doesn't get added via the MediaStream constructor");
+      assert_equals(stream3.getTrackById(videoTrack.id), videoTrack, "a non-ended track gets added via the MediaStream constructor even if the previous track was ended");
+      t.done();
+    }, false);
+    audioTrack2.stop();
+  }), function(error) {});
+});
+</script>
+</body>
+</html>