1 const CANVAS_WIDTH = 200;
2 const CANVAS_HEIGHT = 100;
4 async function runDrawWindowTests(snapshotCallback, transparentBackground) {
5 function make_canvas() {
6 var canvas = document.createElement("canvas");
7 canvas.setAttribute("height", CANVAS_HEIGHT);
8 canvas.setAttribute("width", CANVAS_WIDTH);
9 document.body.appendChild(canvas);
13 var testCanvas = make_canvas();
14 var refCanvas = make_canvas();
16 var testCx = testCanvas.getContext("2d");
17 var refCx = refCanvas.getContext("2d");
19 var testWrapCx = SpecialPowers.wrap(testCx);
20 var refWrapCx = SpecialPowers.wrap(refCx);
22 function clearRef(fillStyle) {
23 refCx.setTransform(1, 0, 0, 1, 0, 0);
24 refCx.fillStyle = fillStyle;
25 refCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
27 function clearTest(fillStyle) {
28 testCx.setTransform(1, 0, 0, 1, 0, 0);
29 testCx.fillStyle = fillStyle;
30 testCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
32 function clear(fillStyle) {
37 // Basic tests of drawing the whole document on a background
40 await snapshotCallback(
48 refCx.fillStyle = "fuchsia";
49 refCx.fillRect(10, 10, 20, 20);
50 refCx.fillStyle = "aqua";
51 refCx.fillRect(50, 10, 20, 20);
52 refCx.fillStyle = "yellow";
53 refCx.fillRect(90, 10, 20, 20);
59 "full draw of source on white background",
64 await snapshotCallback(
75 !transparentBackground /* not equal */,
77 "full draw of source on yellow background",
82 refCx.fillStyle = "fuchsia";
83 refCx.fillRect(10, 10, 20, 20);
84 refCx.fillStyle = "aqua";
85 refCx.fillRect(50, 10, 20, 20);
86 refCx.fillStyle = "yellow";
87 refCx.fillRect(90, 10, 20, 20);
92 transparentBackground /* equal */,
94 "full draw of source on yellow background",
98 // Test drawing a region within the document.
102 testCx.translate(17, 31);
103 await snapshotCallback(testWrapCx, 40, 0, 40, 40, "white");
105 refCx.fillStyle = "aqua";
106 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
113 "draw of subrect of source with matching background",
119 testCx.translate(17, 31);
120 await snapshotCallback(testWrapCx, 40, 0, 35, 45, "green");
122 if (transparentBackground) {
123 refCx.fillStyle = "green";
125 refCx.fillStyle = "white";
127 refCx.fillRect(17, 31, 35, 45);
128 refCx.fillStyle = "aqua";
129 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
136 "draw of subrect of source with different background",
140 // Test transparency of background not disturbing what is behind
143 testCx.translate(17, 31);
144 await snapshotCallback(testWrapCx, 40, 0, 35, 45, "transparent");
146 if (!transparentBackground) {
147 refCx.fillStyle = "white";
148 refCx.fillRect(17, 31, 35, 45);
150 refCx.fillStyle = "aqua";
151 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
158 "draw of subrect of source with different background",
162 // Test that multiple drawWindow calls draw at correct positions.
165 testCx.translate(9, 3);
166 // 5, 8 is 5, 2 from the corner of the fuchsia square
167 await snapshotCallback(testWrapCx, 5, 8, 30, 25, "maroon");
168 // 35, 0 is 15, 10 from the corner of the aqua square
169 await snapshotCallback(testWrapCx, 35, 0, 50, 40, "transparent");
170 testCx.translate(15, 0);
171 // 85, 5 is 5, 5 from the corner of the yellow square
172 await snapshotCallback(testWrapCx, 85, 5, 30, 25, "transparent");
174 if (transparentBackground) {
175 refCx.fillStyle = "maroon";
176 refCx.fillRect(9, 3, 30, 25);
177 refCx.fillStyle = "fuchsia";
178 refCx.fillRect(9 + 5, 3 + 2, 20, 20);
180 refCx.fillStyle = "white";
181 refCx.fillRect(9, 3, 50, 40);
183 refCx.fillStyle = "aqua";
184 refCx.fillRect(9 + 15, 3 + 10, 20, 20);
185 if (!transparentBackground) {
186 refCx.fillStyle = "white";
187 refCx.fillRect(9 + 15, 3, 30, 25);
189 refCx.fillStyle = "yellow";
190 refCx.fillRect(9 + 15 + 5, 3 + 0 + 5, 20, 20);
197 "multiple drawWindow calls on top of each other",