test: add a test for newCDPSession rejecting on non-pages (#3353)

This commit is contained in:
Dmitry Gozman 2020-08-07 15:40:46 -07:00 committed by GitHub
parent 83f5628549
commit 7e2cc77524
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -463,6 +463,8 @@ export class CRBrowserContext extends BrowserContextBase {
}
async newCDPSession(page: Page): Promise<CRSession> {
if (!(page instanceof Page))
throw new Error('page: expected Page');
const targetId = (page._delegate as CRPage)._targetId;
const rootSession = await this._browser._clientRootSession();
const { sessionId } = await rootSession.send('Target.attachToTarget', { targetId, flatten: true });

View file

@ -36,6 +36,11 @@ it.skip(!CHROMIUM)('should send events', async function({page, server}) {
expect(events.length).toBe(1);
});
it.skip(!CHROMIUM)('should only accept a page', async function({page}) {
const error = await page.context().newCDPSession(page.context()).catch(e => e);
expect(error.message).toContain('page: expected Page');
});
it.skip(!CHROMIUM)('should enable and disable domains independently', async function({page}) {
const client = await page.context().newCDPSession(page);
await client.send('Runtime.enable');