blob: 46867654d28f520fceb74d4bae9e248f0b07ffb1 [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 testRequestScreenshots() {
document.getElementById("test").style.width = "200px";
savePageData({invalidatedLayout: true});
}
function test()
{
let suite = InspectorTest.createAsyncSuite("TimelineEvent.FireScreenshots");
suite.addTestCase({
name: "TimelineEvent.FireScreenshots.requestScreenshots",
async test() {
WI.timelineManager.enabledTimelineTypes = [WI.TimelineRecord.Type.Screenshots];
let pageRecordingData = await InspectorTest.TimelineEvent.captureTimelineWithScript({
expression: `testRequestScreenshots()`,
timelineType: WI.TimelineRecord.Type.Screenshots,
});
InspectorTest.assert(pageRecordingData.invalidatedLayout);
let recording = WI.timelineManager.activeRecording;
let screenshotTimeline = recording.timelines.get(WI.TimelineRecord.Type.Screenshots);
let records = screenshotTimeline.records;
let oldLength = records.length;
InspectorTest.expectGreaterThan(oldLength, 0, "Should have at least 1 Screenshot record.");
InspectorTest.assert(records[0].startTime, "Screenshot record should have a timestamp.");
InspectorTest.expectGreaterThan(records[0].imageData.length, 0, "Screenshot record should contain image data.");
InspectorTest.log("Adding screenshot from console...");
await InspectorTest.evaluateInPage(`console.screenshot()`);
InspectorTest.expectEqual(records.length, oldLength + 1, "Should have added another Screenshot record.");
InspectorTest.assert(records[oldLength].startTime, "Screenshot record from console should have a timestamp.");
InspectorTest.expectGreaterThan(records[oldLength].imageData.length, 0, "Screenshot record from console should contain image data.");
InspectorTest.assert(records[oldLength].startTime > records[oldLength - 1].startTime, "Screenshot record from console should be newer than the last screenshot record.");
InspectorTest.assert(records[oldLength].imageData !== records[oldLength - 1].imageData, "Screenshot record from console should have different content than the last screenshot record.");
}
});
suite.runTestCasesAndFinish();
}
</script>
<style>
#test {
width: 100px;
height: 100px;
background-color: darkseagreen;
}
</style>
</head>
<body onload="runTest()">
<p>Tests 'Screenshot' Timeline event records.</p>
<div id="test"></div>
</body>
</html>