feat(rpc): misc fixes (#3351)

This commit is contained in:
Dmitry Gozman 2020-08-07 15:40:21 -07:00 committed by GitHub
parent a225447653
commit 83f5628549
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 22 deletions

View file

@ -1591,9 +1591,11 @@ export type WorkerInitializer = {
url: string,
};
export interface WorkerChannel extends Channel {
on(event: 'close', callback: (params: WorkerCloseEvent) => void): this;
evaluateExpression(params: WorkerEvaluateExpressionParams): Promise<WorkerEvaluateExpressionResult>;
evaluateExpressionHandle(params: WorkerEvaluateExpressionHandleParams): Promise<WorkerEvaluateExpressionHandleResult>;
}
export type WorkerCloseEvent = {};
export type WorkerEvaluateExpressionParams = {
expression: string,
isFunction: boolean,

View file

@ -50,6 +50,4 @@ export class BrowserServer extends ChannelOwner<BrowserServerChannel, BrowserSer
await this._channel.close();
});
}
_checkLeaks() {}
}

View file

@ -1343,6 +1343,9 @@ Worker:
returns:
handle: JSHandle
events:
close:
JSHandle:

View file

@ -18,7 +18,7 @@
import utils from './utils';
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
{
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -34,26 +34,29 @@ it.slow()('should be able to reconnect to a browser', async({browserType, defaul
await page.goto(server.EMPTY_PAGE);
await browser.close();
}
await (browserServer as any)._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
it.fail(USES_HOOKS || (CHROMIUM && WIN)).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions, server}) => {
it.fail(USES_HOOKS || (CHROMIUM && WIN)).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
await (browserServer as any)._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
expect(error.message).toContain('Dummy');
});
it('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {
it('should set the browser connected state', async ({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(remote.isConnected()).toBe(true);
await remote.close();
expect(remote.isConnected()).toBe(false);
await (browserServer as any)._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});

View file

@ -20,7 +20,7 @@ const fs = require('fs');
const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
it('should work', async({browserType, defaultBrowserOptions}) => {
it('should work', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browserContext = await browser.newContext();
@ -30,7 +30,8 @@ it('should work', async({browserType, defaultBrowserOptions}) => {
expect(await page.evaluate('11 * 11')).toBe(121);
await page.close();
await browser.close();
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
@ -76,7 +77,7 @@ it('should fire close event', async ({browserType, defaultBrowserOptions}) => {
expect(result.signal).toBe(null);
});
it('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => {
it('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server, toImpl}) => {
server.setRoute('/one-style.css', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -86,11 +87,12 @@ it('should reject navigation when browser closes', async({browserType, defaultBr
await remote.close();
const error = await navigationPromise;
expect(error.message).toContain('Navigation failed because page was closed!');
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
it('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => {
it('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server, toImpl}) => {
server.setRoute('/empty.html', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -103,18 +105,20 @@ it('should reject waitForSelector when browser closes', async({browserType, defa
await remote.close();
const error = await watchdog;
expect(error.message).toContain('Protocol error');
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
it('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => {
it('should throw if used after disconnect', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage();
await remote.close();
const error = await page.evaluate('1 + 1').catch(e => e);
expect(error.message).toContain('has been closed');
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});

View file

@ -17,7 +17,7 @@
const {FFOX, CHROMIUM, WEBKIT} = testOptions;
it('should work across sessions', async ({browserType, defaultBrowserOptions}) => {
it('should work across sessions', async ({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(browser1.contexts().length).toBe(0);
@ -34,7 +34,8 @@ it('should work across sessions', async ({browserType, defaultBrowserOptions}) =
await browser1.close();
await browser2.close();
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
@ -72,7 +73,7 @@ it.slow()('should be emitted when: browser gets closed, disconnected or underlyi
expect(disconnectedRemote2).toBe(1);
});
it('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions}) => {
it('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -83,11 +84,12 @@ it('should be able to connect multiple times to the same browser', async({browse
const page2 = await browser2.newPage();
expect(await page2.evaluate(() => 7 * 6)).toBe(42, 'original browser should still work');
await browser2.close();
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
it('should not be able to close remote browser', async({browserType, defaultBrowserOptions}) => {
it('should not be able to close remote browser', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
{
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -99,6 +101,7 @@ it('should not be able to close remote browser', async({browserType, defaultBrow
await remote.newContext();
await remote.close();
}
await browserServer._checkLeaks();
if (toImpl)
await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});