content/media/test/seek1.js

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 function test_seek1(v, seekTime, is, ok, finish) {
michael@0 2
michael@0 3 var startPassed = false;
michael@0 4 var endPassed = false;
michael@0 5 var seekFlagStart = false;
michael@0 6 var seekFlagEnd = false;
michael@0 7 var readonly = true;
michael@0 8 var completed = false;
michael@0 9
michael@0 10 function startTest() {
michael@0 11 if (completed)
michael@0 12 return;
michael@0 13 ok(!v.seeking, "seeking should default to false");
michael@0 14 try {
michael@0 15 v.seeking = true;
michael@0 16 readonly = v.seeking === false;
michael@0 17 }
michael@0 18 catch(e) {
michael@0 19 readonly = "threw exception: " + e;
michael@0 20 }
michael@0 21 is(readonly, true, "seeking should be readonly");
michael@0 22
michael@0 23 v.play();
michael@0 24 v.currentTime=seekTime;
michael@0 25 seekFlagStart = v.seeking;
michael@0 26 }
michael@0 27
michael@0 28 function seekStarted() {
michael@0 29 if (completed)
michael@0 30 return;
michael@0 31 ok(v.currentTime >= seekTime - 0.1,
michael@0 32 "Video currentTime should be around " + seekTime + ": " + v.currentTime + " (seeking)");
michael@0 33 v.pause();
michael@0 34 startPassed = true;
michael@0 35 }
michael@0 36
michael@0 37 function seekEnded() {
michael@0 38 if (completed)
michael@0 39 return;
michael@0 40
michael@0 41 var t = v.currentTime;
michael@0 42 // Since we were playing, and we only paused asynchronously, we can't be
michael@0 43 // sure that we paused before the seek finished, so we may have played
michael@0 44 // ahead arbitrarily far.
michael@0 45 ok(t >= seekTime - 0.1, "Video currentTime should be around " + seekTime + ": " + t + " (seeked)");
michael@0 46 v.play();
michael@0 47 endPassed = true;
michael@0 48 seekFlagEnd = v.seeking;
michael@0 49 }
michael@0 50
michael@0 51 function playbackEnded() {
michael@0 52 if (completed)
michael@0 53 return;
michael@0 54
michael@0 55 completed = true;
michael@0 56 ok(startPassed, "seeking event");
michael@0 57 ok(endPassed, "seeked event");
michael@0 58 ok(seekFlagStart, "seeking flag on start should be true");
michael@0 59 ok(!seekFlagEnd, "seeking flag on end should be false");
michael@0 60 finish();
michael@0 61 }
michael@0 62
michael@0 63 v.addEventListener("ended", playbackEnded, false);
michael@0 64 v.addEventListener("loadedmetadata", startTest, false);
michael@0 65 v.addEventListener("seeking", seekStarted, false);
michael@0 66 v.addEventListener("seeked", seekEnded, false);
michael@0 67
michael@0 68 }

mercurial