5 document.getElementById("log").innerHTML += m + "<br>";
8 var multiplyFactor = 2; // Create this many timers in every timer callback.
9 var targetLatency = 10000; // Multiply timers until it takes this much to fire all their callbacks.
12 function timerCallback(creationTimestamp) {
15 if (!multiplyFactor) {
17 log("No more timers - UI should be responsive now.");
21 // Create more timers. Capture the current time so when callbacks are fired,
22 // we can check how long it actually took (latency caused by a long timer queue).
23 var timestamp = new Date().getTime();
24 for (i = 0; i < multiplyFactor; ++i) {
25 setTimeout(function() { timerCallback(timestamp); }, 0);
29 // Once the timer queue gets long enough for the timer firing latency to be over the limit,
30 // stop multplying them and keep the number of timers constant.
31 if (multiplyFactor > 1 && new Date().getTime() - creationTimestamp > targetLatency)
36 log("Freezing UI...");
37 setTimeout(function() { timerCallback(new Date().getTime()); }, 0);
38 setTimeout("multiplyFactor = 0; log('Finishing. Started to drain timers.');", 10000);
43 <body onload="runTest()">
44 This test will create enough timers to freeze browser UI. After 10 seconds, it
45 will start drain the timers so the UI becomes responsive again in a few seconds.
46 You don't need to kill the browser.<br>If the bug is fixed, there will be no
47 UI freeze. Refresh the page to repeat the experiment.<br>Try to click at this
48 button (or browser's menu) while UI is frozen: <button onclick="log('clicked')">Click Me</button> <hr>