mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(chromium): can get correct orientation angle on non-mobile devices (#23796)
Fix #23772
This commit is contained in:
parent
a18475eaab
commit
6f67f6b52b
@ -1008,7 +1008,7 @@ class FrameSession {
|
|||||||
return;
|
return;
|
||||||
const viewportSize = emulatedSize.viewport;
|
const viewportSize = emulatedSize.viewport;
|
||||||
const screenSize = emulatedSize.screen;
|
const screenSize = emulatedSize.screen;
|
||||||
const isLandscape = viewportSize.width > viewportSize.height;
|
const isLandscape = screenSize.width > screenSize.height;
|
||||||
const metricsOverride: Protocol.Emulation.setDeviceMetricsOverrideParameters = {
|
const metricsOverride: Protocol.Emulation.setDeviceMetricsOverrideParameters = {
|
||||||
mobile: !!options.isMobile,
|
mobile: !!options.isMobile,
|
||||||
width: viewportSize.width,
|
width: viewportSize.width,
|
||||||
@ -1016,7 +1016,9 @@ class FrameSession {
|
|||||||
screenWidth: screenSize.width,
|
screenWidth: screenSize.width,
|
||||||
screenHeight: screenSize.height,
|
screenHeight: screenSize.height,
|
||||||
deviceScaleFactor: options.deviceScaleFactor || 1,
|
deviceScaleFactor: options.deviceScaleFactor || 1,
|
||||||
screenOrientation: isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' },
|
screenOrientation: !!options.isMobile ? (
|
||||||
|
isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' }
|
||||||
|
) : { angle: 0, type: 'landscapePrimary' },
|
||||||
dontSetVisibleSize: preserveWindowBoundaries
|
dontSetVisibleSize: preserveWindowBoundaries
|
||||||
};
|
};
|
||||||
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
||||||
|
|||||||
@ -163,3 +163,15 @@ it('WebKit Windows headed should have a minimal viewport', async ({ contextFacto
|
|||||||
await expect(page.setViewportSize({ width: 100, height: 100 })).rejects.toThrow('WebKit on Windows has a minimal viewport of 250x240.');
|
await expect(page.setViewportSize({ width: 100, height: 100 })).rejects.toThrow('WebKit on Windows has a minimal viewport of 250x240.');
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
browserTest('should be able to get correct orientation angle on non-mobile devices', async ({ browser, browserName, server }) => {
|
||||||
|
browserTest.skip(browserName === 'webkit', 'Desktop webkit dont support orientation API');
|
||||||
|
|
||||||
|
const context = await browser.newContext({ viewport: { width: 300, height: 400 }, isMobile: false });
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.goto(server.PREFIX + '/index.html');
|
||||||
|
expect(await page.evaluate(() => window.screen.orientation.angle)).toBe(0);
|
||||||
|
await page.setViewportSize({ width: 400, height: 300 });
|
||||||
|
expect(await page.evaluate(() => window.screen.orientation.angle)).toBe(0);
|
||||||
|
await context.close();
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user