Bug 1425255 - Clamp the screenshot cropping to the screen.avail* properties so we don't include parts of the Windows task bar. r?mattn
MozReview-Commit-ID: 5uTfF2Epvkr
--- a/browser/tools/mozscreenshots/browser_boundingbox.js
+++ b/browser/tools/mozscreenshots/browser_boundingbox.js
@@ -1,27 +1,28 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
+const scale = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIBaseWindow)
+ .devicePixelsPerDesktopPixel;
+
add_task(async function() {
- const scale = window.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIBaseWindow)
- .devicePixelsPerDesktopPixel;
let {bounds, rects} = TestRunner._findBoundingBox(["#tabbrowser-tabs"]);
- let element = document.querySelector("#tabbrowser-tabs");
- let tabBar = element.ownerDocument.getBoxObjectFor(element);
+ let tabbrowserTabs = document.querySelector("#tabbrowser-tabs");
+ let tabbrowserTabsBO = document.getBoxObjectFor(tabbrowserTabs);
// Calculate expected values
- let expectedLeft = scale * (tabBar.screenX - TestRunner.croppingPadding);
- let expectedTop = scale * (tabBar.screenY - TestRunner.croppingPadding);
- let expectedRight = scale * (tabBar.width + TestRunner.croppingPadding * 2) + expectedLeft;
- let expectedBottom = scale * (tabBar.height + TestRunner.croppingPadding * 2) + expectedTop;
+ let expectedLeft = scale * (tabbrowserTabsBO.screenX - TestRunner.croppingPadding);
+ let expectedTop = scale * (tabbrowserTabsBO.screenY - TestRunner.croppingPadding);
+ let expectedRight = scale * (tabbrowserTabsBO.width + TestRunner.croppingPadding * 2) + expectedLeft;
+ let expectedBottom = scale * (tabbrowserTabsBO.height + TestRunner.croppingPadding * 2) + expectedTop;
// Calculate browser region
let windowLeft = window.screenX * scale;
let windowTop = window.screenY * scale;
let windowRight = window.outerWidth * scale + windowLeft;
let windowBottom = window.outerHeight * scale + windowTop;
// Adjust values based on browser window
@@ -43,60 +44,73 @@ add_task(async function() {
"Checking _findBoundingBox union.top and rect.top is the same for a single selector");
is(bounds.bottom, rects[0].bottom,
"Checking _findBoundingBox union.bottom and rect.bottom is the same for a single selector");
let result = TestRunner._findBoundingBox(["#forward-button", "#TabsToolbar"]);
bounds = result.bounds;
rects = result.rects;
- element = document.querySelector("#TabsToolbar");
- let tabToolbar = element.ownerDocument.getBoxObjectFor(element);
- element = document.querySelector("#forward-button");
- let fButton = element.ownerDocument.getBoxObjectFor(element);
+ let tabsToolbar = document.querySelector("#TabsToolbar");
+ let tabsToolbarBO = document.getBoxObjectFor(tabsToolbar);
+ let forwardButton = document.querySelector("#forward-button");
+ let fButtonBO = document.getBoxObjectFor(forwardButton);
// Calculate expected values
- expectedLeft = scale * (Math.min(tabToolbar.screenX, fButton.screenX)
- - TestRunner.croppingPadding);
- expectedTop = scale * (Math.min(tabToolbar.screenY, fButton.screenY)
- - TestRunner.croppingPadding);
- expectedRight = scale * (Math.max(tabToolbar.width + tabToolbar.screenX,
- fButton.width + fButton.screenX)
- + TestRunner.croppingPadding);
- expectedBottom = scale * (Math.max(tabToolbar.height + tabToolbar.screenY,
- fButton.height + fButton.screenY)
- + TestRunner.croppingPadding );
+ expectedLeft = scale * (Math.min(tabsToolbarBO.screenX, fButtonBO.screenX)
+ - TestRunner.croppingPadding);
+ expectedTop = scale * (Math.min(tabsToolbarBO.screenY, fButtonBO.screenY)
+ - TestRunner.croppingPadding);
+ expectedRight = scale * (Math.max(tabsToolbarBO.width + tabsToolbarBO.screenX,
+ fButtonBO.width + fButtonBO.screenX)
+ + TestRunner.croppingPadding);
+ expectedBottom = scale * (Math.max(tabsToolbarBO.height + tabsToolbarBO.screenY,
+ fButtonBO.height + fButtonBO.screenY)
+ + TestRunner.croppingPadding);
// Adjust values based on browser window
expectedLeft = Math.max(expectedLeft, windowLeft);
expectedTop = Math.max(expectedTop, windowTop);
expectedRight = Math.min(expectedRight, windowRight);
expectedBottom = Math.min(expectedBottom, windowBottom);
// Check width calculation on union
is(bounds.width, expectedRight - expectedLeft,
"Checking _findBoundingBox union width calculation");
// Check height calculation on union
is(bounds.height, expectedBottom - expectedTop,
"Checking _findBoundingBox union height calculation");
// Check single selector's left position
- is(rects[0].left, Math.max(scale * (fButton.screenX - TestRunner.croppingPadding), windowLeft),
+ is(rects[0].left, Math.max(scale * (fButtonBO.screenX - TestRunner.croppingPadding), windowLeft),
"Checking single selector's left position when _findBoundingBox has multiple selectors");
// Check single selector's right position
- is(rects[0].right, Math.min(scale * (fButton.width + fButton.screenX + TestRunner.croppingPadding), windowRight),
+ is(rects[0].right, Math.min(scale * (fButtonBO.width + fButtonBO.screenX + TestRunner.croppingPadding), windowRight),
"Checking single selector's right position when _findBoundingBox has multiple selectors");
// Check single selector's top position
- is(rects[0].top, Math.max(scale * (fButton.screenY - TestRunner.croppingPadding), windowTop),
+ is(rects[0].top, Math.max(scale * (fButtonBO.screenY - TestRunner.croppingPadding), windowTop),
"Checking single selector's top position when _findBoundingBox has multiple selectors");
// Check single selector's bottom position
- is(rects[0].bottom, Math.min(scale * (fButton.height + fButton.screenY + TestRunner.croppingPadding), windowBottom),
+ is(rects[0].bottom, Math.min(scale * (fButtonBO.height + fButtonBO.screenY + TestRunner.croppingPadding), windowBottom),
"Checking single selector's bottom position when _findBoundingBox has multiple selectors");
// Check that nonexistent selectors throws an exception
Assert.throws(() => {
TestRunner._findBoundingBox(["#does_not_exist"]);
}, "No element for '#does_not_exist' found.", "Checking that nonexistent selectors throws an exception");
// Check that no selectors throws an exception
Assert.throws(() => {
TestRunner._findBoundingBox([]);
}, "No selectors specified.", "Checking that no selectors throws an exception");
});
+
+add_task(function* testMaximizedWindow() {
+ window.maximize();
+
+ let {bounds, rects} = TestRunner._findBoundingBox([":root"]);
+
+ is(bounds.top, screen.availTop, "Checking _findBoundingBox top (" + bounds.top + ") calculation (maximized window)");
+ is(bounds.left, screen.availLeft, "Checking _findBoundingBox left (" + bounds.left + ") calculation (maximized window)");
+ is(bounds.width, screen.availWidth, "Checking _findBoundingBox width (" + bounds.width + ") calculation (maximized window)");
+ is(bounds.height, screen.availHeight, "Checking _findBoundingBox height (" + bounds.height + ") calculation (maximized window)");
+
+ window.restore();
+});
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
@@ -228,22 +228,29 @@ this.TestRunner = {
if (!element) {
throw `No element for '${selector}' found.`;
}
// Calculate box region, convert to Rect
let box = element.ownerDocument.getBoxObjectFor(element);
let rect = new Rect(box.screenX * scale, box.screenY * scale,
- box.width * scale, box.height * scale);
+ box.width * scale, box.height * scale);
rect.inflateFixed(this.croppingPadding * scale);
rect.left = Math.max(rect.left, windowLeft);
rect.top = Math.max(rect.top, windowTop);
rect.right = Math.min(rect.right, windowLeft + windowWidth);
rect.bottom = Math.min(rect.bottom, windowTop + windowHeight);
+
+ // Clamp to available screen width/height
+ rect.left = Math.max(rect.left, browserWindow.screen.availLeft);
+ rect.top = Math.max(rect.top, browserWindow.screen.availTop);
+ rect.right = Math.min(rect.right, browserWindow.screen.availLeft + browserWindow.screen.availWidth);
+ rect.bottom = Math.min(rect.bottom, browserWindow.screen.availTop + browserWindow.screen.availHeight);
+
rects.push(rect);
if (!bounds) {
bounds = rect;
} else {
bounds = bounds.union(rect);
}
}