blob: 535095762b390f2ce3fb5a9696ade6113433c2fd [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function load() {
window.context2d = document.createElement("canvas").getContext("2d");
window.context2d.fillStyle = "rgba(255, 0, 0, 0.5)"; // Half-transparent red
window.context2d.fillRect(0, 0, 300, 150);
runTest();
}
function test() {
let suite = InspectorTest.createAsyncSuite("Canvas.requestContent2D");
suite.addTestCase({
name: "Canvas.requestContent2D.validCanvasId",
description: "Get the base64 encoded data for the canvas on the page with the given type.",
test(resolve, reject) {
let canvas = WI.canvasManager.canvases.find((canvas) => canvas.contextType === WI.Canvas.ContextType.Canvas2D);
if (!canvas) {
reject(`Missing Canvas.`);
return;
}
CanvasAgent.requestContent(canvas.identifier)
.then(({content}) => InspectorTest.expectGreaterThan(content.length, "data:image/png;base64,".length, "Content should not be empty."))
.then(resolve, reject);
}
});
// ------
suite.addTestCase({
name: "Canvas.requestContent.invalidCanvasId",
description: "Invalid canvas identifiers should cause an error.",
test(resolve, reject) {
const canvasId = "DOES_NOT_EXIST";
CanvasAgent.requestContent(canvasId, (error) => {
InspectorTest.expectThat(error, "Should produce an error.");
InspectorTest.log("Error: " + error);
resolve();
});
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="load()">
<p>Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the 2D canvas.</p>
</body>
</html>