Skip to content

Commit

Permalink
Bug 1857961 - [bidi] Add support for the "devicePixelRatio" argument …
Browse files Browse the repository at this point in the history
…for "browsingContext.setViewport". r=webdriver-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D207011
  • Loading branch information
lutien committed Apr 23, 2024
1 parent 4102bc2 commit d93d2c6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 67 deletions.
2 changes: 1 addition & 1 deletion remote/shared/Capture.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 0 additions & 21 deletions remote/test/puppeteer/test/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand All @@ -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"],
Expand Down
26 changes: 24 additions & 2 deletions remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d93d2c6

Please sign in to comment.