test for media assignment
authorDominique Hazael-Massieux <dom@w3.org>
Mon, 03 Jun 2013 17:28:19 +0200
changeset 54 7247f3d5ec34
parent 53 dd1505cf2848
child 55 c65aa59152e4
test for media assignment
submitted/W3C/video-assignment.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/submitted/W3C/video-assignment.html	Mon Jun 03 17:28:19 2013 +0200
@@ -0,0 +1,65 @@
+<!doctype html>
+<html>
+<head>
+<title>Assigning mediastream to a video element</title>
+<link rel="author" title="Dominique Hazael-Massieux" href="mailto:dom@w3.org"/>
+<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 stream.</p>
+<h1>Description</h1>
+<p>This test checks that the MediaStream object returned by the success callback in getUserMedia can be properly assigned to a video element via the <code>srcObject</code> attribute.</p>
+
+<video id="vid"></video>
+
+<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 vid = document.getElementById("vid");
+var t = async_test("Tests that a MediaStream can be assigned to a video element with srcObject", {timeout: 10000});
+t.step(function() {
+  navigator.getUserMedia({video: true}, t.step_func(function (stream) {
+    // TODO remove when prefixes are gone
+    var srcObj = BrowserHasFeature(vid, "srcObject");
+    if (!vid.srcObject && undefined !== srcObj) {
+       vid.srcObject = srcObj;
+    } 
+    vid.addEventListener("timeupdate", t.step_func(function() {
+       assert_equals(vid.played.length, 1, "A MediaStream's timeline always consists of a single range");
+       assert_equals(vid.played.start(0), 0, "A MediaStream's timeline always consists of a single range");
+       assert_equals(vid.played.end(0), vid.currentTime, "A MediaStream's timeline always consists of a single range");
+       assert_equals(vid.readyState, vid.HAVE_ENOUGH_DATA, "Upon selecting a media stream, the UA sets readyState to HAVE_ENOUGH_DATA");
+       var t = vid.currentTime;
+       vid.currentTime = 0;
+       assert_equals(vid.currentTime, t, "The UA MUST ignore attempts to set the currentTime attribute");
+       // TODO add test that duration must be set to currentTime 
+       // when mediastream is destroyed
+       t.done();
+       
+    }), false);
+
+    vid.srcObject = stream;
+    vid.play();
+    assert_true(!vid.seeking, "A MediaStream is not seekable");
+    assert_equals(vid.seekable.length, 0, "A MediaStream is not seekable");
+    assert_equals(vid.defaultPlaybackRate, 1, "playback rate is always 1");
+    assert_equals(vid.playbackRate, 1, "playback rate is always 1");
+    assert_equals(vid.preload, "none", "A MediaStream cannot be preloaded.");
+    // not as in spec, see https://www.w3.org/Bugs/Public/show_bug.cgi?id=22246
+    assert_equals(vid.buffered.length, 0, "A MediaStream cannot be preloaded.  Therefore, there is no buffered timeranges");
+    assert_equals(vid.duration, Infinity, " A MediaStream does not have a pre-defined duration. ");
+    assert_equals(vid.startDate, NaN, " A MediaStream does not specify a timeline offset");
+    assert_true(!vid.loop, "A MediaStream cannot be looped");
+    vid.loop = true;
+    // not sure about that one https://www.w3.org/Bugs/Public/show_bug.cgi?id=22247
+    assert_true(!vid.loop, "Setting looped to true in a MediaStream is a no-op");
+    t.done();
+  }), function(error) {});
+});
+</script>
+</body>
+</html>