File: input-starved-by-timers.html

package info (click to toggle)
qtwebkit 2.3.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 290,116 kB
  • ctags: 272,544
  • sloc: cpp: 1,417,496; python: 85,048; ansic: 39,353; perl: 38,858; ruby: 10,313; objc: 9,505; xml: 8,679; asm: 3,864; yacc: 2,458; sh: 1,237; lex: 813; makefile: 592; java: 228; php: 79
file content (51 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<head>
<script>
function log(m) {
    document.getElementById("log").innerHTML += m + "<br>";
}

var multiplyFactor = 2;   // Create this many timers in every timer callback.
var targetLatency = 10000; // Multiply timers until it takes this much to fire all their callbacks.
var timerCount = 1;

function timerCallback(creationTimestamp) {
    --timerCount;

    if (!multiplyFactor) {
        if (timerCount == 0)
            log("No more timers - UI should be responsive now.");
        return;
    }

    // Create more timers. Capture the current time so when callbacks are fired,
    // we can check how long it actually took (latency caused by a long timer queue).
    var timestamp = new Date().getTime();
    for (i = 0; i < multiplyFactor; ++i) {
        setTimeout(function() { timerCallback(timestamp); }, 0);
        ++timerCount;
    }

    // Once the timer queue gets long enough for the timer firing latency to be over the limit,
    // stop multplying them and keep the number of timers constant.
    if (multiplyFactor > 1 && new Date().getTime() - creationTimestamp > targetLatency)
        multiplyFactor = 1;
}

function runTest() {
    log("Freezing UI...");
    setTimeout(function() { timerCallback(new Date().getTime()); }, 0);
    setTimeout("multiplyFactor = 0; log('Finishing. Started to drain timers.');", 10000);
}

</script>
</head>
<body onload="runTest()">
This test will create enough timers to freeze browser UI. After 10 seconds, it
will start drain the timers so the UI becomes responsive again in a few seconds.
You don't need to kill the browser.<br>If the bug is fixed, there will be no
UI freeze. Refresh the page to repeat the experiment.<br>Try to click at this
button (or browser's menu) while UI is frozen: <button onclick="log('clicked')">Click Me</button> <hr>
<div id="log"></div>
</body>
</html>