Bug 1532639 [wpt PR 15630] - Add <meta name=timeout content=long> to WPT in SlowTests...
[gecko.git] / testing / web-platform / tests / requestidlecallback / callback-timeout-when-busy.html
blob39e17f7b73fc007b20e3ec64a3a5b4b7cdd9cac1
1 <!DOCTYPE html>
2 <title>window.requestIdleCallback deals with timeouts correctly</title>
3 <meta name="timeout" content="long">
4 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script>
9 async_test(function() {
10 // Check whether requestIdleCallback with a timeout works when the event loop
11 // is busy.
12 var busy_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
13 var idle_callback_scheduled;
14 var idle_callback = this.step_func_done(function(deadline) {
15 assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout");
16 assert_equals(busy_loop_iterations_remaining, 0, "Busy event loop should be finished by the time we get scheduled");
17 });
19 var busy_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
20 step_timeout(this.step_func(function busyLoop() {
21 var start_time = performance.now();
22 if (!idle_callback_scheduled) {
23 idle_callback_scheduled = start_time;
24 requestIdleCallback(idle_callback);
27 // Use up more than a frames worth of budget.
28 while (performance.now() - start_time < 40) {
30 if (busy_loop_iterations_remaining > 0) {
31 busy_loop_iterations_remaining--;
32 step_timeout(busyLoop);
34 }));
35 }, 'requestIdleCallback not scheduled when event loop is busy.');
37 async_test(function() {
38 // Check whether requestIdleCallback with a timeout works when the event loop
39 // is busy.
40 var busy_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
41 var timeout = 200;
42 var idle_callback_scheduled;
43 var idle_callback = this.step_func_done(function(deadline) {
44 var time_delta = performance.now() - idle_callback_scheduled;
45 assert_true(time_delta >= timeout, "Should only have been run after timeout");
46 assert_true(deadline.timeRemaining() == 0, "IdleDeadline.timeRemaining MUST be equal to zero if requestIdleCallback was scheduled due to a timeout");
47 assert_true(deadline.didTimeout, "IdleDeadline.didTimeout MUST be true if requestIdleCallback was scheduled due to a timeout");
48 assert_true(busy_loop_iterations_remaining > 0, "Busy event loop should still be going");
49 });
51 step_timeout(this.step_func(function busyLoop() {
52 var start_time = performance.now();
53 if (!idle_callback_scheduled) {
54 idle_callback_scheduled = start_time;
55 requestIdleCallback(idle_callback, { timeout: timeout });
58 // Use up more than a frames worth of budget.
59 while (performance.now() - start_time < 40) {
61 if (busy_loop_iterations_remaining > 0) {
62 busy_loop_iterations_remaining--;
63 step_timeout(busyLoop);
65 }));
66 }, 'requestIdleCallback scheduled with timeout when event loop is busy.');
68 </script>
69 <h1>Test of requestIdleCallback timeout behavior</h1>
70 <div id="log"></div>