зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 39f3534179a7 (bug 1743887) for causing failures at browser_screenshots_test_screenshot_too_big.js.
This commit is contained in:
Родитель
25ce224366
Коммит
9268f063c3
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import { getFilename } from "chrome://browser/content/screenshots/fileHelpers.mjs";
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
|
@ -13,22 +12,9 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetters(lazy, {
|
||||
AlertsService: ["@mozilla.org/alerts-service;1", "nsIAlertsService"],
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "screenshotsLocalization", () => {
|
||||
return new Localization(["browser/screenshots.ftl"], true);
|
||||
});
|
||||
|
||||
const PanelPosition = "bottomright topright";
|
||||
const PanelOffsetX = -33;
|
||||
const PanelOffsetY = -8;
|
||||
// The max dimension for a canvas is defined https://searchfox.org/mozilla-central/rev/f40d29a11f2eb4685256b59934e637012ea6fb78/gfx/cairo/cairo/src/cairo-image-surface.c#62.
|
||||
// The max number of pixels for a canvas is 124925329 or 11177 x 11177.
|
||||
// We have to limit screenshots to these dimensions otherwise it will cause an error.
|
||||
const MAX_CAPTURE_DIMENSION = 32767;
|
||||
const MAX_CAPTURE_AREA = 124925329;
|
||||
|
||||
export class ScreenshotsComponentParent extends JSWindowActorParent {
|
||||
async receiveMessage(message) {
|
||||
|
@ -292,49 +278,6 @@ export var ScreenshotsUtils = {
|
|||
let actor = this.getActor(browser);
|
||||
return actor.sendQuery("Screenshots:getVisibleBounds");
|
||||
},
|
||||
showAlertMessage(title, message) {
|
||||
lazy.AlertsService.showAlertNotification(null, title, message);
|
||||
},
|
||||
/**
|
||||
* The max one dimesion for a canvas is 32767 and the max canvas area is
|
||||
* 124925329. If the width or height is greater than 32767 we will crop the
|
||||
* screenshot to the max width. If the area is still too large for the canvas
|
||||
* we will adjust the height so we can successfully capture the screenshot.
|
||||
* @param {Object} rect The dimensions of the screenshot. The rect will be
|
||||
* modified in place
|
||||
*/
|
||||
cropScreenshotRectIfNeeded(rect) {
|
||||
let cropped = false;
|
||||
let width = rect.width * rect.devicePixelRatio;
|
||||
let height = rect.height * rect.devicePixelRatio;
|
||||
|
||||
if (width > MAX_CAPTURE_DIMENSION) {
|
||||
width = MAX_CAPTURE_DIMENSION;
|
||||
cropped = true;
|
||||
}
|
||||
if (height > MAX_CAPTURE_DIMENSION) {
|
||||
height = MAX_CAPTURE_DIMENSION;
|
||||
cropped = true;
|
||||
}
|
||||
if (width * height > MAX_CAPTURE_AREA) {
|
||||
height = Math.floor(MAX_CAPTURE_AREA / width);
|
||||
cropped = true;
|
||||
}
|
||||
|
||||
rect.width = Math.floor(width / rect.devicePixelRatio);
|
||||
rect.height = Math.floor(height / rect.devicePixelRatio);
|
||||
|
||||
if (cropped) {
|
||||
let [
|
||||
errorTitle,
|
||||
errorMessage,
|
||||
] = lazy.screenshotsLocalization.formatMessagesSync([
|
||||
{ id: "screenshots-too-large-error-title" },
|
||||
{ id: "screenshots-too-large-error-details" },
|
||||
]);
|
||||
this.showAlertMessage(errorTitle.value, errorMessage.value);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Add screenshot-ui to the dialog box and then take the screenshot
|
||||
* @param browser The current browser.
|
||||
|
@ -363,8 +306,6 @@ export var ScreenshotsUtils = {
|
|||
* @param rect DOMRect containing bounds of the screenshot.
|
||||
*/
|
||||
async takeScreenshot(browser, dialog, rect) {
|
||||
this.cropScreenshotRectIfNeeded(rect);
|
||||
|
||||
let { canvas, snapshot } = await this.createCanvas(rect, browser);
|
||||
|
||||
let newImg = dialog._frame.contentDocument.createElement("img");
|
||||
|
|
|
@ -3,7 +3,6 @@ support-files =
|
|||
head.js
|
||||
test-page.html
|
||||
short-test-page.html
|
||||
large-test-page.html
|
||||
|
||||
prefs =
|
||||
extensions.screenshots.disabled=false
|
||||
|
@ -21,7 +20,6 @@ prefs =
|
|||
skip-if = (!debug && os == 'win' && os_version == '6.1') # Bug 1746281
|
||||
[browser_screenshots_test_page_crash.js]
|
||||
skip-if = !crashreporter
|
||||
[browser_screenshots_test_screenshot_too_big.js]
|
||||
[browser_screenshots_test_toggle_pref.js]
|
||||
[browser_screenshots_test_toolbar_button.js]
|
||||
[browser_screenshots_test_visible.js]
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
|
||||
});
|
||||
|
||||
add_task(async function test_screenshot_too_large_cropped() {
|
||||
const screenshotsLocalization = new Localization(
|
||||
["browser/screenshots.ftl"],
|
||||
true
|
||||
);
|
||||
|
||||
let [errorTitle, errorMessage] = screenshotsLocalization.formatMessagesSync([
|
||||
{ id: "screenshots-too-large-error-title" },
|
||||
{ id: "screenshots-too-large-error-details" },
|
||||
]);
|
||||
let showAlertMessageStub = sinon
|
||||
.stub(ScreenshotsUtils, "showAlertMessage")
|
||||
.callsFake(function(title, message) {
|
||||
is(title, errorTitle.value, "Got error title");
|
||||
is(message, errorMessage.value, "Got error message");
|
||||
});
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: LARGE_TEST_PAGE,
|
||||
},
|
||||
async browser => {
|
||||
let helper = new ScreenshotsHelper(browser);
|
||||
|
||||
helper.triggerUIFromToolbar();
|
||||
await helper.waitForOverlay();
|
||||
|
||||
let screenshotReady = TestUtils.topicObserved(
|
||||
"screenshots-preview-ready"
|
||||
);
|
||||
|
||||
let panel = gBrowser.selectedBrowser.ownerDocument.querySelector(
|
||||
"#screenshotsPagePanel"
|
||||
);
|
||||
// click the full page button in panel
|
||||
let visiblePage = panel
|
||||
.querySelector("screenshots-buttons")
|
||||
.shadowRoot.querySelector(".full-page");
|
||||
visiblePage.click();
|
||||
|
||||
await screenshotReady;
|
||||
|
||||
let dialog = helper.getDialog();
|
||||
|
||||
let image = dialog._frame.contentDocument.querySelector(
|
||||
"#placeholder-image"
|
||||
);
|
||||
|
||||
await TestUtils.waitForCondition(() => {
|
||||
return image.naturalHeight > 0 && image.naturalWidth > 0;
|
||||
});
|
||||
|
||||
is(image.naturalWidth, MAX_CAPTURE_DIMENSION, "The width is 32767");
|
||||
|
||||
is(
|
||||
image.naturalHeight,
|
||||
Math.floor(MAX_CAPTURE_AREA / MAX_CAPTURE_DIMENSION),
|
||||
"The height is 124925329 / 32767"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
let rect = { x: 0, y: 0, width: 40000, height: 1, devicePixelRatio: 1 };
|
||||
|
||||
ScreenshotsUtils.cropScreenshotRectIfNeeded(rect);
|
||||
|
||||
is(
|
||||
rect.width,
|
||||
MAX_CAPTURE_DIMENSION,
|
||||
"The width was cropped to the max capture dimension (32767)."
|
||||
);
|
||||
|
||||
rect.width = 1;
|
||||
rect.height = 40000;
|
||||
|
||||
ScreenshotsUtils.cropScreenshotRectIfNeeded(rect);
|
||||
|
||||
is(
|
||||
rect.height,
|
||||
MAX_CAPTURE_DIMENSION,
|
||||
"The height was cropped to the max capture dimension (32767)."
|
||||
);
|
||||
|
||||
rect.width = 12345;
|
||||
rect.height = 12345;
|
||||
|
||||
ScreenshotsUtils.cropScreenshotRectIfNeeded(rect);
|
||||
|
||||
is(rect.width, 12345, "The width was not cropped");
|
||||
is(
|
||||
rect.height,
|
||||
Math.floor(MAX_CAPTURE_AREA / 12345),
|
||||
"The height was cropped to 10119"
|
||||
);
|
||||
|
||||
showAlertMessageStub.restore();
|
||||
});
|
|
@ -10,10 +10,6 @@ const TEST_ROOT = getRootDirectory(gTestPath).replace(
|
|||
|
||||
const TEST_PAGE = TEST_ROOT + "test-page.html";
|
||||
const SHORT_TEST_PAGE = TEST_ROOT + "short-test-page.html";
|
||||
const LARGE_TEST_PAGE = TEST_ROOT + "large-test-page.html";
|
||||
|
||||
const MAX_CAPTURE_DIMENSION = 32767;
|
||||
const MAX_CAPTURE_AREA = 124925329;
|
||||
|
||||
const gScreenshotUISelectors = {
|
||||
panelButtons: "#screenshotsPagePanel",
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Screenshots</title>
|
||||
</head>
|
||||
<body style="height:40000px; width:40000px; background-repeat: no-repeat; background-size: 40008px 40016px; background-color: rgb(111, 111, 111); background-image:linear-gradient(to right, transparent 50%, rgba(0, 200, 200, 0.5) 50%),linear-gradient(to bottom, transparent 50%, rgba(100, 0, 100, 0.5) 50%);">
|
||||
</body>
|
||||
</html>
|
|
@ -55,6 +55,3 @@ screenshots-private-window-error-details = Sorry for the inconvenience. We are w
|
|||
|
||||
screenshots-generic-error-title = Whoa! { -screenshots-brand-name } went haywire.
|
||||
screenshots-generic-error-details = We’re not sure what just happened. Care to try again or take a shot of a different page?
|
||||
|
||||
screenshots-too-large-error-title = Your screenshot was cropped because it was too large
|
||||
screenshots-too-large-error-details = Try selecting a region that’s smaller than 32,700 pixels on its longest side or 124,900,000 pixels total area.
|
||||
|
|
Загрузка…
Ссылка в новой задаче