Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / virtual / threaded / fast / idle-callback / idle_periods.html
blob4751fabebc4b3798a813072175c27362dacc37ad
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>
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;
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 run 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);
37 });
38 requestIdleCallback(callback_1);
39 requestIdleCallback(callback_2);
40 }, 'requestIdleCallback can run multiple different requestIdleCallback callbacks in the same idle period.');
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.");
55 // Schedule a new requestIdleCallback.
56 if (--idle_callbacks_remaining > 0) {
57 previous_deadline = now + remaining;
58 requestIdleCallback(rIC);
59 } else {
60 self.done();
62 }));
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 doesn\'t run in the current idle period.');
69 </script>
70 <h1>Description</h1>
71 <p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p>
72 <div id="log"></div>