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