Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Test playback of media files that should play OK</title>
5
<script src="/tests/SimpleTest/SimpleTest.js"></script>
6
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
7
<script type="text/javascript" src="manifest.js"></script>
8
</head>
9
<body>
10
<pre id="test">
11
<script class="testbody" type="text/javascript">
12
13
var manager = new MediaTestManager;
14
15
function startTest(test, token) {
16
var video = document.createElement('video');
17
video.preload = "metadata";
18
video.token = token;
19
video.prevTime = 0;
20
video.seenEnded = false;
21
video.seenSuspend = false;
22
23
var handler = {
24
"ontimeout": function() {
25
Log(token, "timed out: ended=" + video.seenEnded + ", suspend=" + video.seenSuspend);
26
}
27
};
28
manager.started(token, handler);
29
30
video.src = test.name;
31
video.name = test.name;
32
33
var check = function(t, v) { return function() {
34
is(t.name, v.name, t.name + ": Name should match #1");
35
checkMetadata(t.name, v, t);
36
}}(test, video);
37
38
var noLoad = function(t, v) { return function() {
39
ok(false, t.name + " should not fire 'load' event");
40
}}(test, video);
41
42
var noError = function(t, v) { return function() {
43
ok(false, t.name + " should not fire 'error' event " + v.error.message);
44
}}(test, video);
45
46
var finish = function() {
47
video.finished = true;
48
video.removeEventListener("timeupdate", timeUpdate);
49
removeNodeAndSource(video);
50
manager.finished(video.token);
51
}
52
53
// We should get "ended" and "suspend" events to finish the test.
54
var mayFinish = function() {
55
if (video.seenEnded && video.seenSuspend) {
56
finish();
57
}
58
}
59
60
var checkEnded = function(t, v) { return function() {
61
is(t.name, v.name, t.name + ": Name should match #2");
62
checkMetadata(t.name, v, test);
63
is(v.readyState, v.HAVE_CURRENT_DATA, t.name + " checking readyState");
64
ok(v.ended, t.name + " checking playback has ended");
65
ok(!v.finished, t.name + " shouldn't be finished");
66
ok(!v.seenEnded, t.name + " shouldn't be ended");
67
68
v.seenEnded = true;
69
mayFinish();
70
}}(test, video);
71
72
var checkSuspended = function(t, v) { return function() {
73
if (v.seenSuspend) {
74
return;
75
}
76
is(t.name, v.name, t.name + ": Name should match #3");
77
78
v.seenSuspend = true;
79
mayFinish();
80
}}(test, video);
81
82
var timeUpdate = function(t, v) { return function() {
83
if (v.prevTime > v.currentTime) {
84
ok(false, t.name + " time should run forwards: p=" +
85
v.prevTime + " c=" + v.currentTime);
86
}
87
v.prevTime = v.currentTime;
88
}}(test, video);
89
90
video.addEventListener("load", noLoad);
91
video.addEventListener("error", noError);
92
video.addEventListener("loadedmetadata", check);
93
video.addEventListener("timeupdate", timeUpdate);
94
95
// We should get "ended" and "suspend" events for every resource
96
video.addEventListener("ended", checkEnded);
97
video.addEventListener("suspend", checkSuspended);
98
99
document.body.appendChild(video);
100
video.play();
101
}
102
103
manager.runTests(gPlayTests, startTest);
104
105
</script>
106
</pre>
107
</body>
108
</html>