| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../resources/js-test.js"></script> | |
| 4 <script> | |
| 5 description('<a href="https://bugs.webkit.org/show_bug.cgi?id=98474">Bug
98474</a>: Throttle DOM timers on hidden pages and <a href="http://crbug.com/40
0343">bug 400343</a> prerender pages.'); | |
| 6 | |
| 7 var jsTestIsAsync = true; | |
| 8 var previousTime = 0; | |
| 9 var timerCount = 0; | |
| 10 var firstTimerWhileNotVisible = true; | |
| 11 var isPageVisible = true; | |
| 12 var timeoutInterval = 100; | |
| 13 var tolerance = 20; | |
| 14 var timerAlignmentInterval = 1000; | |
| 15 | |
| 16 function testTimer() | |
| 17 { | |
| 18 var time = Date.now(); | |
| 19 if (!isPageVisible) { | |
| 20 if (firstTimerWhileNotVisible) { | |
| 21 firstTimerIntervalWhilePageNotVisible = time - previousTime; | |
| 22 var minValue = timeoutInterval - tolerance; | |
| 23 shouldBeGreaterThanOrEqual("firstTimerIntervalWhilePageNotVi
sible", minValue.toString()); | |
| 24 var maxValue = timeoutInterval + timerAlignmentInterval + to
lerance; | |
| 25 shouldBeTrue("firstTimerIntervalWhilePageNotVisible <= " + m
axValue); | |
| 26 firstTimerWhileNotVisible = false; | |
| 27 } else { | |
| 28 timerIntervalWhilePageNotVisible = time - previousTime; | |
| 29 shouldBeCloseTo("timerIntervalWhilePageNotVisible", timerAli
gnmentInterval, tolerance); | |
| 30 } | |
| 31 } else { | |
| 32 timerIntervalWhilePageVisible = time - previousTime; | |
| 33 shouldBeCloseTo("timerIntervalWhilePageVisible", timeoutInterval
, tolerance); | |
| 34 } | |
| 35 | |
| 36 timerCount++; | |
| 37 previousTime = time; | |
| 38 | |
| 39 if (timerCount == 1) { | |
| 40 testRunner.setPageVisibility("hidden"); | |
| 41 isPageVisible = false; | |
| 42 } else if (timerCount == 3) { | |
| 43 testRunner.setPageVisibility("visible"); | |
| 44 isPageVisible = true; | |
| 45 } else if (timerCount == 5) { | |
| 46 testRunner.setPageVisibility("prerender"); | |
| 47 isPageVisible = false; | |
| 48 firstTimerWhileNotVisible = true; | |
| 49 } else if (timerCount == 7) { | |
| 50 testRunner.setPageVisibility("visible"); | |
| 51 isPageVisible = true; | |
| 52 } else if (timerCount >= 8){ | |
| 53 finishJSTest(); | |
| 54 return; | |
| 55 } | |
| 56 previousTime = Date.now(); | |
| 57 setTimeout(testTimer, timeoutInterval); | |
| 58 } | |
| 59 | |
| 60 function runTest() | |
| 61 { | |
| 62 if (!window.testRunner) { | |
| 63 debug('This test requires testRunner'); | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 var timeoutIntervalSpans = document.getElementsByClassName('timeoutI
nterval'); | |
| 68 for (var i = 0; i < timeoutIntervalSpans.length; i++) | |
| 69 timeoutIntervalSpans[i].innerText = timeoutInterval; | |
| 70 | |
| 71 document.getElementById('alignmentInterval').innerText = timerAlignm
entInterval / 1000; | |
| 72 | |
| 73 testRunner.dumpAsText(); | |
| 74 previousTime = Date.now(); | |
| 75 setTimeout(testTimer, timeoutInterval); | |
| 76 } | |
| 77 </script> | |
| 78 </head> | |
| 79 <body onload="runTest()"> | |
| 80 <p> | |
| 81 This test measures the time taken to fire a <span class="timeoutInterval"></
span>ms DOM Timer when the page visibility is set to "visible", "hidden", "visib
le", "prerender" and then back to "visible". Due to page timer throttling, the
timer should fire close to <span id="alignmentInterval"></span>s when page is hi
dden or prerender. And it should fire close to <span class="timeoutInterval"></
span>ms, when the page is visible. | |
| 82 </p> | |
| 83 </body> | |
| 84 </html> | |
| OLD | NEW |