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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<!DOCTYPE HTML>
<html>
<head>
<title>Test that reloading, pausing and seeking in a media element that's being captured behaves as expected</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="manifest.js"></script>
</head>
<body>
<video id="v"></video>
<video id="vout"></video>
<video id="vout_untilended"></video>
<pre id="test">
<script>
const v = document.getElementById('v');
const vout = document.getElementById('vout');
const vout_untilended = document.getElementById('vout_untilended');
function dumpEvent(event) {
const video = event.target;
info(
`${video.name}:${video.id} GOT EVENT ${event.type} ` +
`currentTime=${video.currentTime} paused=${video.paused} ` +
`ended=${video.ended} readyState=${video.readyState}`
);
}
function unexpected(event) {
ok(false, `${event.type} event received on ${event.target.id} unexpectedly`);
};
const events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
for (const e of events) {
v.addEventListener(e, dumpEvent);
vout.addEventListener(e, dumpEvent);
vout_untilended.addEventListener(e, dumpEvent);
}
function isWithinEps(a, b, msg) {
ok(Math.abs(a - b) < 0.01,
"Got " + a + ", expected " + b + "; " + msg);
}
function isGreaterThanOrEqualEps(a, b, msg) {
ok(a >= b - 0.01,
"Got " + a + ", expected at least " + b + "; " + msg);
}
async function startTest(test) {
const seekTime = test.duration/2;
const contentDuration = test.contentDuration ?? test.duration;
v.src = test.name;
v.name = test.name;
vout.name = test.name;
vout_untilended.name = test.name;
v.preload = "metadata";
await new Promise(r => v.onloadedmetadata = r);
vout.srcObject = v.mozCaptureStream();
vout.play();
vout_untilended.srcObject = v.mozCaptureStreamUntilEnded();
vout_untilended.play();
for (const track of [
...vout.srcObject.getTracks(),
...vout_untilended.srcObject.getTracks(),
]) {
ok(track.muted, `${track.kind} track ${track.id} should be muted`);
}
v.play();
await Promise.all([
...vout.srcObject.getTracks(),
...vout_untilended.srcObject.getTracks()
].map(t => new Promise(r => t.onunmute = r)));
await new Promise(r => v.onended = r);
isGreaterThanOrEqualEps(v.currentTime, test.duration,
"checking v.currentTime at first 'ended' event");
await Promise.all([
new Promise(r => vout.onended = r),
new Promise(r => vout_untilended.onended = r),
]);
isGreaterThanOrEqualEps(vout.currentTime, contentDuration,
"checking vout.currentTime at first 'ended' event");
ok(vout.ended, "checking vout has actually ended");
ok(vout_untilended.ended, "checking vout_untilended has actually ended");
vout_untilended.srcObject.onaddtrack = unexpected;
vout_untilended.onplaying = unexpected;
vout_untilended.onended = unexpected;
const voutPreSeekCurrentTime = vout.currentTime;
v.currentTime = seekTime;
await new Promise(r => v.onseeked = r);
is(v.currentTime, seekTime, "Finished seeking");
is(vout.currentTime, voutPreSeekCurrentTime,
"checking vout.currentTime has not changed after seeking");
v.play();
vout.play();
await new Promise(r => v.onended = r);
isGreaterThanOrEqualEps(v.currentTime, test.duration,
"checking v.currentTime at second 'ended' event");
await new Promise(r => vout.onended = r);
isGreaterThanOrEqualEps(vout.currentTime,
(test.duration - seekTime) + contentDuration,
"checking vout.currentTime after seeking and playing through again");
v.src = test.name + "?1";
vout.play();
await v.play();
isnot(vout.srcObject.getTracks().length, 0, "There are some output tracks");
vout.onended = unexpected;
vout.srcObject.onremovetrack = unexpected;
v.pause();
await Promise.all(
vout.srcObject.getTracks().map(t => new Promise(r => t.onmute = r))
);
for (const track of vout.srcObject.getTracks()) {
track.onunmute = unexpected;
}
v.currentTime = 0;
await new Promise(r => v.onseeked = r);
v.play();
await Promise.all(
vout.srcObject.getTracks().map(t => new Promise(r => t.onunmute = r))
);
vout.srcObject.onremovetrack = null;
await new Promise(r => v.onended = r);
isGreaterThanOrEqualEps(v.currentTime, test.duration,
"checking v.currentTime at third 'ended' event");
await new Promise(r => vout.onended = r);
isGreaterThanOrEqualEps(vout.currentTime,
(test.duration - seekTime) + contentDuration*2,
"checking vout.currentTime after seeking, playing through and reloading");
}
(async () => {
SimpleTest.waitForExplicitFinish();
try {
const testVideo = getPlayableVideo(gSmallTests);
if (testVideo) {
await startTest(testVideo);
} else {
todo(false, "No playable video");
}
} catch(e) {
ok(false, `Error: ${e}`);
} finally {
SimpleTest.finish();
}
})();
</script>
</pre>
</body>
</html>
|