fix: mock safari.pushNotification (#29107)

Fixes https://github.com/microsoft/playwright/issues/29032
This commit is contained in:
Yury Semikhatsky 2024-01-22 15:44:13 -08:00 committed by GitHub
parent db00aa7305
commit b2de9bc865
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -786,7 +786,7 @@ export class WKPage implements PageDelegate {
scripts.push('delete window.ondevicemotion'); scripts.push('delete window.ondevicemotion');
scripts.push('delete window.ondeviceorientation'); scripts.push('delete window.ondeviceorientation');
} }
scripts.push('if (!window.safari) window.safari = {};'); scripts.push('if (!window.safari) window.safari = { pushNotification: { toString() { return "[object SafariRemoteNotification]"; } } };');
scripts.push('if (!window.GestureEvent) window.GestureEvent = function GestureEvent() {};'); scripts.push('if (!window.GestureEvent) window.GestureEvent = function GestureEvent() {};');
for (const binding of this._page.allBindings()) for (const binding of this._page.allBindings())

View File

@ -212,10 +212,13 @@ it('serviceWorker should intercept document request', async ({ page, server }) =
it('webkit should define window.safari', async ({ page, server, browserName }) => { it('webkit should define window.safari', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21037' }); it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21037' });
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29032' });
it.skip(browserName !== 'webkit'); it.skip(browserName !== 'webkit');
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const defined = await page.evaluate(() => !!(window as any).safari); const defined = await page.evaluate(() => !!(window as any).safari);
expect(defined).toBeTruthy(); expect(defined).toBeTruthy();
expect(await page.evaluate(() => typeof (window as any).safari.pushNotification)).toBe('object');
expect(await page.evaluate(() => (window as any).safari.pushNotification.toString())).toBe('[object SafariRemoteNotification]');
}); });
it('make sure that XMLHttpRequest upload events are emitted correctly', async ({ page, server }) => { it('make sure that XMLHttpRequest upload events are emitted correctly', async ({ page, server }) => {