Bug 1857961 - [bidi] Add support for the "devicePixelRatio" argument for "browsingContext.setViewport". r=webdriver-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D207011
This commit is contained in:
Alexandra Borovova 2024-04-23 09:38:56 +00:00
parent 6d68d75755
commit 30386e20ca
5 changed files with 27 additions and 67 deletions

View file

@ -74,7 +74,7 @@ capture.canvas = async function (
) {
// FIXME(bug 1761032): This looks a bit sketchy, overrideDPPX doesn't
// influence rendering...
const scale = win.browsingContext.overrideDPPX || win.devicePixelRatio;
const scale = browsingContext.overrideDPPX || win.devicePixelRatio;
let canvasHeight = height * scale;
let canvasWidth = width * scale;

View file

@ -1160,13 +1160,6 @@
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[click.spec] Page.click should click the button with deviceScaleFactor set",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[click.spec] Page.click should click the button with fixed position inside an iframe",
"platforms": ["darwin", "linux", "win32"],
@ -1587,13 +1580,6 @@
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[emulation.spec] Emulation Page.viewport should load correct pictures when emulation dpr",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[emulation.spec] Emulation Page.viewport should support landscape emulation",
"platforms": ["darwin", "linux", "win32"],
@ -1615,13 +1601,6 @@
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[emulation.spec] Emulation Page.viewport should update media queries when resoltion changes",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluate should simulate a user gesture",
"platforms": ["darwin", "linux", "win32"],

View file

@ -1305,7 +1305,11 @@ class BrowsingContextModule extends Module {
* @param {object=} options
* @param {string} options.context
* Id of the browsing context.
* @param {Viewport|null} options.viewport
* @param {(number|null)=} options.devicePixelRatio
* A value to override device pixel ratio, or `null` to reset it to
* the original value. Different values will not cause the rendering to change,
* only image srcsets and media queries will be applied as if DPR is redefined.
* @param {(Viewport|null)=} options.viewport
* Dimensions to set the viewport to, or `null` to reset it
* to the original dimensions.
*
@ -1315,7 +1319,7 @@ class BrowsingContextModule extends Module {
* Raised when the command is called on Android.
*/
async setViewport(options = {}) {
const { context: contextId, viewport } = options;
const { context: contextId, devicePixelRatio, viewport } = options;
if (lazy.AppInfo.isAndroid) {
// Bug 1840084: Add Android support for modifying the viewport.
@ -1378,6 +1382,24 @@ class BrowsingContextModule extends Module {
browser.style.setProperty("width", targetWidth + "px");
}
if (devicePixelRatio !== undefined) {
if (devicePixelRatio !== null) {
lazy.assert.number(
devicePixelRatio,
`Expected "devicePixelRatio" to be a number or null, got ${devicePixelRatio}`
);
lazy.assert.that(
devicePixelRatio => devicePixelRatio > 0,
`Expected "devicePixelRatio" to be greater than 0, got ${devicePixelRatio}`
)(devicePixelRatio);
context.overrideDPPX = devicePixelRatio;
} else {
// Will reset to use the global default scaling factor.
context.overrideDPPX = 0;
}
}
if (targetHeight !== currentHeight || targetWidth !== currentWidth) {
// Wait until the viewport has been resized
await this.messageHandler.forwardCommand({

View file

@ -1,20 +1,3 @@
[device_pixel_ratio.py]
[test_device_pixel_ratio_only[0.5\]]
bug: 1857961
expected: FAIL
[test_device_pixel_ratio_only[2\]]
bug: 1857961
expected: FAIL
[test_device_pixel_ratio_with_viewport[0.5\]]
bug: 1865618
expected: FAIL
[test_device_pixel_ratio_with_viewport[2\]]
bug: 1857961
expected: FAIL
[test_reset_device_pixel_ratio]
bug: 1857961
expected: FAIL
disabled:
if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1840084

View file

@ -1,27 +1,3 @@
[invalid.py]
disabled:
if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1840084
[test_params_devicePixelRatio_invalid_type[False\]]
bug: 1857961
expected: FAIL
[test_params_devicePixelRatio_invalid_type[\]]
bug: 1857961
expected: FAIL
[test_params_devicePixelRatio_invalid_type[device_pixel_ratio2\]]
bug: 1857961
expected: FAIL
[test_params_devicePixelRatio_invalid_type[device_pixel_ratio3\]]
bug: 1857961
expected: FAIL
[test_params_devicePixelRatio_invalid_value[0\]]
bug: 1857961
expected: FAIL
[test_params_devicePixelRatio_invalid_value[-1\]]
bug: 1857961
expected: FAIL