blob: a7a0a038732aa2d033dceb2f3c666c86163fa811 [file] [log] [blame]
commit-queue@webkit.org7d369352016-11-10 01:13:05 +00001<!DOCTYPE html>
2<html>
3<head>
4 <script src="../../resources/js-test-pre.js"></script>
5</head>
6<body>
7 <canvas id="canvas"></canvas>
8 <script>
9 description("Ensure the image frame duration is respected even if the frame finishes decoding early.");
10 jsTestIsAsync = true;
11
12 internals.clearMemoryCache();
13
14 var image = new Image;
15 image.onload = imageLoaded;
16 image.src = "resources/animated-red-green-blue.gif";
17
18 function imageLoaded()
19 {
20 if (!window.internals)
21 return;
22 internals.setImageFrameDecodingDuration(image, 0.040);
clopez@igalia.comcaff60c2019-08-27 19:50:47 +000023 internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
commit-queue@webkit.org7d369352016-11-10 01:13:05 +000024 drawImage();
25 drawLoop();
26 }
27
28 function drawImage()
29 {
30 if (drawImage.count == undefined)
31 drawImage.count = 0;
32 var canvas = document.getElementById("canvas");
33 var ctx = canvas.getContext("2d");
34 ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
35 return ++drawImage.count;
36 }
37
38 function drawLoop()
39 {
40 // 1st time the image is drawn, time = 0, current_frame = 0
41 // 2nd time the image is drawn, time = 50, current_frame = 1
42 // 3rd time the image is drawn, time = 100, current_frame = 2
43 setTimeout(function() {
44 if (drawImage() == 3) {
45 shouldBe("internals.imageFrameIndex(image)", "2");
46 finishJSTest();
47 } else
48 drawLoop();
49 }, 50);
50 }
51 </script>
52 <script src="../../resources/js-test-post.js"></script>
53</body>
54</html>