requestFrameAnimation() callback timestamp should be very close to Performance.now()
[WebKit-https.git] / LayoutTests / animations / animation-multiple-callbacks-timestamp.html
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4     <script src="../resources/js-test-pre.js"></script>
5 </head>
6 <body>
7     <script>
8         var currentFrame = 0;
9         var timestamp1 = 0;
10         var failed = false;
11
12         function finishTest()
13         {
14             if (failed)
15                 testFailed("Some of the multiple requestAnimationFrame() callbacks, which were fired at the same time, received different timestamps.");
16             else
17                 testPassed("All the multiple requestAnimationFrame() callbacks, which were fired at the same time, received the same timestamp.");
18             finishJSTest();
19         }
20
21         function doAnimation1(timestamp)
22         {
23             timestamp1 = timestamp;
24             
25             const MaxFrames = 25;
26             if (currentFrame == MaxFrames)
27                 finishTest();
28             else {
29                 requestAnimationFrame(doAnimation1);
30                 requestAnimationFrame(doAnimation2);
31             }
32         }
33
34         function doAnimation2(timestamp)
35         {
36             const WarmupFrames = 5;
37             if (++currentFrame > WarmupFrames && timestamp != timestamp1) {
38                 testFailed("timestamp1 = " + timestamp1 + ", timestamp2 = " + timestamp2  + ", window.performance.now() = " + window.performance.now());
39                 failed = true;
40             }
41         }
42         
43         window.jsTestIsAsync = true;
44         requestAnimationFrame(doAnimation1);
45     </script>
46     <script src="../resources/js-test-post.js"></script>
47 </body>
48 </html>