Bug 1485730 - [marionette] Limit width and height of created canvas to 32767 pixels. r=ato

The Skia GFX backend limits the dimension of canvases to a maximum
of 32767 for the width and height.

--HG--
extra : rebase_source : b0e1f60cc2f0c1b83e7cb7551216323983cb3407
This commit is contained in:
Henrik Skupin 2018-08-28 13:40:11 +02:00
parent ef28c22d42
commit 65c9584a67
2 changed files with 25 additions and 2 deletions

View File

@ -7,13 +7,16 @@
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const {InvalidArgumentError} = ChromeUtils.import("chrome://marionette/content/error.js", {});
const {Log} = ChromeUtils.import("chrome://marionette/content/log.js", {});
XPCOMUtils.defineLazyGetter(this, "logger", Log.get);
XPCOMUtils.defineLazyGlobalGetters(this, ["crypto"]);
this.EXPORTED_SYMBOLS = ["capture"];
const CONTEXT_2D = "2d";
const BG_COLOUR = "rgb(255,255,255)";
const MAX_SKIA_DIMENSIONS = 32767;
const PNG_MIME = "image/png";
const XHTML_NS = "http://www.w3.org/1999/xhtml";
@ -112,9 +115,24 @@ capture.canvas = function(win, left, top, width, height,
const scale = win.devicePixelRatio;
if (canvas === null) {
let canvasWidth = width * scale;
let canvasHeight = height * scale;
if (canvasWidth > MAX_SKIA_DIMENSIONS) {
logger.warn("Reducing screenshot width because it exceeds " +
MAX_SKIA_DIMENSIONS + " pixels");
canvasWidth = MAX_SKIA_DIMENSIONS;
}
if (canvasHeight > MAX_SKIA_DIMENSIONS) {
logger.warn("Reducing screenshot height because it exceeds " +
MAX_SKIA_DIMENSIONS + " pixels");
canvasHeight = MAX_SKIA_DIMENSIONS;
}
canvas = win.document.createElementNS(XHTML_NS, "canvas");
canvas.width = width * scale;
canvas.height = height * scale;
canvas.width = canvasWidth;
canvas.height = canvasHeight;
}
let ctx = canvas.getContext(CONTEXT_2D);

View File

@ -294,6 +294,11 @@ class TestScreenCaptureContent(WindowManagerMixin, ScreenCaptureTestCase):
self.assertRaises(NoSuchWindowException, self.marionette.screenshot)
self.marionette.switch_to_window(self.start_tab)
def test_capture_vertical_bounds(self):
self.marionette.navigate(inline("<body style='margin-top: 32768px'>foo"))
screenshot = self.marionette.screenshot()
self.assert_png(screenshot)
def test_capture_element(self):
self.marionette.navigate(box)
el = self.marionette.find_element(By.TAG_NAME, "div")