Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/callback-timeout-with-raf.html

Issue 2517743002: Import wpt@5a1f188e0536ad023936cc62f9a00617299dc192 (Closed)
Patch Set: rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>window.requestIdleCallback deals with timeouts correctly</title>
3 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script>
7
8 async_test(function() {
9 // Check whether requestIdleCallback with a timeout works when the event loop
10 // is busy.
11 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
12 var idle_callback_scheduled;
13 var idle_callback = this.step_func_done(function(deadline) {
14 assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout");
15 assert_equals(busy_raf_loop_iterations_remaining, 0, "Busy rAF loop should b e finished by the time we get scheduled");
16 });
17
18 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
19 requestAnimationFrame(this.step_func(function busyRAFLoop() {
20 var start_time = performance.now();
21 if (!idle_callback_scheduled) {
22 idle_callback_scheduled = start_time;
23 requestIdleCallback(idle_callback);
24 }
25
26 // Use up the whole frame budget.
27 while (performance.now() - start_time < 40) {
28 }
29 if (busy_raf_loop_iterations_remaining > 0) {
30 busy_raf_loop_iterations_remaining--;
31 requestAnimationFrame(busyRAFLoop);
32 }
33 }));
34 }, 'requestIdleCallback not scheduled when event loop is busy.');
35
36 async_test(function() {
37 // Check whether requestIdleCallback with a timeout works when the event loop
38 // is busy.
39 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
40 var timeout = 200;
41 var idle_callback_scheduled;
42 var idle_callback = this.step_func_done(function(deadline) {
43 var time_delta = performance.now() - idle_callback_scheduled;
44 assert_true(time_delta >= timeout, "Should only have been run after timeout" );
45 assert_true(deadline.timeRemaining() == 0, "IdleDeadline.timeRemaining MUST be equal to zero if requestIdleCallback was scheduled due to a timeout");
46 assert_true(deadline.didTimeout, "IdleDeadline.didTimeout MUST be true if re questIdleCallback was scheduled due to a timeout");
47 assert_true(busy_raf_loop_iterations_remaining > 0, "Busy rAF loop should st ill be going");
48 });
49
50 requestAnimationFrame(this.step_func(function busyRAFLoop() {
51 var start_time = performance.now();
52 if (!idle_callback_scheduled) {
53 idle_callback_scheduled = start_time;
54 requestIdleCallback(idle_callback, { timeout: timeout });
55 }
56
57 // Use up the whole frame budget.
58 while (performance.now() - start_time < 40) {
59 }
60 if (busy_raf_loop_iterations_remaining > 0) {
61 busy_raf_loop_iterations_remaining--;
62 requestAnimationFrame(busyRAFLoop);
63 }
64 }));
65 }, 'requestIdleCallback scheduled with timeout when event loop is busy.');
66
67 </script>
68 <h1>Test of requestIdleCallback timeout behavior</h1>
69 <div id="log"></div>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698