File: callback-idle-periods.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (44 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (17)
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
<!DOCTYPE html>
<title>window.requestIdleCallback callback behavior during idle periods.</title>
<meta name="timeout" content="long">
<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

async_test(function() {
  // Check that if an idle callback calls requestIdleCallback, the new callback
  // doesn't get the same deadline (i.e., runs in a new idle period).
  var previous_deadline = undefined;
  var idle_callbacks_remaining = 10;
  var rIC = this.step_func(function(deadline) {
    var now = performance.now();
    var remaining = deadline.timeRemaining();
    var new_deadline = now + remaining;
    if (previous_deadline != undefined) {
      assert_true(new_deadline >= previous_deadline, "A requestIdleCallback scheduled during an idle period should be called back with a deadline greater than or equal to that in the current idle period.");
    }

    // Schedule a new requestIdleCallback.
    if (--idle_callbacks_remaining > 0) {
      previous_deadline = new_deadline;
      requestIdleCallback(rIC);
    } else {
      this.done();
    }
  });

  // Spin an empty rAF loop to cause an idle period each frame.
  var idle_task_posted = false;
  requestAnimationFrame(function rAFLoop() {
    if (!idle_task_posted) {
      requestIdleCallback(rIC);
      idle_task_posted = true;
    }
    requestAnimationFrame(rAFLoop);
  });
}, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.');
</script>
<h1>Test of requestIdleCallback idle period behavior</h1>
<p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p>
<div id="log"></div>