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

Side by Side Diff: LayoutTests/virtual/threaded/fast/idle-callback/idle_periods.html

Issue 1342803002: [LayoutTests] Add a new requestIdleCallback layout test which checks idle period behavior. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>window.requestIdleCallback callback behavior during idle periods.</title>
3 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
4 <link rel="help" href="http://www.w3.org/TR/requestidlecallback/"/>
5 <script src="../../../../resources/testharness.js"></script>
6 <script src="../../../../resources/testharnessreport.js"></script>
7 <link rel="stylesheet" href="../../../..//resources/testharness.css" />
8 <script>
9
10 async_test(function() {
11 // Check whether separate calls to requestIdleCallbacks can run in the same
Sami 2015/09/14 15:55:37 nit: This description is a little vague in the sen
rmcilroy 2015/09/14 16:24:32 Done.
12 // idle period.
13 var callback_1_deadline;
14 var callback_1_has_run = false;
15 var callback_1 = function(deadline) {
16 callback_1_has_run = true;
17 var remaining = deadline.timeRemaining();
18 if (remaining >= 5) {
19 // Should be enough time to run the next callback in the current idle
20 // period.
21 callback_1_deadline = performance.now() + remaining;
22 }
23 };
24 var callback_2 = this.step_func(function(deadline) {
25 assert_true(callback_1_has_run, "Should run callbacks in order of posting if they don't have a timeout.");
26 if (callback_1_deadline != undefined) {
Sami 2015/09/14 15:55:37 I'm wondering if we should do this in a loop until
rmcilroy 2015/09/14 16:24:33 Added a loop if we weren't able to do the check. D
27 assert_true(performance.now() < callback_1_deadline, "Should be able to ru n both callbacks in the same idle period.");
28 }
29 this.done();
30 });
31 requestIdleCallback(callback_1);
32 requestIdleCallback(callback_2);
33 }, 'requestIdleCallback can run multiple different requestIdleCallback callbacks in the same idle period.');
34
35 async_test(function() {
36 // Check that if an idle callback calls requestIdleCallback the new callback
37 // doesn't run in the current idle period.
38 var previous_deadline;
39 var idle_callbacks_remaining = 10;
40 var self = this;
41 requestIdleCallback(this.step_func(function rIC(deadline) {
42 var remaining = deadline.timeRemaining();
43 var now = performance.now();
44 if (previous_deadline != undefined) {
45 assert_true(now >= previous_deadline, "A requestIdleCallback called during an idle period should not be run until the next idle period.");
46 }
47
48 // Schedule a new requestIdleCallback.
49 if (--idle_callbacks_remaining > 0) {
50 previous_deadline = now + remaining;
51 requestIdleCallback(rIC);
52 } else {
53 self.done();
54 }
55 }));
56
57 // Spin an empty rAF loop to cause an idle period each frame.
58 requestAnimationFrame(this.step_func(function rAFLoop() {
59 requestAnimationFrame(rAFLoop);
60 }));
61 }, 'Check that if an idle callback calls requestIdleCallback the new callback do esn\'t run in the current idle period.');
62 </script>
63 <h1>Description</h1>
64 <p>This test validates that window.requestIdleCallback deals with callbacks duri ng idle periods correctly.</p>
65 <div id="log"></div>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698