2 <title>window.requestIdleCallback exists
</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" />
10 assert_equals(typeof window
.requestIdleCallback
, "function");
11 }, "window.requestIdleCallback is defined", {assert
: "The window.requestIdleCallback function is used to request callbacks during browser-defined idle time."});
14 assert_equals(typeof window
.cancelIdleCallback
, "function");
15 }, "window.cancelIdleCallback is defined", {assert
: "The window.cancelIdleCallback function is used to cancel callbacks scheduled via requestIdleCallback."});
18 assert_equals(typeof window
.requestIdleCallback(function() {}), "number");
19 }, "window.requestIdleCallback() returns a number", {assert
: "The requestIdleCallback method MUST return a long"});
22 assert_equals(typeof window
.cancelIdleCallback(1), "undefined");
23 }, "window.cancelIdleCallback() returns undefined", {assert
: "The cancelIdleCallback method MUST return void"});
25 async_test(function() {
26 // Check whether requestIdleCallback schedules a callback which gets executed
27 // and the deadline argument is passed correctly.
28 requestIdleCallback(this.step_func(function(deadline
) {
29 assert_equals(typeof deadline
, "object", "IdleDeadline MUST be passed to callback.");
30 assert_equals(typeof deadline
.timeRemaining
, "function", "IdleDeadline.timeRemaining MUST be a function which returns the time remaining in milliseconds");
31 assert_equals(typeof deadline
.timeRemaining(), "number", "IdleDeadline.timeRemaining MUST return a double of the time remaining in milliseconds");
32 assert_true(deadline
.timeRemaining() <= 50, "IdleDeadline.timeRemaining() MUST be less than or equal to 50ms in the future.");
33 assert_equals(typeof deadline
.didTimeout
, "boolean", "IdleDeadline.didTimeout MUST be a boolean");
34 assert_false(deadline
.didTimeout
, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout");
37 }, 'requestIdleCallback schedules callbacks');
39 async_test(function() {
40 // Check whether requestIdleCallback schedules a callback which gets executed
41 // and the deadline argument is passed correctly.
42 var handle
= requestIdleCallback(this.step_func(function(deadline
) {
43 assert_unreached("callback should not be called if canceled with cancelIdleCallback");
45 cancelIdleCallback(handle
);
46 setTimeout(this.step_func(function() {
49 }, 'cancelIdleCallback cancels callbacks');
53 <p>This test validates that window.requestIdleCallback and window.cancelIdleCallback exist and are a functions.
</p>