Skip to content

Commit

Permalink
feat(webkit): simulate device orientation events (#1852)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Apr 20, 2020
1 parent 93c9083 commit fb45c75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"playwright": {
"chromium_revision": "759546",
"firefox_revision": "1084",
"webkit_revision": "1197"
"webkit_revision": "1200"
},
"scripts": {
"ctest": "cross-env BROWSER=chromium node --unhandled-rejections=strict test/test.js",
Expand Down
4 changes: 4 additions & 0 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ export class WKPage implements PageDelegate {
height: viewport.height,
}),
];
if (options.isMobile) {
const angle = viewport.width > viewport.height ? 90 : 0;
promises.push(this._session.send('Page.setOrientationOverride', { angle }));
}
await Promise.all(promises);
}

Expand Down
11 changes: 10 additions & 1 deletion test/emulation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ describe.skip(FFOX)('viewport.isMobile', () => {
await context1.close();
await context2.close();
});
it.fail(WEBKIT)('should fire orientationchange event', async({browser, server}) => {
it('should support window.orientation emulation', async({browser, server}) => {
const context = await browser.newContext({ viewport: { width: 300, height: 400 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
expect(await page.evaluate(() => window.orientation)).toBe(0);
await page.setViewportSize({width: 400, height: 300});
expect(await page.evaluate(() => window.orientation)).toBe(90);
await context.close();
});
it('should fire orientationchange event', async({browser, server}) => {
const context = await browser.newContext({ viewport: { width: 300, height: 400 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
Expand Down

0 comments on commit fb45c75

Please sign in to comment.