Bug 1886382 - browsingContext.print" needs to raise "unsupported operation" error for PDFs with zero dimension. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D224329
This commit is contained in:
Temidayo 2024-10-10 09:16:28 +00:00
parent f5dc1f7793
commit 5023365fef
4 changed files with 17 additions and 12 deletions

View File

@ -6,6 +6,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
Log: "chrome://remote/content/shared/Log.sys.mjs",
pprint: "chrome://remote/content/shared/Format.sys.mjs",
});
@ -17,6 +18,8 @@ export const print = {
minScaleValue: 0.1,
};
export const MIN_PAGE_SIZE = 0.0352;
print.defaults = {
// The size of the page in centimeters.
page: {
@ -60,6 +63,18 @@ print.addDefaultSettings = function (settings) {
page.height = print.defaults.page.height;
}
if (page.width < MIN_PAGE_SIZE) {
throw new lazy.error.InvalidArgumentError(
`Expected "page.width" to be greater than or equal to ${MIN_PAGE_SIZE}cm, got ${page.width}cm.`
);
}
if (page.height < MIN_PAGE_SIZE) {
throw new lazy.error.InvalidArgumentError(
`Expected "page.height" to be greater than or equal to ${MIN_PAGE_SIZE}cm, got ${page.height}cm.`
);
}
if (!("top" in margin)) {
margin.top = print.defaults.margin.top;
}

View File

@ -1,6 +0,0 @@
[invalid.py]
[test_params_page_invalid_value[page2\]]
expected: FAIL
[test_params_page_invalid_value[page3\]]
expected: FAIL

View File

@ -3,7 +3,7 @@ import base64
import pytest
from tests.support.asserts import assert_pdf, assert_success
from tests.support.image import px_to_cm
from tests.support.image import pt_to_cm
from . import do_print
@ -43,7 +43,7 @@ def test_background(
{
"background": print_with_background,
"margin": {"top": 0, "bottom": 0, "right": 0, "left": 0},
"page": {"width": px_to_cm(1), "height": px_to_cm(1)},
"page": {"width": pt_to_cm(1), "height": pt_to_cm(1)},
},
)
print_value = assert_success(print_result)

View File

@ -13,10 +13,6 @@ def cm_to_px(cm: float) -> float:
return round(cm * inch_in_pixel / inch_in_cm)
def px_to_cm(px: float) -> float:
return px * inch_in_cm / inch_in_pixel
def pt_to_cm(pt: float) -> float:
return pt * inch_in_cm / inch_in_point