Skip to content

Commit

Permalink
feat(emulation): emulate a mouse pointer in headless chrome (#3922)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder authored Sep 21, 2020
1 parent c2d9af8 commit 75edc61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/server/chromium/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class Chromium extends BrowserType {
chromeArguments.push(
'--headless',
'--hide-scrollbars',
'--mute-audio'
'--mute-audio',
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4',
);
}
if (options.chromiumSandbox === false)
Expand Down
27 changes: 27 additions & 0 deletions test/browsercontext-viewport-mobile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,31 @@ describe('mobile viewport', (suite, parameters) => {
expect(await page.evaluate(() => window.innerWidth)).toBe(320);
await context.close();
});

it('should emulate the hover media feature', (test, parameters) => {
test.fail(options.WEBKIT(parameters));
}, async ({playwright, browser}) => {
const iPhone = playwright.devices['iPhone 6'];
const mobilepage = await browser.newPage({ ...iPhone });
expect(await mobilepage.evaluate(() => matchMedia('(hover: hover)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(hover: none)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(any-hover: hover)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(any-hover: none)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(pointer: coarse)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(pointer: fine)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(any-pointer: coarse)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(any-pointer: fine)').matches)).toBe(false);
await mobilepage.close();

const desktopPage = await browser.newPage();
expect(await desktopPage.evaluate(() => matchMedia('(hover: none)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(hover: hover)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(any-hover: none)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(any-hover: hover)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(pointer: coarse)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(pointer: fine)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(any-pointer: coarse)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(any-pointer: fine)').matches)).toBe(true);
await desktopPage.close();
});
});

0 comments on commit 75edc61

Please sign in to comment.