blob: cc3507c4bad7be33d5d6e3703a2dac113225ec9b [file] [log] [blame]
<!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.TimerFire");
let timeoutIdentifier = undefined;
let intervalIdentifier = undefined;
suite.addTestCase({
name: "TimelineEvent.TimerFire.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.TimerFired);
InspectorTest.expectEqual(records.length, 1, "Should be 1 TimerFired record.");
for (let record of records) {
InspectorTest.log("DETAILS: " + typeof record.details);
InspectorTest.expectEqual(record.details, timeoutIdentifier, "ScriptTimelineRecord details should be the setTimeout identifier.");
}
}
});
suite.addTestCase({
name: "TimelineEvent.TimerFire.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.TimerFired);
InspectorTest.expectEqual(records.length, 3, "Should be 3 TimerFired records.");
for (let record of records) {
InspectorTest.log("DETAILS: " + typeof record.details);
InspectorTest.expectEqual(record.details, 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 'TimerFire' Timeline event records.</p>
</body>
</html>