| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script src="./resources/timeline-event-utilities.js"></script> |
| <script> |
| |
| function testSetTimeout() { |
| let setTimeoutIdentifier = setTimeout(() => { |
| TestPage.addResult("PASS: setTimeout fired"); |
| }, 10); |
| |
| savePageData({setTimeoutIdentifier}); |
| } |
| |
| function testSetInterval() { |
| let count = 0; |
| |
| let setIntervalIdentifier = setInterval(() => { |
| count++; |
| |
| TestPage.addResult("PASS: setInterval fired: " + count); |
| |
| if (count === 3) |
| clearInterval(setIntervalIdentifier); |
| }, 5); |
| |
| savePageData({setIntervalIdentifier}); |
| } |
| |
| function test() |
| { |
| let suite = InspectorTest.createAsyncSuite("TimelineEvent.TimerInstall"); |
| |
| let timeoutIdentifier = undefined; |
| let intervalIdentifier = undefined; |
| |
| function jsonFilter(key, value) { |
| if (key === "timerId") |
| return "<filtered>"; |
| return value; |
| } |
| |
| suite.addTestCase({ |
| name: "TimelineEvent.TimerInstall.setTimeout", |
| async test() { |
| let pageRecordingData = await InspectorTest.TimelineEvent.captureTimelineWithScript({ |
| expression: `testSetTimeout()`, |
| eventType: WI.ScriptTimelineRecord.EventType.TimerFired, |
| }); |
| |
| InspectorTest.assert(typeof pageRecordingData.setTimeoutIdentifier === "number"); |
| timeoutIdentifier = pageRecordingData.setTimeoutIdentifier; |
| |
| let recording = WI.timelineManager.activeRecording; |
| let scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script); |
| let records = scriptTimeline.records.filter((x) => x.eventType === WI.ScriptTimelineRecord.EventType.TimerInstalled); |
| InspectorTest.expectEqual(records.length, 1, "Should be 1 TimerInstalled record."); |
| for (let record of records) { |
| InspectorTest.log("DETAILS: " + JSON.stringify(record.details, jsonFilter)); |
| InspectorTest.expectEqual(record.details.timerId, timeoutIdentifier, "ScriptTimelineRecord details should be the setTimeout identifier."); |
| } |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "TimelineEvent.TimerInstall.setInterval", |
| async test() { |
| let pageRecordingData = await InspectorTest.TimelineEvent.captureTimelineWithScript({ |
| expression: `testSetInterval()`, |
| eventType: WI.ScriptTimelineRecord.EventType.TimerRemoved, |
| }); |
| |
| InspectorTest.assert(typeof pageRecordingData.setIntervalIdentifier === "number"); |
| intervalIdentifier = pageRecordingData.setIntervalIdentifier; |
| |
| let recording = WI.timelineManager.activeRecording; |
| let scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script); |
| let records = scriptTimeline.records.filter((x) => x.eventType === WI.ScriptTimelineRecord.EventType.TimerInstalled); |
| InspectorTest.expectEqual(records.length, 1, "Should be 1 TimerInstalled record."); |
| for (let record of records) { |
| InspectorTest.log("DETAILS: " + JSON.stringify(record.details, jsonFilter)); |
| InspectorTest.expectEqual(record.details.timerId, pageRecordingData.setIntervalIdentifier, "ScriptTimelineRecord details should be the setInterval identifier."); |
| } |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "SanityCheck", |
| async test() { |
| InspectorTest.expectThat(timeoutIdentifier !== intervalIdentifier, "The setTimeout identifier and setInterval identifiers should be different."); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests 'TimerInstall' Timeline event records.</p> |
| </body> |
| </html> |