summaryrefslogtreecommitdiff
path: root/dom/media/test/test_cueless_webm_seek-1.html
blob: 8e501a61ec28fa434e2a7f251822e775f94b684b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=657791
-->
<head>
  <title>Test for Bug 657791</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=657791">Mozilla Bug 657791</a>

<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">

// Subset of seek tests for cueless WebMs. When random seeking (rather than just
// in buffered ranges) is implemented for WebM, these tests can be removed and
// the cueless WebM(s) references can be moved to the general test_seek test
// array.
// Test array is defined in manifest.js

var manager = new MediaTestManager;

// Exercise functionality as in test_seek-1
function testWebM1(e) {
  var v = e.target;
  v.removeEventListener('loadeddata', testWebM1);

  var startPassed = false;
  var endPassed = false;
  var seekFlagStart = false;
  var seekFlagEnd = false;
  var readonly = true;
  var completed = false;

  ok(v.buffered.length >= 1, "Should have a buffered range");
  var halfBuffered = v.buffered.end(0) / 2;

  function startTest() {
    is(v.seekable.start(0), v.buffered.start(0), "Seekable start should be buffered start");
    is(v.seekable.end(0), v.buffered.end(0), "Seekable end should be buffered end");
    ok(!completed, "Should not be completed yet");
    ok(!v.seeking, "seeking should default to false");
    try {
      v.seeking = true;
      readonly = v.seeking === false;
    }
    catch(e) {
      readonly = "threw exception: " + e;
    }
    is(readonly, true, "seeking should be readonly");

    v.currentTime = halfBuffered;
    seekFlagStart = v.seeking;
  }

  function seekStarted() {
    ok(!completed, "should not be completed yet");
    startPassed = true;
  }

  function seekEnded() {
    ok(!completed, "should not be completed yet");
    ok(Math.abs(v.currentTime - halfBuffered) < 0.1,
       "Video currentTime should be around " + halfBuffered + ": " + v.currentTime + " (seeked)");
    endPassed = true;
    seekFlagEnd = v.seeking;
    v.play();
  }

  function playbackEnded() {
    ok(!completed, "should not be completed yet");

    completed = true;
    ok(startPassed, "seeking event");
    ok(endPassed, "seeked event");
    ok(seekFlagStart, "seeking flag on start should be true");
    ok(!seekFlagEnd, "seeking flag on end should be false");
    removeNodeAndSource(v);
    manager.finished(v._token);
  }

  once(v, "ended", playbackEnded);
  once(v, "seeking", seekStarted);
  once(v, "seeked", seekEnded);

  startTest();
}

// Fetch the media resource using XHR so we can be sure the entire
// resource is loaded before we test buffered ranges. This ensures
// we have deterministic behaviour.
function fetch(url, fetched_callback) {
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url, true);
  xhr.responseType = "blob";

  var loaded = function (event) {
    if (xhr.status == 200 || xhr.status == 206) {
      // Request fulfilled. Note sometimes we get 206... Presumably because either
      // httpd.js or Necko cached the result.
      fetched_callback(window.URL.createObjectURL(xhr.response));
    } else {
      ok(false, "Fetch failed headers=" + xhr.getAllResponseHeaders());
    }
  };

  xhr.addEventListener("load", loaded, false);
  xhr.send();
}

function startTest(test, token) {
  var onfetched = function(uri) {
    var v = document.createElement('video');
    v._token = token;
    v.src = uri;
    v.addEventListener("loadeddata", testWebM1, false);
    document.body.appendChild(v);
  }
  manager.started(token);
  fetch(test.name, onfetched);
}

SimpleTest.waitForExplicitFinish();
manager.runTests(gCuelessWebMTests, startTest);

</script>
</pre>
</body>
</html>