5 <title>Test for drawSnapshot
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <script src=
"/tests/SimpleTest/WindowSnapshot.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
24 <script type=
"application/javascript">
25 function make_canvas() {
26 var canvas = document.createElement(
"canvas");
27 canvas.setAttribute(
"height",
2000);
28 canvas.setAttribute(
"width",
500);
32 SimpleTest.waitForExplicitFinish();
33 window.addEventListener(
"load", runTests);
35 window.scrollTo(
0,
1000);
37 async function runTests(event) {
38 var testCanvas = make_canvas();
39 var testCx = testCanvas.getContext(
"2d");
40 var testWrapCx = SpecialPowers.wrap(testCx);
42 // Take a snapshot of the page while scrolled down, so that the fixed header will
43 // be visually in the middle of the root scroll frame, but should still be at the
44 // top of the snapshot (since snapshots with a rect are taken relative to the document).
45 var rect = new window.DOMRect(
0,
0,
500,
2000);
46 let image = await SpecialPowers.snapshotContext(window, rect,
"rgb(255, 255, 255)", true);
47 testWrapCx.drawImage(image,
0,
0);
49 var refCanvas = make_canvas();
50 var refCx = refCanvas.getContext(
"2d");
52 // Construct a reference image with an equivalent red square at the top.
53 refCx.fillStyle =
"white";
54 refCx.fillRect(
0,
0,
500,
2000);
55 refCx.fillStyle =
"red";
56 refCx.fillRect(
0,
0,
500,
200);
58 assertSnapshots(testCanvas, refCanvas, true, null,
"position:fixed element with scrolling",
"reference");