| 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 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <script> |
| 7 test(function() { |
| 8 assert_equals(typeof window.requestIdleCallback, "function"); |
| 9 }, "window.requestIdleCallback is defined", {assert: "The window.requestIdleCall
back function is used to request callbacks during browser-defined idle time."}); |
| 10 |
| 11 test(function() { |
| 12 assert_equals(typeof window.cancelIdleCallback, "function"); |
| 13 }, "window.cancelIdleCallback is defined", {assert: "The window.cancelIdleCallba
ck function is used to cancel callbacks scheduled via requestIdleCallback."}); |
| 14 |
| 15 test(function() { |
| 16 assert_equals(typeof window.requestIdleCallback(function() {}), "number"); |
| 17 }, "window.requestIdleCallback() returns a number", {assert: "The requestIdleCal
lback method MUST return a long"}); |
| 18 |
| 19 test(function() { |
| 20 assert_equals(typeof window.cancelIdleCallback(1), "undefined"); |
| 21 }, "window.cancelIdleCallback() returns undefined", {assert: "The cancelIdleCall
back method MUST return void"}); |
| 22 |
| 23 async_test(function() { |
| 24 // Check whether requestIdleCallback schedules a callback which gets executed |
| 25 // and the deadline argument is passed correctly. |
| 26 requestIdleCallback(this.step_func_done(function(deadline) { |
| 27 assert_equals(arguments.length, 1, "Only one argument should be passed to ca
llback."); |
| 28 assert_class_string(deadline, "IdleDeadline"); |
| 29 assert_equals(typeof deadline.timeRemaining, "function", "IdleDeadline.timeR
emaining MUST be a function which returns the time remaining in milliseconds"); |
| 30 assert_equals(typeof deadline.timeRemaining(), "number", "IdleDeadline.timeR
emaining MUST return a double of the time remaining in milliseconds"); |
| 31 assert_true(deadline.timeRemaining() <= 50, "IdleDeadline.timeRemaining() MU
ST 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 })); |
| 35 }, 'requestIdleCallback schedules callbacks'); |
| 36 |
| 37 async_test(function() { |
| 38 // Check whether requestIdleCallback schedules a callback which gets executed |
| 39 // and the deadline argument is passed correctly. |
| 40 var handle = requestIdleCallback(this.step_func(function(deadline) { |
| 41 assert_unreached("callback should not be called if canceled with cancelIdleC
allback"); |
| 42 })); |
| 43 cancelIdleCallback(handle); |
| 44 setTimeout(this.step_func(function() { |
| 45 this.done(); |
| 46 }), 200); |
| 47 }, 'cancelIdleCallback cancels callbacks'); |
| 48 |
| 49 </script> |
| 50 <h1>Basic requestIdleCallback Tests</h1> |
| 51 <div id="log"></div> |
| OLD | NEW |