mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(screencast): support viewport with odd dimensions (#5399)
This commit is contained in:
parent
7933cfc7df
commit
a8ebe4d888
@ -373,19 +373,22 @@ export function validateBrowserContextOptions(options: types.BrowserContextOptio
|
|||||||
throw new Error(`"isMobile" option is not supported with null "viewport"`);
|
throw new Error(`"isMobile" option is not supported with null "viewport"`);
|
||||||
if (!options.viewport && !options.noDefaultViewport)
|
if (!options.viewport && !options.noDefaultViewport)
|
||||||
options.viewport = { width: 1280, height: 720 };
|
options.viewport = { width: 1280, height: 720 };
|
||||||
if (options.recordVideo && !options.recordVideo.size) {
|
if (options.recordVideo) {
|
||||||
if (options.noDefaultViewport) {
|
if (!options.recordVideo.size) {
|
||||||
options.recordVideo.size = { width: 800, height: 600 };
|
if (options.noDefaultViewport) {
|
||||||
} else {
|
options.recordVideo.size = { width: 800, height: 600 };
|
||||||
const size = options.viewport!;
|
} else {
|
||||||
const scale = 800 / Math.max(size.width, size.height);
|
const size = options.viewport!;
|
||||||
if (scale < 1) {
|
const scale = Math.min(1, 800 / Math.max(size.width, size.height));
|
||||||
options.recordVideo.size = {
|
options.recordVideo.size = {
|
||||||
width: Math.floor(size.width * scale),
|
width: Math.floor(size.width * scale),
|
||||||
height: Math.floor(size.height * scale)
|
height: Math.floor(size.height * scale)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Make sure both dimensions are odd, this is required for vp8
|
||||||
|
options.recordVideo.size!.width &= ~1;
|
||||||
|
options.recordVideo.size!.height &= ~1;
|
||||||
}
|
}
|
||||||
if (options.proxy) {
|
if (options.proxy) {
|
||||||
if (!browserOptions.proxy)
|
if (!browserOptions.proxy)
|
||||||
|
@ -479,4 +479,26 @@ describe('screencast', suite => {
|
|||||||
expectAll(pixels, almostRed);
|
expectAll(pixels, almostRed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emulate an iphone', (test, { browserName }) => {
|
||||||
|
test.skip(browserName === 'firefox', 'isMobile is not supported in Firefox');
|
||||||
|
}, async ({contextFactory, playwright, contextOptions, testInfo}) => {
|
||||||
|
const device = playwright.devices['iPhone 6'];
|
||||||
|
const context = await contextFactory({
|
||||||
|
...contextOptions,
|
||||||
|
...device,
|
||||||
|
recordVideo: {
|
||||||
|
dir: testInfo.outputPath(''),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const page = await context.newPage();
|
||||||
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
|
await context.close();
|
||||||
|
|
||||||
|
const videoFile = await page.video().path();
|
||||||
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
|
expect(videoPlayer.videoWidth).toBe(374);
|
||||||
|
expect(videoPlayer.videoHeight).toBe(666);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user