| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../../../http/tests/inspector/timeline-test.js"></script> | 4 <script src="../../../../http/tests/inspector/timeline-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 function performActions(callback) | 6 function performActions() |
| 7 { | 7 { |
| 8 var callback; |
| 9 var promise = new Promise((fulfill) => callback = fulfill); |
| 8 var requestId = window.requestIdleCallback(idleCallback); | 10 var requestId = window.requestIdleCallback(idleCallback); |
| 9 window.cancelIdleCallback(requestId); | 11 window.cancelIdleCallback(requestId); |
| 10 window.requestIdleCallback(idleCallback); | 12 window.requestIdleCallback(idleCallback); |
| 11 function idleCallback() | 13 function idleCallback() |
| 12 { | 14 { |
| 13 window.requestIdleCallback(slowIdleCallback); | 15 window.requestIdleCallback(slowIdleCallback); |
| 14 } | 16 } |
| 15 function slowIdleCallback(deadline) | 17 function slowIdleCallback(deadline) |
| 16 { | 18 { |
| 17 while (deadline.timeRemaining()) {}; | 19 while (deadline.timeRemaining()) {}; |
| 18 if (callback) | 20 if (callback) |
| 19 callback(); | 21 callback(); |
| 20 } | 22 } |
| 23 return promise; |
| 21 } | 24 } |
| 22 | 25 |
| 23 function test() | 26 function test() |
| 24 { | 27 { |
| 25 InspectorTest.invokeAsyncWithTimeline("performActions", finish); | 28 InspectorTest.invokeAsyncWithTimeline("performActions", finish); |
| 26 | 29 |
| 27 function finish() | 30 function finish() |
| 28 { | 31 { |
| 29 InspectorTest.printTimelineRecordsWithDetails("RequestIdleCallback"); | 32 InspectorTest.printTimelineRecordsWithDetails("RequestIdleCallback"); |
| 30 InspectorTest.printTimelineRecordsWithDetails("CancelIdleCallback"); | 33 InspectorTest.printTimelineRecordsWithDetails("CancelIdleCallback"); |
| 31 InspectorTest.printTimelineRecordsWithDetails("FireIdleCallback"); | 34 InspectorTest.printTimelineRecordsWithDetails("FireIdleCallback"); |
| 32 InspectorTest.completeTest(); | 35 InspectorTest.completeTest(); |
| 33 } | 36 } |
| 34 } | 37 } |
| 35 | 38 |
| 36 if (!window.testRunner) | 39 if (!window.testRunner) |
| 37 setTimeout(performActions, 2000); | 40 setTimeout(performActions, 2000); |
| 38 </script> | 41 </script> |
| 39 </head> | 42 </head> |
| 40 | 43 |
| 41 <body onload="runTest()"> | 44 <body onload="runTest()"> |
| 42 <p> | 45 <p> |
| 43 Tests Timeline events emitted when idle callback is scheduled and fired. | 46 Tests Timeline events emitted when idle callback is scheduled and fired. |
| 44 </p> | 47 </p> |
| 45 | 48 |
| 46 </body> | 49 </body> |
| 47 </html> | 50 </html> |
| OLD | NEW |