1 function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
2 const CANVAS_WIDTH = 200;
3 const CANVAS_HEIGHT = 100;
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 testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
41 "rgb(255, 255, 255)", drawWindowFlags);
42 refCx.fillStyle = "fuchsia";
43 refCx.fillRect(10, 10, 20, 20);
44 refCx.fillStyle = "aqua";
45 refCx.fillRect(50, 10, 20, 20);
46 refCx.fillStyle = "yellow";
47 refCx.fillRect(90, 10, 20, 20);
48 assertSnapshots(testCanvas, refCanvas, true /* equal */,
49 "full draw of source on white background", "reference");
52 testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
53 "rgb(255, 255, 0)", drawWindowFlags);
54 assertSnapshots(testCanvas, refCanvas,
55 !transparentBackground /* not equal */,
56 "full draw of source on yellow background", "reference");
59 refCx.fillStyle = "fuchsia";
60 refCx.fillRect(10, 10, 20, 20);
61 refCx.fillStyle = "aqua";
62 refCx.fillRect(50, 10, 20, 20);
63 refCx.fillStyle = "yellow";
64 refCx.fillRect(90, 10, 20, 20);
66 assertSnapshots(testCanvas, refCanvas, transparentBackground /* equal */,
67 "full draw of source on yellow background", "reference");
69 // Test drawing a region within the document.
73 testCx.translate(17, 31);
74 testWrapCx.drawWindow(win, 40, 0, 40, 40,
75 "white", drawWindowFlags);
77 refCx.fillStyle = "aqua";
78 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
80 assertSnapshots(testCanvas, refCanvas, true /* equal */,
81 "draw of subrect of source with matching background",
86 testCx.translate(17, 31);
87 testWrapCx.drawWindow(win, 40, 0, 35, 45,
88 "green", drawWindowFlags);
90 if (transparentBackground) {
91 refCx.fillStyle = "green";
93 refCx.fillStyle = "white";
95 refCx.fillRect(17, 31, 35, 45);
96 refCx.fillStyle = "aqua";
97 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
99 assertSnapshots(testCanvas, refCanvas, true /* equal */,
100 "draw of subrect of source with different background",
103 // Test transparency of background not disturbing what is behind
106 testCx.translate(17, 31);
107 testWrapCx.drawWindow(win, 40, 0, 35, 45,
108 "transparent", drawWindowFlags);
110 if (!transparentBackground) {
111 refCx.fillStyle = "white";
112 refCx.fillRect(17, 31, 35, 45);
114 refCx.fillStyle = "aqua";
115 refCx.fillRect(17 + 10, 31 + 10, 20, 20);
117 assertSnapshots(testCanvas, refCanvas, true /* equal */,
118 "draw of subrect of source with different background",
121 // Test that multiple drawWindow calls draw at correct positions.
124 testCx.translate(9, 3);
125 // 5, 8 is 5, 2 from the corner of the fuchsia square
126 testWrapCx.drawWindow(win, 5, 8, 30, 25,
127 "maroon", drawWindowFlags);
128 // 35, 0 is 15, 10 from the corner of the aqua square
129 testWrapCx.drawWindow(win, 35, 0, 50, 40,
130 "transparent", drawWindowFlags);
131 testCx.translate(15, 0);
132 // 85, 5 is 5, 5 from the corner of the yellow square
133 testWrapCx.drawWindow(win, 85, 5, 30, 25,
134 "transparent", drawWindowFlags);
136 if (transparentBackground) {
137 refCx.fillStyle = "maroon";
138 refCx.fillRect(9, 3, 30, 25);
139 refCx.fillStyle = "fuchsia";
140 refCx.fillRect(9 + 5, 3 + 2, 20, 20);
142 refCx.fillStyle = "white";
143 refCx.fillRect(9, 3, 50, 40);
145 refCx.fillStyle = "aqua";
146 refCx.fillRect(9 + 15, 3 + 10, 20, 20);
147 if (!transparentBackground) {
148 refCx.fillStyle = "white";
149 refCx.fillRect(9 + 15, 3, 30, 25);
151 refCx.fillStyle = "yellow";
152 refCx.fillRect(9 + 15 + 5, 3 + 0 + 5, 20, 20);
154 assertSnapshots(testCanvas, refCanvas, true /* equal */,
155 "multiple drawWindow calls on top of each other",