OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8" /> |
| 5 <title>window.requestIdleCallback exists</title> |
| 6 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" /> |
| 7 <link rel="help" href="http://www.w3.org/TR/requestidlecallback/"/> |
| 8 <script src="../../../../resources/testharness.js"></script> |
| 9 <script src="../../../../resources/testharnessreport.js"></script> |
| 10 <link rel="stylesheet" href="../../resources/testharness.css" /> |
| 11 <script> |
| 12 test(function() { |
| 13 assert_equals(typeof window.requestIdleCallback, "function"); |
| 14 }, "window.requestIdleCallback is defined", {assert: "The window.requestIdleCall
back function is used to request callbacks during browser-defined idle time."}); |
| 15 |
| 16 test(function() { |
| 17 assert_equals(typeof window.cancelIdleCallback, "function"); |
| 18 }, "window.cancelIdleCallback is defined", {assert: "The window.cancelIdleCallba
ck function is used to cancel callbacks scheduled via requestIdleCallback."}); |
| 19 |
| 20 test(function() { |
| 21 assert_equals(typeof window.requestIdleCallback(function() {}), "number"); |
| 22 }, "window.requestIdleCallback() returns a number", {assert: "The requestIdleCal
lback method MUST return a long"}); |
| 23 |
| 24 test(function() { |
| 25 assert_equals(typeof window.cancelIdleCallback(1), "undefined"); |
| 26 }, "window.cancelIdleCallback() returns undefined", {assert: "The cancelIdleCall
back method MUST return void"}); |
| 27 |
| 28 async_test(function() { |
| 29 // Check whether requestIdleCallback schedules a callback which gets executed |
| 30 // and the deadline argument is passed correctly. |
| 31 requestIdleCallback(this.step_func(function(deadline) { |
| 32 assert_equals(typeof deadline, "object", "IdleDeadline MUST be passed to cal
lback."); |
| 33 assert_equals(typeof deadline.deadline, "number", "IdleDeadline.deadline MUS
T be a DOMHighResTimeStamp"); |
| 34 var now = performance.now(); |
| 35 assert_true((deadline.deadline - now) <= 50, "IdleDeadline.deadline MUST be
less than or equal to 50ms in the future."); |
| 36 assert_equals(typeof deadline.isExceeded, "function", "IdleDeadline.isExceed
ed MUST be a function"); |
| 37 assert_equals(typeof deadline.isExceeded(), "boolean", "IdleDeadline.isExcee
ded MUST return a boolean"); |
| 38 if (!deadline.isExceeded()) { |
| 39 // If the deadline has not been exceeded now, then it should be greater th
an |
| 40 // the than what performance.now() returned earlier. |
| 41 assert_true(now < deadline.deadline, "performance.now() should be less tha
n deadline if isExceeded returned true."); |
| 42 } |
| 43 assert_equals(typeof deadline.didTimeout, "boolean", "IdleDeadline.didTimeou
t MUST be a boolean"); |
| 44 assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if
requestIdleCallback wasn't scheduled due to a timeout"); |
| 45 this.done(); |
| 46 })); |
| 47 }, 'requestIdleCallback schedules callbacks'); |
| 48 |
| 49 async_test(function() { |
| 50 // Check whether requestIdleCallback schedules a callback which gets executed |
| 51 // and the deadline argument is passed correctly. |
| 52 var handle = requestIdleCallback(this.step_func(function(deadline) { |
| 53 assert_unreached("callback should not be called if canceled with cancelIdleC
allback"); |
| 54 })); |
| 55 cancelIdleCallback(handle); |
| 56 setTimeout(this.step_func(function() { |
| 57 this.done(); |
| 58 }), 200); |
| 59 }, 'cancelIdleCallback cancels callbacks'); |
| 60 |
| 61 </script> |
| 62 <h1>Description</h1> |
| 63 <p>This test validates that window.requestIdleCallback and window.cancelIdleCall
back exist and are a functions.</p> |
| 64 </head> |
| 65 <body> |
| 66 <div id="log"></div> |
| 67 |
| 68 </body> |
| 69 </html> |
OLD | NEW |