summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/file_drawWindow_common.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/canvas/test/file_drawWindow_common.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/canvas/test/file_drawWindow_common.js')
-rw-r--r--dom/canvas/test/file_drawWindow_common.js159
1 files changed, 159 insertions, 0 deletions
diff --git a/dom/canvas/test/file_drawWindow_common.js b/dom/canvas/test/file_drawWindow_common.js
new file mode 100644
index 000000000..2f4c385d3
--- /dev/null
+++ b/dom/canvas/test/file_drawWindow_common.js
@@ -0,0 +1,159 @@
+const CANVAS_WIDTH = 200;
+const CANVAS_HEIGHT = 100;
+
+function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
+
+ function make_canvas() {
+ var canvas = document.createElement("canvas");
+ canvas.setAttribute("height", CANVAS_HEIGHT);
+ canvas.setAttribute("width", CANVAS_WIDTH);
+ document.body.appendChild(canvas);
+ return canvas;
+ }
+
+ var testCanvas = make_canvas();
+ var refCanvas = make_canvas();
+
+ var testCx = testCanvas.getContext("2d");
+ var refCx = refCanvas.getContext("2d");
+
+ var testWrapCx = SpecialPowers.wrap(testCx);
+ var refWrapCx = SpecialPowers.wrap(refCx);
+
+ function clearRef(fillStyle) {
+ refCx.setTransform(1, 0, 0, 1, 0, 0);
+ refCx.fillStyle = fillStyle;
+ refCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
+ }
+ function clearTest(fillStyle) {
+ testCx.setTransform(1, 0, 0, 1, 0, 0);
+ testCx.fillStyle = fillStyle;
+ testCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
+ }
+ function clear(fillStyle) {
+ clearRef(fillStyle);
+ clearTest(fillStyle);
+ }
+
+ // Basic tests of drawing the whole document on a background
+
+ clear("white");
+ testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
+ "rgb(255, 255, 255)", drawWindowFlags);
+ refCx.fillStyle = "fuchsia";
+ refCx.fillRect(10, 10, 20, 20);
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(50, 10, 20, 20);
+ refCx.fillStyle = "yellow";
+ refCx.fillRect(90, 10, 20, 20);
+ assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
+ "full draw of source on white background", "reference");
+
+ clearTest("white");
+ testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
+ "rgb(255, 255, 0)", drawWindowFlags);
+ assertSnapshots(testCanvas, refCanvas,
+ !transparentBackground /* not equal */, null /*no fuzz*/,
+ "full draw of source on yellow background", "reference");
+
+ clearRef("yellow");
+ refCx.fillStyle = "fuchsia";
+ refCx.fillRect(10, 10, 20, 20);
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(50, 10, 20, 20);
+ refCx.fillStyle = "yellow";
+ refCx.fillRect(90, 10, 20, 20);
+
+ assertSnapshots(testCanvas, refCanvas, transparentBackground /* equal */,
+ null /*no fuzz*/,
+ "full draw of source on yellow background", "reference");
+
+ // Test drawing a region within the document.
+
+ clear("white");
+
+ testCx.translate(17, 31);
+ testWrapCx.drawWindow(win, 40, 0, 40, 40,
+ "white", drawWindowFlags);
+
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(17 + 10, 31 + 10, 20, 20);
+
+ assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
+ "draw of subrect of source with matching background",
+ "reference");
+
+ clear("blue");
+
+ testCx.translate(17, 31);
+ testWrapCx.drawWindow(win, 40, 0, 35, 45,
+ "green", drawWindowFlags);
+
+ if (transparentBackground) {
+ refCx.fillStyle = "green";
+ } else {
+ refCx.fillStyle = "white";
+ }
+ refCx.fillRect(17, 31, 35, 45);
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(17 + 10, 31 + 10, 20, 20);
+
+ assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
+ "draw of subrect of source with different background",
+ "reference");
+
+ // Test transparency of background not disturbing what is behind
+ clear("blue");
+
+ testCx.translate(17, 31);
+ testWrapCx.drawWindow(win, 40, 0, 35, 45,
+ "transparent", drawWindowFlags);
+
+ if (!transparentBackground) {
+ refCx.fillStyle = "white";
+ refCx.fillRect(17, 31, 35, 45);
+ }
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(17 + 10, 31 + 10, 20, 20);
+
+ assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
+ "draw of subrect of source with different background",
+ "reference");
+
+ // Test that multiple drawWindow calls draw at correct positions.
+ clear("blue");
+
+ testCx.translate(9, 3);
+ // 5, 8 is 5, 2 from the corner of the fuchsia square
+ testWrapCx.drawWindow(win, 5, 8, 30, 25,
+ "maroon", drawWindowFlags);
+ // 35, 0 is 15, 10 from the corner of the aqua square
+ testWrapCx.drawWindow(win, 35, 0, 50, 40,
+ "transparent", drawWindowFlags);
+ testCx.translate(15, 0);
+ // 85, 5 is 5, 5 from the corner of the yellow square
+ testWrapCx.drawWindow(win, 85, 5, 30, 25,
+ "transparent", drawWindowFlags);
+
+ if (transparentBackground) {
+ refCx.fillStyle = "maroon";
+ refCx.fillRect(9, 3, 30, 25);
+ refCx.fillStyle = "fuchsia";
+ refCx.fillRect(9 + 5, 3 + 2, 20, 20);
+ } else {
+ refCx.fillStyle = "white";
+ refCx.fillRect(9, 3, 50, 40);
+ }
+ refCx.fillStyle = "aqua";
+ refCx.fillRect(9 + 15, 3 + 10, 20, 20);
+ if (!transparentBackground) {
+ refCx.fillStyle = "white";
+ refCx.fillRect(9 + 15, 3, 30, 25);
+ }
+ refCx.fillStyle = "yellow";
+ refCx.fillRect(9 + 15 + 5, 3 + 0 + 5, 20, 20);
+
+ assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
+ "multiple drawWindow calls on top of each other",
+ "reference");
+}