refactor: add parentSession() to CDPSession (#10709)
This commit is contained in:
parent
2dec12fe8b
commit
932a5e0415
@ -310,7 +310,8 @@ export class Connection extends EventEmitter {
|
|||||||
const session = new CDPSessionImpl(
|
const session = new CDPSessionImpl(
|
||||||
this,
|
this,
|
||||||
object.params.targetInfo.type,
|
object.params.targetInfo.type,
|
||||||
sessionId
|
sessionId,
|
||||||
|
object.sessionId
|
||||||
);
|
);
|
||||||
this.#sessions.set(sessionId, session);
|
this.#sessions.set(sessionId, session);
|
||||||
this.emit('sessionattached', session);
|
this.emit('sessionattached', session);
|
||||||
@ -470,6 +471,15 @@ export class CDPSession extends EventEmitter {
|
|||||||
throw new Error('Not implemented');
|
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>(
|
send<T extends keyof ProtocolMapping.Commands>(
|
||||||
method: T,
|
method: T,
|
||||||
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
||||||
@ -504,21 +514,36 @@ export class CDPSessionImpl extends CDPSession {
|
|||||||
#targetType: string;
|
#targetType: string;
|
||||||
#callbacks = new CallbackRegistry();
|
#callbacks = new CallbackRegistry();
|
||||||
#connection?: Connection;
|
#connection?: Connection;
|
||||||
|
#parentSessionId?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
constructor(connection: Connection, targetType: string, sessionId: string) {
|
constructor(
|
||||||
|
connection: Connection,
|
||||||
|
targetType: string,
|
||||||
|
sessionId: string,
|
||||||
|
parentSessionId: string | undefined
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.#connection = connection;
|
this.#connection = connection;
|
||||||
this.#targetType = targetType;
|
this.#targetType = targetType;
|
||||||
this.#sessionId = sessionId;
|
this.#sessionId = sessionId;
|
||||||
|
this.#parentSessionId = parentSessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
override connection(): Connection | undefined {
|
override connection(): Connection | undefined {
|
||||||
return this.#connection;
|
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>(
|
override send<T extends keyof ProtocolMapping.Commands>(
|
||||||
method: T,
|
method: T,
|
||||||
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
||||||
|
@ -36,6 +36,9 @@ class MockCDPSession extends EventEmitter {
|
|||||||
id() {
|
id() {
|
||||||
return '1';
|
return '1';
|
||||||
}
|
}
|
||||||
|
parentSession() {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('DeviceRequestPrompt', function () {
|
describe('DeviceRequestPrompt', function () {
|
||||||
|
@ -37,6 +37,9 @@ class MockCDPSession extends EventEmitter {
|
|||||||
id() {
|
id() {
|
||||||
return '1';
|
return '1';
|
||||||
}
|
}
|
||||||
|
parentSession() {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('NetworkManager', () => {
|
describe('NetworkManager', () => {
|
||||||
|
@ -2649,7 +2649,7 @@
|
|||||||
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
|
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["firefox", "webDriverBiDi"],
|
"parameters": ["firefox", "webDriverBiDi"],
|
||||||
"expectations": ["PASS", "FAIL"]
|
"expectations": ["FAIL", "PASS"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
|
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
|
||||||
|
Loading…
Reference in New Issue
Block a user