From 136c4e10e6c78ca82ed498b12401a13a6642d3bf Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 24 Mar 2022 07:46:37 -0700 Subject: [PATCH] Revert "chore: align setInputFiles in webkit with other browsers (#13011)" (#13021) This reverts commit 7fe763c1fcd0c54fad9ddbdafc9555249540f28c. --- packages/playwright-core/src/server/chromium/crPage.ts | 5 +++++ packages/playwright-core/src/server/dom.ts | 2 +- packages/playwright-core/src/server/firefox/ffPage.ts | 5 +++++ packages/playwright-core/src/server/page.ts | 1 + packages/playwright-core/src/server/webkit/wkPage.ts | 10 ++++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index 1e76ec87e1..679d862dfc 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -317,6 +317,11 @@ export class CRPage implements PageDelegate { return this._sessionForHandle(handle)._getContentQuads(handle); } + async setInputFiles(handle: dom.ElementHandle, files: types.FilePayload[]): Promise { + await handle.evaluateInUtility(([injected, node, files]) => + injected.setInputFiles(node, files), files); + } + async setInputFilePaths(handle: dom.ElementHandle, files: string[]): Promise { const frame = await handle.ownerFrame(); if (!frame) diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts index 515d18db18..4aa832d90a 100644 --- a/packages/playwright-core/src/server/dom.ts +++ b/packages/playwright-core/src/server/dom.ts @@ -639,7 +639,7 @@ export class ElementHandle extends js.JSHandle { if (localPaths) await this._page._delegate.setInputFilePaths(retargeted, localPaths); else - await retargeted.evaluateInUtility(([injected, node, files]) => injected.setInputFiles(node, files), files as types.FilePayload[]); + await this._page._delegate.setInputFiles(retargeted, files as types.FilePayload[]); }); await this._page._doSlowMo(); return 'done'; diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts index da288077a0..37965b642e 100644 --- a/packages/playwright-core/src/server/firefox/ffPage.ts +++ b/packages/playwright-core/src/server/firefox/ffPage.ts @@ -527,6 +527,11 @@ export class FFPage implements PageDelegate { return result.quads.map(quad => [ quad.p1, quad.p2, quad.p3, quad.p4 ]); } + async setInputFiles(handle: dom.ElementHandle, files: types.FilePayload[]): Promise { + await handle.evaluateInUtility(([injected, node, files]) => + injected.setInputFiles(node, files), files); + } + async setInputFilePaths(handle: dom.ElementHandle, files: string[]): Promise { throw new Error('Not implemented'); } diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 73eb20efd0..33d8305abb 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -69,6 +69,7 @@ export interface PageDelegate { getContentFrame(handle: dom.ElementHandle): Promise; // Only called for frame owner elements. getOwnerFrame(handle: dom.ElementHandle): Promise; // Returns frameId. getContentQuads(handle: dom.ElementHandle): Promise; + setInputFiles(handle: dom.ElementHandle, files: types.FilePayload[]): Promise; setInputFilePaths(handle: dom.ElementHandle, files: string[]): Promise; getBoundingBox(handle: dom.ElementHandle): Promise; getFrameElement(frame: frames.Frame): Promise; diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index b711d07d0b..500d72da6c 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -926,6 +926,16 @@ export class WKPage implements PageDelegate { ]); } + async setInputFiles(handle: dom.ElementHandle, files: types.FilePayload[]): Promise { + const objectId = handle._objectId; + const protocolFiles = files.map(file => ({ + name: file.name, + type: file.mimeType, + data: file.buffer, + })); + await this._session.send('DOM.setInputFiles', { objectId, files: protocolFiles }); + } + async setInputFilePaths(handle: dom.ElementHandle, files: string[]): Promise { throw new Error('Not implemented'); }