Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add parentSession() to CDPSession #10709

Merged
merged 1 commit into from Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/puppeteer-core/src/common/Connection.ts
Expand Up @@ -310,7 +310,8 @@ export class Connection extends EventEmitter {
const session = new CDPSessionImpl(
this,
object.params.targetInfo.type,
sessionId
sessionId,
object.sessionId
);
this.#sessions.set(sessionId, session);
this.emit('sessionattached', session);
Expand Down Expand Up @@ -470,6 +471,15 @@ export class CDPSession extends EventEmitter {
throw new Error('Not implemented');
}

/**
* Parent session in terms of CDP's auto-attach mechanism.
*
* @internal
*/
parentSession(): CDPSession | undefined {
return undefined;
}

send<T extends keyof ProtocolMapping.Commands>(
method: T,
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
Expand Down Expand Up @@ -504,21 +514,36 @@ export class CDPSessionImpl extends CDPSession {
#targetType: string;
#callbacks = new CallbackRegistry();
#connection?: Connection;
#parentSessionId?: string;

/**
* @internal
*/
constructor(connection: Connection, targetType: string, sessionId: string) {
constructor(
connection: Connection,
targetType: string,
sessionId: string,
parentSessionId: string | undefined
) {
super();
this.#connection = connection;
this.#targetType = targetType;
this.#sessionId = sessionId;
this.#parentSessionId = parentSessionId;
}

override connection(): Connection | undefined {
return this.#connection;
}

override parentSession(): CDPSession | undefined {
if (!this.#parentSessionId) {
return;
}
const parent = this.#connection?.session(this.#parentSessionId);
return parent ?? undefined;
}

override send<T extends keyof ProtocolMapping.Commands>(
method: T,
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
Expand Down
Expand Up @@ -36,6 +36,9 @@ class MockCDPSession extends EventEmitter {
id() {
return '1';
}
parentSession() {
return undefined;
}
}

describe('DeviceRequestPrompt', function () {
Expand Down
3 changes: 3 additions & 0 deletions packages/puppeteer-core/src/common/NetworkManager.test.ts
Expand Up @@ -37,6 +37,9 @@ class MockCDPSession extends EventEmitter {
id() {
return '1';
}
parentSession() {
return undefined;
}
}

describe('NetworkManager', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/TestExpectations.json
Expand Up @@ -2649,7 +2649,7 @@
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS", "FAIL"]
"expectations": ["FAIL", "PASS"]
},
{
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
Expand Down