Throttle RequestAnimationFrame in subframes that are outside the viewport
[WebKit-https.git] / LayoutTests / fast / animation / request-animation-frame-throttle-subframe.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../resources/js-test-pre.js"></script>
5 <script>
6 description("Tests that requestAnimationFrame is throttled in subframes that are outside the viewport");
7 window.jsTestIsAsync = true;
8
9 function checkSubframesThrottled()
10 {
11     shouldBeTrue("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
12     shouldBeTrue("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
13
14     finishJSTest();
15 }
16
17 function scrollFrameOutOfView()
18 {
19     debug("Scrolling frame out of view again.");
20     window.scroll(0, 0);
21
22     shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
23     shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "true", checkSubframesThrottled);
24 }
25
26 function scrollFrameIntoView()
27 {
28     shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
29     shouldBeTrue("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
30     shouldBeTrue("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
31
32     debug("Scrolling frame into view.");
33     window.internals.scrollElementToRect(testFrame, 0, 0, 300, 300);
34
35     debug("RequestAnimationFrame should no longer be throttled");
36     shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
37     shouldBeFalse("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
38     shouldBeFalse("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
39
40     scrollFrameOutOfView();
41 }
42
43 function runTest()
44 {
45     testFrame = document.getElementById("testFrame");
46     grandChildFrame = testFrame.contentDocument.getElementById("grandChildFrame");
47     debug("Frame is initially outside the viewport so requestAnimationFrame should be throttled");
48     shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "true", scrollFrameIntoView);
49 }
50
51 var i = 0;
52 requestAnimationFrame(function() {
53     i++;
54 });
55 </script>
56 <div style="position: relative; width: 1600px; height: 2400px; background-color: green;">
57     <iframe id="testFrame" src="resources/requestAnimationFrame-frame.html" style="position:absolute; left: 600px; top: 800px;" onload="runTest()"></iframe>
58 </div>
59 <script src="../../resources/js-test-post.js"></script>
60 </body>
61 </html>