Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | function runDrawWindowTests(win, drawWindowFlags, transparentBackground) { |
michael@0 | 2 | const CANVAS_WIDTH = 200; |
michael@0 | 3 | const CANVAS_HEIGHT = 100; |
michael@0 | 4 | |
michael@0 | 5 | function make_canvas() { |
michael@0 | 6 | var canvas = document.createElement("canvas"); |
michael@0 | 7 | canvas.setAttribute("height", CANVAS_HEIGHT); |
michael@0 | 8 | canvas.setAttribute("width", CANVAS_WIDTH); |
michael@0 | 9 | document.body.appendChild(canvas); |
michael@0 | 10 | return canvas; |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | var testCanvas = make_canvas(); |
michael@0 | 14 | var refCanvas = make_canvas(); |
michael@0 | 15 | |
michael@0 | 16 | var testCx = testCanvas.getContext("2d"); |
michael@0 | 17 | var refCx = refCanvas.getContext("2d"); |
michael@0 | 18 | |
michael@0 | 19 | var testWrapCx = SpecialPowers.wrap(testCx); |
michael@0 | 20 | var refWrapCx = SpecialPowers.wrap(refCx); |
michael@0 | 21 | |
michael@0 | 22 | function clearRef(fillStyle) { |
michael@0 | 23 | refCx.setTransform(1, 0, 0, 1, 0, 0); |
michael@0 | 24 | refCx.fillStyle = fillStyle; |
michael@0 | 25 | refCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); |
michael@0 | 26 | } |
michael@0 | 27 | function clearTest(fillStyle) { |
michael@0 | 28 | testCx.setTransform(1, 0, 0, 1, 0, 0); |
michael@0 | 29 | testCx.fillStyle = fillStyle; |
michael@0 | 30 | testCx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); |
michael@0 | 31 | } |
michael@0 | 32 | function clear(fillStyle) { |
michael@0 | 33 | clearRef(fillStyle); |
michael@0 | 34 | clearTest(fillStyle); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | // Basic tests of drawing the whole document on a background |
michael@0 | 38 | |
michael@0 | 39 | clear("white"); |
michael@0 | 40 | testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, |
michael@0 | 41 | "rgb(255, 255, 255)", drawWindowFlags); |
michael@0 | 42 | refCx.fillStyle = "fuchsia"; |
michael@0 | 43 | refCx.fillRect(10, 10, 20, 20); |
michael@0 | 44 | refCx.fillStyle = "aqua"; |
michael@0 | 45 | refCx.fillRect(50, 10, 20, 20); |
michael@0 | 46 | refCx.fillStyle = "yellow"; |
michael@0 | 47 | refCx.fillRect(90, 10, 20, 20); |
michael@0 | 48 | assertSnapshots(testCanvas, refCanvas, true /* equal */, |
michael@0 | 49 | "full draw of source on white background", "reference"); |
michael@0 | 50 | |
michael@0 | 51 | clearTest("white"); |
michael@0 | 52 | testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, |
michael@0 | 53 | "rgb(255, 255, 0)", drawWindowFlags); |
michael@0 | 54 | assertSnapshots(testCanvas, refCanvas, |
michael@0 | 55 | !transparentBackground /* not equal */, |
michael@0 | 56 | "full draw of source on yellow background", "reference"); |
michael@0 | 57 | |
michael@0 | 58 | clearRef("yellow"); |
michael@0 | 59 | refCx.fillStyle = "fuchsia"; |
michael@0 | 60 | refCx.fillRect(10, 10, 20, 20); |
michael@0 | 61 | refCx.fillStyle = "aqua"; |
michael@0 | 62 | refCx.fillRect(50, 10, 20, 20); |
michael@0 | 63 | refCx.fillStyle = "yellow"; |
michael@0 | 64 | refCx.fillRect(90, 10, 20, 20); |
michael@0 | 65 | |
michael@0 | 66 | assertSnapshots(testCanvas, refCanvas, transparentBackground /* equal */, |
michael@0 | 67 | "full draw of source on yellow background", "reference"); |
michael@0 | 68 | |
michael@0 | 69 | // Test drawing a region within the document. |
michael@0 | 70 | |
michael@0 | 71 | clear("white"); |
michael@0 | 72 | |
michael@0 | 73 | testCx.translate(17, 31); |
michael@0 | 74 | testWrapCx.drawWindow(win, 40, 0, 40, 40, |
michael@0 | 75 | "white", drawWindowFlags); |
michael@0 | 76 | |
michael@0 | 77 | refCx.fillStyle = "aqua"; |
michael@0 | 78 | refCx.fillRect(17 + 10, 31 + 10, 20, 20); |
michael@0 | 79 | |
michael@0 | 80 | assertSnapshots(testCanvas, refCanvas, true /* equal */, |
michael@0 | 81 | "draw of subrect of source with matching background", |
michael@0 | 82 | "reference"); |
michael@0 | 83 | |
michael@0 | 84 | clear("blue"); |
michael@0 | 85 | |
michael@0 | 86 | testCx.translate(17, 31); |
michael@0 | 87 | testWrapCx.drawWindow(win, 40, 0, 35, 45, |
michael@0 | 88 | "green", drawWindowFlags); |
michael@0 | 89 | |
michael@0 | 90 | if (transparentBackground) { |
michael@0 | 91 | refCx.fillStyle = "green"; |
michael@0 | 92 | } else { |
michael@0 | 93 | refCx.fillStyle = "white"; |
michael@0 | 94 | } |
michael@0 | 95 | refCx.fillRect(17, 31, 35, 45); |
michael@0 | 96 | refCx.fillStyle = "aqua"; |
michael@0 | 97 | refCx.fillRect(17 + 10, 31 + 10, 20, 20); |
michael@0 | 98 | |
michael@0 | 99 | assertSnapshots(testCanvas, refCanvas, true /* equal */, |
michael@0 | 100 | "draw of subrect of source with different background", |
michael@0 | 101 | "reference"); |
michael@0 | 102 | |
michael@0 | 103 | // Test transparency of background not disturbing what is behind |
michael@0 | 104 | clear("blue"); |
michael@0 | 105 | |
michael@0 | 106 | testCx.translate(17, 31); |
michael@0 | 107 | testWrapCx.drawWindow(win, 40, 0, 35, 45, |
michael@0 | 108 | "transparent", drawWindowFlags); |
michael@0 | 109 | |
michael@0 | 110 | if (!transparentBackground) { |
michael@0 | 111 | refCx.fillStyle = "white"; |
michael@0 | 112 | refCx.fillRect(17, 31, 35, 45); |
michael@0 | 113 | } |
michael@0 | 114 | refCx.fillStyle = "aqua"; |
michael@0 | 115 | refCx.fillRect(17 + 10, 31 + 10, 20, 20); |
michael@0 | 116 | |
michael@0 | 117 | assertSnapshots(testCanvas, refCanvas, true /* equal */, |
michael@0 | 118 | "draw of subrect of source with different background", |
michael@0 | 119 | "reference"); |
michael@0 | 120 | |
michael@0 | 121 | // Test that multiple drawWindow calls draw at correct positions. |
michael@0 | 122 | clear("blue"); |
michael@0 | 123 | |
michael@0 | 124 | testCx.translate(9, 3); |
michael@0 | 125 | // 5, 8 is 5, 2 from the corner of the fuchsia square |
michael@0 | 126 | testWrapCx.drawWindow(win, 5, 8, 30, 25, |
michael@0 | 127 | "maroon", drawWindowFlags); |
michael@0 | 128 | // 35, 0 is 15, 10 from the corner of the aqua square |
michael@0 | 129 | testWrapCx.drawWindow(win, 35, 0, 50, 40, |
michael@0 | 130 | "transparent", drawWindowFlags); |
michael@0 | 131 | testCx.translate(15, 0); |
michael@0 | 132 | // 85, 5 is 5, 5 from the corner of the yellow square |
michael@0 | 133 | testWrapCx.drawWindow(win, 85, 5, 30, 25, |
michael@0 | 134 | "transparent", drawWindowFlags); |
michael@0 | 135 | |
michael@0 | 136 | if (transparentBackground) { |
michael@0 | 137 | refCx.fillStyle = "maroon"; |
michael@0 | 138 | refCx.fillRect(9, 3, 30, 25); |
michael@0 | 139 | refCx.fillStyle = "fuchsia"; |
michael@0 | 140 | refCx.fillRect(9 + 5, 3 + 2, 20, 20); |
michael@0 | 141 | } else { |
michael@0 | 142 | refCx.fillStyle = "white"; |
michael@0 | 143 | refCx.fillRect(9, 3, 50, 40); |
michael@0 | 144 | } |
michael@0 | 145 | refCx.fillStyle = "aqua"; |
michael@0 | 146 | refCx.fillRect(9 + 15, 3 + 10, 20, 20); |
michael@0 | 147 | if (!transparentBackground) { |
michael@0 | 148 | refCx.fillStyle = "white"; |
michael@0 | 149 | refCx.fillRect(9 + 15, 3, 30, 25); |
michael@0 | 150 | } |
michael@0 | 151 | refCx.fillStyle = "yellow"; |
michael@0 | 152 | refCx.fillRect(9 + 15 + 5, 3 + 0 + 5, 20, 20); |
michael@0 | 153 | |
michael@0 | 154 | assertSnapshots(testCanvas, refCanvas, true /* equal */, |
michael@0 | 155 | "multiple drawWindow calls on top of each other", |
michael@0 | 156 | "reference"); |
michael@0 | 157 | } |