OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 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" /> |
| 8 <script> |
| 9 test(function() { |
| 10 assert_equals(typeof window.requestIdleCallback, "function"); |
| 11 }, "window.requestIdleCallback is defined", {assert: "The window.requestIdleCall
back function is used to request callbacks during browser-defined idle time."}); |
| 12 |
| 13 test(function() { |
| 14 assert_equals(typeof window.cancelIdleCallback, "function"); |
| 15 }, "window.cancelIdleCallback is defined", {assert: "The window.cancelIdleCallba
ck function is used to cancel callbacks scheduled via requestIdleCallback."}); |
| 16 |
| 17 test(function() { |
| 18 assert_equals(typeof window.requestIdleCallback(function() {}), "number"); |
| 19 }, "window.requestIdleCallback() returns a number", {assert: "The requestIdleCal
lback method MUST return a long"}); |
| 20 |
| 21 test(function() { |
| 22 assert_equals(typeof window.cancelIdleCallback(1), "undefined"); |
| 23 }, "window.cancelIdleCallback() returns undefined", {assert: "The cancelIdleCall
back method MUST return void"}); |
| 24 |
| 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 cal
lback."); |
| 30 assert_equals(typeof deadline.timeRemaining, "number", "IdleDeadline.timeRem
aining MUST be a double time remaining in milliseconds"); |
| 31 assert_true(deadline.timeRemaining <= 50, "IdleDeadline.timeRemaining() MUST
be less than or equal to 50ms in the future."); |
| 32 assert_equals(typeof deadline.didTimeout, "boolean", "IdleDeadline.didTimeou
t MUST be a boolean"); |
| 33 assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if
requestIdleCallback wasn't scheduled due to a timeout"); |
| 34 this.done(); |
| 35 })); |
| 36 }, 'requestIdleCallback schedules callbacks'); |
| 37 |
| 38 async_test(function() { |
| 39 // Check whether requestIdleCallback schedules a callback which gets executed |
| 40 // and the deadline argument is passed correctly. |
| 41 var handle = requestIdleCallback(this.step_func(function(deadline) { |
| 42 assert_unreached("callback should not be called if canceled with cancelIdleC
allback"); |
| 43 })); |
| 44 cancelIdleCallback(handle); |
| 45 setTimeout(this.step_func(function() { |
| 46 this.done(); |
| 47 }), 200); |
| 48 }, 'cancelIdleCallback cancels callbacks'); |
| 49 |
| 50 </script> |
| 51 <h1>Description</h1> |
| 52 <p>This test validates that window.requestIdleCallback and window.cancelIdleCall
back exist and are a functions.</p> |
| 53 <div id="log"></div> |
OLD | NEW |