blob: 9b78fdd2413d85daeee79628d651d2c2da4a53ae [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/recording-utilities.js"></script>
<script src="resources/recording-2d.js"></script>
<script>
function test() {
let suite = InspectorTest.createAsyncSuite("Canvas.recording2D");
suite.addTestCase({
name: "Canvas.recording2D.ExistingSaves",
description: "Check that existing save calls are sent to the frontend.",
test(resolve, reject) {
let canvas = getCanvas(WI.Canvas.ContextType.Canvas2D);
if (!canvas) {
reject("Missing 2D canvas.");
return;
}
async function logStates(recording) {
async function compare(index, expected) {
let state = await WI.RecordingState.swizzleInitialState(recording, recording.initialState.states[index]);
InspectorTest.expectEqual(state.get("fillStyle"), expected, `State ${index} should match expected fillStyle value.`)
}
await compare(0, "#000000");
await compare(1, "#ff0000");
await compare(2, "#00ff00");
await compare(3, "#0000ff");
}
canvas.awaitEvent(WI.Canvas.Event.RecordingStopped)
.then((event) => {
let {recording} = event.data;
InspectorTest.expectEqual(recording.initialState.states.length, 4, "There should be 4 existing states.");
logStates(recording)
.then(resolve, reject);
});
canvas.awaitEvent(WI.Canvas.Event.RecordingStarted)
.then((event) => {
InspectorTest.evaluateInPage(`performSavePostActions()`).catch(reject);
});
InspectorTest.evaluateInPage(`performSavePreActions()`)
.then(() => {
const frameCount = 1;
CanvasAgent.startRecording(canvas.identifier, frameCount).catch(reject);
}, reject);
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="load()">
<p>Test that CanvasManager is able to record actions made to 2D canvas contexts.</p>
</body>
</html>