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

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: Fix comment and add loop in first test. 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 that two separate calls to requestIdleCallbacks can run in the same
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) {
27 assert_true(performance.now() < callback_1_deadline, "Should be able to ru n both callbacks in the same idle period.");
28 this.done();
29 } else {
30 // Might not have had enough idle time, so try again.
31 callback_1_has_run = false;
32 setTimeout(function() {
33 requestIdleCallback(callback_1);
34 requestIdleCallback(callback_2);
35 }, 0);
36 }
37 });
38 requestIdleCallback(callback_1);
39 requestIdleCallback(callback_2);
40 }, 'requestIdleCallback can run multiple different requestIdleCallback callbacks in the same idle period.');
41
42 async_test(function() {
43 // Check that if an idle callback calls requestIdleCallback the new callback
44 // doesn't run in the current idle period.
45 var previous_deadline;
46 var idle_callbacks_remaining = 10;
47 var self = this;
48 requestIdleCallback(this.step_func(function rIC(deadline) {
49 var remaining = deadline.timeRemaining();
50 var now = performance.now();
51 if (previous_deadline != undefined) {
52 assert_true(now >= previous_deadline, "A requestIdleCallback called during an idle period should not be run until the next idle period.");
53 }
54
55 // Schedule a new requestIdleCallback.
56 if (--idle_callbacks_remaining > 0) {
57 previous_deadline = now + remaining;
58 requestIdleCallback(rIC);
59 } else {
60 self.done();
61 }
62 }));
63
64 // Spin an empty rAF loop to cause an idle period each frame.
65 requestAnimationFrame(this.step_func(function rAFLoop() {
66 requestAnimationFrame(rAFLoop);
67 }));
68 }, 'Check that if an idle callback calls requestIdleCallback the new callback do esn\'t run in the current idle period.');
69 </script>
70 <h1>Description</h1>
71 <p>This test validates that window.requestIdleCallback deals with callbacks duri ng idle periods correctly.</p>
72 <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