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
|
<!DOCTYPE HTML>
<html>
<head>
<title>Seamless looping video canvas test</title>
<script 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>
<canvas id="canvas"></canvas>
<video id="v"></video>
<script type="application/javascript">
/**
* This test aims to check if the video is seamless looping by capturing the
* image when loop happens. We use a video contains only white frames, so the
* captured frame should always be a white frame. If looping is not seamless,
* the captured frame would become a black frame.
*/
const WIDTH = 10, HEIGHT = 10;
add_task(async function testSeamlessLoopingVideoCanvas() {
await SpecialPowers.pushPrefEnv({
set: [
["media.seamless-looping-video", true],
],
});
info(`load video which only contains white frames`);
let video = document.getElementById("v");
video.loop = true;
video.src = "white-short.webm";
video.width = WIDTH;
video.height = HEIGHT;
await video.play();
info(`setup canvas`);
const cvs = document.getElementById("canvas");
cvs.width = WIDTH;
cvs.height = HEIGHT;
info(`test seamless looping multiples times`);
let MAX_LOOPING_COUNT = 10;
for (let count = 0; count < MAX_LOOPING_COUNT; count++) {
await once(video, "seeking");
assertPaintedFrameIsWhiteFrame();
await once(video, "seeked");
ok(true, `the round ${count} of the seamless looping succeeds`);
}
});
function assertPaintedFrameIsWhiteFrame() {
info(`catpure image from video`);
const cvs = document.getElementById("canvas");
let context = cvs.getContext('2d');
if (!context) {
ok(false, "can't get 2d context");
}
context.drawImage(document.getElementById("v"), 0, 0, WIDTH, HEIGHT);
let imageData = context.getImageData(0, 0, WIDTH, HEIGHT);
for (let idx = 0; idx < WIDTH * HEIGHT; idx++) {
let pixelCount = 4 * idx; // RGBA
let data = imageData.data;
// White frame's RGB value should be [255,255,255]
is(data[pixelCount + 0], 255, `R should be 255`);
is(data[pixelCount + 1], 255, `G should be 255`);
is(data[pixelCount + 2], 255, `B should be 255`);
}
}
</script>
<body>
</body>
</html>
|