From 9cfc19579418db37d210d026c7915c77fa3bbca4 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 21 Sep 2023 10:49:30 +0200 Subject: [PATCH] test: enable queryObjects for bidi (#10964) --- docs/api/puppeteer.page.queryobjects.md | 2 +- packages/puppeteer-core/src/api/Page.ts | 5 +---- packages/puppeteer-core/src/bidi/Page.ts | 21 +++++++++++++++++++++ test/TestExpectations.json | 18 ++++++++++++------ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/api/puppeteer.page.queryobjects.md b/docs/api/puppeteer.page.queryobjects.md index 8a10e697085..44a76b1bc3e 100644 --- a/docs/api/puppeteer.page.queryobjects.md +++ b/docs/api/puppeteer.page.queryobjects.md @@ -10,7 +10,7 @@ This method iterates the JavaScript heap and finds all objects with the given pr ```typescript class Page { - queryObjects( + abstract queryObjects( prototypeHandle: JSHandle ): Promise>; } diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index e9d706e1656..14768def007 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -1073,12 +1073,9 @@ export abstract class Page extends EventEmitter { * @returns Promise which resolves to a handle to an array of objects with * this prototype. */ - async queryObjects( + abstract queryObjects( prototypeHandle: JSHandle ): Promise>; - async queryObjects(): Promise> { - throw new Error('Not implemented'); - } /** * This method runs `document.querySelector` within the page and passes the diff --git a/packages/puppeteer-core/src/bidi/Page.ts b/packages/puppeteer-core/src/bidi/Page.ts index cfa7763db77..6afd36e7af4 100644 --- a/packages/puppeteer-core/src/bidi/Page.ts +++ b/packages/puppeteer-core/src/bidi/Page.ts @@ -76,6 +76,7 @@ import {BidiFrame, lifeCycleToReadinessState} from './Frame.js'; import {type BidiHTTPRequest} from './HTTPRequest.js'; import {type BidiHTTPResponse} from './HTTPResponse.js'; import {BidiKeyboard, BidiMouse, BidiTouchscreen} from './Input.js'; +import {type BidiJSHandle} from './JSHandle.js'; import {BidiNetworkManager} from './NetworkManager.js'; import {createBidiHandle} from './Realm.js'; import {BidiSerializer} from './Serializer.js'; @@ -219,6 +220,26 @@ export class BidiPage extends Page { await this._client().send('Page.setBypassCSP', {enabled}); } + override async queryObjects( + prototypeHandle: BidiJSHandle + ): Promise> { + assert(!prototypeHandle.disposed, 'Prototype JSHandle is disposed!'); + assert( + prototypeHandle.id, + 'Prototype JSHandle must not be referencing primitive value' + ); + const response = await this.mainFrame().client.send( + 'Runtime.queryObjects', + { + prototypeObjectId: prototypeHandle.id, + } + ); + return createBidiHandle(this.mainFrame().mainRealm(), { + type: 'array', + handle: response.objects.objectId, + }) as BidiJSHandle; + } + _setBrowserContext(browserContext: BidiBrowserContext): void { this.#browserContext = browserContext; } diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 3d4ed2f15b2..865bfee78b7 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -983,6 +983,12 @@ "parameters": ["webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[page.spec] Page ExecutionContext.queryObjects *", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.addScriptTag should throw when added with content to the CSP page", "platforms": ["darwin", "linux", "win32"], @@ -3413,6 +3419,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[page.spec] Page Page.setCacheEnabled should enable or disable the cache based on the state passed", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.setCacheEnabled should stay disabled when toggling request interception on/off", "platforms": ["darwin", "linux", "win32"], @@ -4084,11 +4096,5 @@ "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "chrome", "new-headless", "tabTarget"], "expectations": ["FAIL"] - }, - { - "testIdPattern": "[page.spec] Page Page.setCacheEnabled should enable or disable the cache based on the state passed", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["PASS"] } ]